From 168c2fb31aba59ce6af1909a24cdc14975c785a4 Mon Sep 17 00:00:00 2001 From: Joel Hughes Date: Wed, 9 Dec 2020 23:26:45 -0500 Subject: [PATCH] Revert "Revert "Added optional gen swift to genjava.js"" --- package.json | 3 ++- src/gen.sh | 2 +- tools/genjava.js | 62 ++++++++++++++++++++++++++++++------------------ 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 609f1ba13f1..b320cd0d696 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "lint": "jshint -c .jshintrc ./src/ && jscs -c .jscsrc ./src/" }, "dependencies": { - "ace-builds": "^1.4.3" + "ace-builds": "^1.4.3", + "yargs": "^16.0.0" } } diff --git a/src/gen.sh b/src/gen.sh index 591d8d527a8..c2f9884f60f 100755 --- a/src/gen.sh +++ b/src/gen.sh @@ -23,5 +23,5 @@ if [ ${CLEAN_BUILD} -eq 1 ]; then rm -r ../build/ fi -node ../tools/genjava.js ../tools/classes.js ../build/ +node ../tools/genjava.js -i ../tools/classes.js -o ../build/ node ../tools/build.js web diff --git a/tools/genjava.js b/tools/genjava.js index d13323d21ce..1c69c767c38 100644 --- a/tools/genjava.js +++ b/tools/genjava.js @@ -12,8 +12,34 @@ process.on('unhandledRejection', function(e) { process.exit(1); }); +const yargs = require("yargs/yargs") +const { hideBin } = require('yargs/helpers') +const argv = yargs(hideBin(process.argv)) + .option("i", { + alias: "input", + demandOption: "The input file is required.", + type: "string" + }) + .option("o", { + alias: "output", + demandOption: "The input dir is required.", + type: "string" + }) + .option("s", { + alias: "source", + type: "string" + }) + .option("f", { + alias: "increment", + type: "string" + }) + .option("genswift", { + type: "boolean" + }) + .argv + // enable FOAM java support. -global.FOAM_FLAGS = { 'java': true, 'debug': true, 'js': false, 'swift': true }; +global.FOAM_FLAGS = { 'java': true, 'debug': true, 'js': false, 'swift': argv.genswift }; // Enable FOAMLink mode but only if FOAMLINK_DATA is set in environment var foamlinkMode = process.env.hasOwnProperty('FOAMLINK_DATA'); @@ -39,34 +65,27 @@ require('../src/foam.js'); require('../src/foam/nanos/nanos.js'); require('../src/foam/support/support.js'); -var srcPath = __dirname + "/../src/"; - -if ( ! ( - process.argv.length == 4 || - process.argv.length == 5 || - process.argv.length == 6 ) ) { - console.log("USAGE: genjava.js input-path output-path src-path(optional) files-to-update (optional)"); - process.exit(1); +var incrementalMeta = null; +if ( argv.f ) { + incrementalMeta = JSON.parse(argv.f); + logger.debug('INCREMENTAL', argv.f); } -if ( process.argv.length > 4 && process.argv[4] !== '--' ) { - srcPath = process.argv[4]; +if ( argv.s ) { + srcPath = argv.s; if ( ! srcPath.endsWith('/') ) { srcPath = srcPath + '/'; } } -var incrementalMeta = null; -if ( process.argv.length > 5 && - process.argv[5] !== '--' && - process.argv[5] != '' ) { - incrementalMeta = JSON.parse(process.argv[5]); - logger.debug('INCREMENTAL', process.argv[5]); -} - -var indir = process.argv[2]; +var indir = argv.i indir = path_.resolve(path_.normalize(indir)); +var outdir = argv.o +outdir = path_.resolve(path_.normalize(outdir)); + +var srcPath = __dirname + "/../src/"; + var externalFile = require(indir); var classes = externalFile.classes; var abstractClasses = externalFile.abstractClasses; @@ -139,9 +158,6 @@ logger.debug('fileWhitelist', fileWhitelist); blacklist[cls] = true; }); -var outdir = process.argv[3]; -outdir = path_.resolve(path_.normalize(outdir)); - function ensurePath(p) { var i = 1 ; var parts = p.split(path_.sep);