Skip to content

Commit 528a7e2

Browse files
committed
Cleanup various
1 parent 07ccc44 commit 528a7e2

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

js/scripts/generate-wrappers.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22

33
const _ = require('underscore');
44
const path = require('path');
5-
const fs = require('fs');
65
const fse = require('fs-extra');
76
const Glob = require('glob').Glob;
8-
const Promise = require('bluebird');
97
const Handlebars = require('handlebars');
108

11-
Promise.promisifyAll(fs);
12-
Promise.promisifyAll(fse);
13-
149
const classConfigs = require('./three-class-config');
1510
const Types = require('./prop-types.js');
1611

@@ -87,7 +82,7 @@ const IGNORE_FILES = [
8782
function compileTemplate(templateName) {
8883
templateName = path.basename(templateName, '.mustache');
8984
const templatePath = path.resolve(templateDir, templateName + '.mustache');
90-
return Handlebars.compile(fs.readFileSync(templatePath, {
85+
return Handlebars.compile(fse.readFileSync(templatePath, {
9186
encoding: 'utf-8'
9287
}));
9388
}
@@ -306,7 +301,7 @@ class JavascriptWrapper {
306301

307302
// check if manual file exists
308303
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);
310305

311306
this.processSuperClass();
312307
this.processDependencies();
@@ -363,7 +358,7 @@ class JavascriptWrapper {
363358

364359
result.absolutePath = path.resolve(jsSrcDir, result.relativePath);
365360
let absPath = result.absolutePath;
366-
if (fs.existsSync(absPath + '.js')) {
361+
if (fse.existsSync(absPath + '.js')) {
367362
absPath += '.js';
368363
} else {
369364
absPath += JS_AUTOGEN_EXT;
@@ -524,7 +519,7 @@ function createJavascriptWrapper(modulePath, className) {
524519
console.log('skipping: ' + modulePath + (className ? ':' + className : ''));
525520
return Promise.resolve(false);
526521
}
527-
return fse.outputFileAsync(wrapper.getOutputFilename(), wrapper.output);
522+
return fse.outputFile(wrapper.getOutputFilename(), wrapper.output);
528523

529524
// NOTE: Old implementation
530525
// const wrapper = new JavascriptWrapper(modulePath);
@@ -553,7 +548,7 @@ function writeJavascriptIndexFiles() {
553548
const dirAbsPath = path.resolve(jsSrcDir, dirPath);
554549

555550
// 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) {
557552

558553
// get proper relative path for file
559554
dirFiles = dirFiles.map(function(filename) {
@@ -616,7 +611,7 @@ function writeJavascriptIndexFiles() {
616611
const output = jsIndexTemplate(context);
617612
const outputPath = path.resolve(jsSrcDir, dirPath, 'index.js');
618613

619-
return fse.outputFileAsync(outputPath, output);
614+
return fse.outputFile(outputPath, output);
620615

621616
});
622617
}
@@ -668,7 +663,7 @@ class PythonWrapper {
668663
this.pyBaseRelativePath = relativePathToPythonImportPath(this.pyBaseRelativePath);
669664

670665
// check if manual file exists
671-
this.hasOverride = fs.existsSync(this.pyDestPath);
666+
this.hasOverride = fse.existsSync(this.pyDestPath);
672667

673668
this.hasParameters = false;
674669

@@ -681,7 +676,6 @@ class PythonWrapper {
681676
this.processConstructorArgs();
682677

683678
// Template and context
684-
this.template = pyWrapperTemplate;
685679
this.context = {
686680
now: new Date(),
687681
generatorScriptName: path.basename(__filename),
@@ -701,7 +695,7 @@ class PythonWrapper {
701695
};
702696

703697
// Render template
704-
this.output = this.template(this.context);
698+
this.output = pyWrapperTemplate(this.context);
705699

706700
}
707701

@@ -727,7 +721,7 @@ class PythonWrapper {
727721
// get path of dependency relative to module dir
728722
result.absolutePath = path.resolve(pySrcDir, result.relativePath);
729723

730-
if (!fs.existsSync(result.absolutePath + '.py')) {
724+
if (!fse.existsSync(result.absolutePath + '.py')) {
731725
result.absolutePath += '_' + AUTOGEN_EXT;
732726
}
733727

@@ -859,8 +853,10 @@ function createPythonWrapper(modulePath, className) {
859853
console.log('skipping: ' + modulePath + (className ? ':' + className : ''));
860854
return Promise.resolve(false);
861855
}
862-
return fse.outputFileAsync(wrapper.getOutputFilename(), wrapper.output);
856+
let fname = wrapper.getOutputFilename();
857+
let pyPromise = fse.outputFile(fname, wrapper.output);
863858

859+
return pyPromise;
864860
}
865861

866862
function createPythonModuleInitFile(modulePath) {
@@ -892,7 +888,7 @@ function createTopLevelPythonModuleFile() {
892888
if (/autogen/.test(moduleName)) {
893889
const overrideName = moduleName.replace('_autogen', '');
894890
const overridePath = path.resolve(pySrcDir, modulePath, overrideName + '.py');
895-
if (fs.existsSync(overridePath)) {
891+
if (fse.existsSync(overridePath)) {
896892
console.log('Python override exists: ' + overrideName + '. Skipping...');
897893
return;
898894
}
@@ -925,7 +921,7 @@ function createTopLevelPythonModuleFile() {
925921
const output = pyTopLevelInitTemplate(context);
926922
const outFilePath = path.resolve(pySrcDir, '__init__.py');
927923

928-
return fse.outputFileAsync(outFilePath, output);
924+
return fse.outputFile(outFilePath, output);
929925

930926
});
931927

@@ -945,7 +941,7 @@ function createJavascriptFiles() {
945941
function createPythonFiles() {
946942

947943
// Prevent python file generation when outside dir (e.g. npm install in dependent)
948-
if (!fs.existsSync(pySrcDir)) {
944+
if (!fse.existsSync(pySrcDir)) {
949945
return Promise.resolve();
950946
}
951947

@@ -975,6 +971,7 @@ function createPythonFiles() {
975971

976972
}
977973

974+
978975
function generateFiles() {
979976

980977
return Promise.all([

js/scripts/prop-types.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BaseType {
1313
if (this.defaultValue === false) { return 'False'; }
1414
if (this.defaultValue === true) { return 'True'; }
1515
if (this.defaultValue === 0) { return '0'; }
16-
if (this.defaultValue === '') { return '""'; }
16+
if (this.defaultValue === '') { return "''"; }
1717
if (this.defaultValue === Infinity) { return "float('inf')"; }
1818
if (this.defaultValue === -Infinity) { return "-float('inf')"; }
1919
if (!this.defaultValue) { return 'None'; }
@@ -99,7 +99,7 @@ class ForwardDeclaredThreeType extends ThreeType {
9999

100100
class InitializedThreeType extends ThreeType {
101101
getJSPropertyValue() {
102-
return '"uninitialized"';
102+
return "'uninitialized'";
103103
}
104104
getPythonDefaultValue() {
105105
return 'UninitializedSentinel';
@@ -304,7 +304,7 @@ class Color extends BaseType {
304304
constructor(defaultValue, options) {
305305
super();
306306
options = options || {};
307-
this.defaultValue = defaultValue || "#ffffff";
307+
this.defaultValue = defaultValue || '#ffffff';
308308
this.nullable = options.nullable === true;
309309
}
310310
getTraitlet() {
@@ -319,7 +319,7 @@ class Color extends BaseType {
319319
class ColorArray extends BaseType {
320320
constructor(defaultValue) {
321321
super();
322-
this.defaultValue = defaultValue || ["#ffffff"];
322+
this.defaultValue = defaultValue || ['#ffffff'];
323323
}
324324
getTraitlet() {
325325
return `List(trait=Unicode(), default_value=${this.getPythonDefaultValue()}).tag(sync=True)`;

0 commit comments

Comments
 (0)