2
2
3
3
const _ = require ( 'underscore' ) ;
4
4
const path = require ( 'path' ) ;
5
- const fs = require ( 'fs' ) ;
6
5
const fse = require ( 'fs-extra' ) ;
7
6
const Glob = require ( 'glob' ) . Glob ;
8
- const Promise = require ( 'bluebird' ) ;
9
7
const Handlebars = require ( 'handlebars' ) ;
10
8
11
- Promise . promisifyAll ( fs ) ;
12
- Promise . promisifyAll ( fse ) ;
13
-
14
9
const classConfigs = require ( './three-class-config' ) ;
15
10
const Types = require ( './prop-types.js' ) ;
16
11
@@ -87,7 +82,7 @@ const IGNORE_FILES = [
87
82
function compileTemplate ( templateName ) {
88
83
templateName = path . basename ( templateName , '.mustache' ) ;
89
84
const templatePath = path . resolve ( templateDir , templateName + '.mustache' ) ;
90
- return Handlebars . compile ( fs . readFileSync ( templatePath , {
85
+ return Handlebars . compile ( fse . readFileSync ( templatePath , {
91
86
encoding : 'utf-8'
92
87
} ) ) ;
93
88
}
@@ -306,7 +301,7 @@ class JavascriptWrapper {
306
301
307
302
// check if manual file exists
308
303
const customSrcPath = path . join ( path . dirname ( this . jsDestPath ) , path . basename ( this . jsDestPath , '.js' ) + '.js' ) ;
309
- this . hasOverride = fs . existsSync ( customSrcPath ) ;
304
+ this . hasOverride = fse . existsSync ( customSrcPath ) ;
310
305
311
306
this . processSuperClass ( ) ;
312
307
this . processDependencies ( ) ;
@@ -363,7 +358,7 @@ class JavascriptWrapper {
363
358
364
359
result . absolutePath = path . resolve ( jsSrcDir , result . relativePath ) ;
365
360
let absPath = result . absolutePath ;
366
- if ( fs . existsSync ( absPath + '.js' ) ) {
361
+ if ( fse . existsSync ( absPath + '.js' ) ) {
367
362
absPath += '.js' ;
368
363
} else {
369
364
absPath += JS_AUTOGEN_EXT ;
@@ -524,7 +519,7 @@ function createJavascriptWrapper(modulePath, className) {
524
519
console . log ( 'skipping: ' + modulePath + ( className ? ':' + className : '' ) ) ;
525
520
return Promise . resolve ( false ) ;
526
521
}
527
- return fse . outputFileAsync ( wrapper . getOutputFilename ( ) , wrapper . output ) ;
522
+ return fse . outputFile ( wrapper . getOutputFilename ( ) , wrapper . output ) ;
528
523
529
524
// NOTE: Old implementation
530
525
// const wrapper = new JavascriptWrapper(modulePath);
@@ -553,7 +548,7 @@ function writeJavascriptIndexFiles() {
553
548
const dirAbsPath = path . resolve ( jsSrcDir , dirPath ) ;
554
549
555
550
// Generate list of files in dir to include in index.js as require lines
556
- return fs . readdirAsync ( dirAbsPath ) . then ( function ( dirFiles ) {
551
+ return fse . readdir ( dirAbsPath ) . then ( function ( dirFiles ) {
557
552
558
553
// get proper relative path for file
559
554
dirFiles = dirFiles . map ( function ( filename ) {
@@ -616,7 +611,7 @@ function writeJavascriptIndexFiles() {
616
611
const output = jsIndexTemplate ( context ) ;
617
612
const outputPath = path . resolve ( jsSrcDir , dirPath , 'index.js' ) ;
618
613
619
- return fse . outputFileAsync ( outputPath , output ) ;
614
+ return fse . outputFile ( outputPath , output ) ;
620
615
621
616
} ) ;
622
617
}
@@ -668,7 +663,7 @@ class PythonWrapper {
668
663
this . pyBaseRelativePath = relativePathToPythonImportPath ( this . pyBaseRelativePath ) ;
669
664
670
665
// check if manual file exists
671
- this . hasOverride = fs . existsSync ( this . pyDestPath ) ;
666
+ this . hasOverride = fse . existsSync ( this . pyDestPath ) ;
672
667
673
668
this . hasParameters = false ;
674
669
@@ -681,7 +676,6 @@ class PythonWrapper {
681
676
this . processConstructorArgs ( ) ;
682
677
683
678
// Template and context
684
- this . template = pyWrapperTemplate ;
685
679
this . context = {
686
680
now : new Date ( ) ,
687
681
generatorScriptName : path . basename ( __filename ) ,
@@ -701,7 +695,7 @@ class PythonWrapper {
701
695
} ;
702
696
703
697
// Render template
704
- this . output = this . template ( this . context ) ;
698
+ this . output = pyWrapperTemplate ( this . context ) ;
705
699
706
700
}
707
701
@@ -727,7 +721,7 @@ class PythonWrapper {
727
721
// get path of dependency relative to module dir
728
722
result . absolutePath = path . resolve ( pySrcDir , result . relativePath ) ;
729
723
730
- if ( ! fs . existsSync ( result . absolutePath + '.py' ) ) {
724
+ if ( ! fse . existsSync ( result . absolutePath + '.py' ) ) {
731
725
result . absolutePath += '_' + AUTOGEN_EXT ;
732
726
}
733
727
@@ -859,8 +853,10 @@ function createPythonWrapper(modulePath, className) {
859
853
console . log ( 'skipping: ' + modulePath + ( className ? ':' + className : '' ) ) ;
860
854
return Promise . resolve ( false ) ;
861
855
}
862
- return fse . outputFileAsync ( wrapper . getOutputFilename ( ) , wrapper . output ) ;
856
+ let fname = wrapper . getOutputFilename ( ) ;
857
+ let pyPromise = fse . outputFile ( fname , wrapper . output ) ;
863
858
859
+ return pyPromise ;
864
860
}
865
861
866
862
function createPythonModuleInitFile ( modulePath ) {
@@ -892,7 +888,7 @@ function createTopLevelPythonModuleFile() {
892
888
if ( / a u t o g e n / . test ( moduleName ) ) {
893
889
const overrideName = moduleName . replace ( '_autogen' , '' ) ;
894
890
const overridePath = path . resolve ( pySrcDir , modulePath , overrideName + '.py' ) ;
895
- if ( fs . existsSync ( overridePath ) ) {
891
+ if ( fse . existsSync ( overridePath ) ) {
896
892
console . log ( 'Python override exists: ' + overrideName + '. Skipping...' ) ;
897
893
return ;
898
894
}
@@ -925,7 +921,7 @@ function createTopLevelPythonModuleFile() {
925
921
const output = pyTopLevelInitTemplate ( context ) ;
926
922
const outFilePath = path . resolve ( pySrcDir , '__init__.py' ) ;
927
923
928
- return fse . outputFileAsync ( outFilePath , output ) ;
924
+ return fse . outputFile ( outFilePath , output ) ;
929
925
930
926
} ) ;
931
927
@@ -945,7 +941,7 @@ function createJavascriptFiles() {
945
941
function createPythonFiles ( ) {
946
942
947
943
// Prevent python file generation when outside dir (e.g. npm install in dependent)
948
- if ( ! fs . existsSync ( pySrcDir ) ) {
944
+ if ( ! fse . existsSync ( pySrcDir ) ) {
949
945
return Promise . resolve ( ) ;
950
946
}
951
947
@@ -975,6 +971,7 @@ function createPythonFiles() {
975
971
976
972
}
977
973
974
+
978
975
function generateFiles ( ) {
979
976
980
977
return Promise . all ( [
0 commit comments