Commits

Anonymous committed 2f8b49c

check if in commandline mode before running commader

  • Participants
  • Parent commits 979fef9

Comments (0)

Files changed (2)

       EXPORTS.requireUrl = EXPORTS.requireUrl || require('url');
       EXPORTS.requireUtil = EXPORTS.requireUtil || require('util');
       EXPORTS.requireVm = EXPORTS.requireVm || require('vm');
-      EXPORTS.ARGV = EXPORTS.ARGV || EXPORTS.requireCommander
-        .option('--build', 'build mode')
-        .option('--cover', 'enable code coverage')
-        .option('--debug', 'debug mode')
-        .option('--port []', 'http port', parseInt)
-        .parse(process.argv);
       EXPORTS.COVER = EXPORTS.COVER || new EXPORTS.requireIstanbul.Instrumenter();
       EXPORTS.COVER_FILE = EXPORTS.COVER_FILE || {};
       EXPORTS.FS_CWD = EXPORTS.FS_CWD || process.cwd();
       EXPORTS.FS_MODULE = EXPORTS.FS_MODULE || EXPORTS.requirePath.dirname(module.filename);
+      EXPORTS.IS_CLI = EXPORTS.IS_CLI || module === require.main;
       EXPORTS.JSLINT_WATCH = EXPORTS.JSLINT_WATCH || {};
       EXPORTS.MODULE = EXPORTS.MODULE || module;
       EXPORTS.MODULES = EXPORTS.MODULES || {};
       EXPORTS.STR_ASCII = EXPORTS.STR_ASCII || '\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
       EXPORTS.TEST = EXPORTS.TEST || {};
       EXPORTS.TEST_HTTP = EXPORTS.TEST_HTTP || {};
+      if (!EXPORTS.IS_CLI) {
+        //// display environment
+        console.log(['process.argv', process.argv]);
+        console.log(['cwd', process.cwd]);
+        console.log(['nodejs', process.version]);
+        console.log(['module', module.id, module.filename]);
+        return;
+      }
       //// initialize command-line code
-      if (module !== require.main) { return; }
+      EXPORTS.ARGV = EXPORTS.ARGV || EXPORTS.requireCommander
+        .option('--build', 'build mode')
+        .option('--cover', 'enable code coverage')
+        .option('--debug', 'debug mode')
+        .option('--port []', 'http port', parseInt)
+        .parse(process.argv);
       Object.keys(EXPORTS.ARGV).forEach(function (key) {
         var val = EXPORTS.ARGV[key];
         if (!val) { return; }
         try { val = JSON.parse(val); } catch (errParse) {}
         EXPORTS['IS_' + key.replace((/\W/g), '_').toUpperCase()] = val;
         switch (key) {
-        case 'debug':
-          //// display environment
-          console.log(['process.argv', process.EXPORTS.ARGV]);
-          console.log(['cwd', EXPORTS.FS_CWD]);
-          console.log(['nodejs', process.version]);
-          console.log(['module', module.id, module.filename]);
-          break;
         case 'port':
           EXPORTS.HTTP_PORT = val;
           break;
       require.extensions['.js2'] = EXPORTS.moduleLoad;
       require('tinyjs-external');
       require('./moduleMisc.js2');
-      require('./moduleUnUsed.js2');
+      require('./moduleUnused.js2');
       //// start application
       if (EXPORTS.startApp) { EXPORTS.startApp(); }
       //// main command-line code
-      if (module !== require.main) { return; }
+      if (!EXPORTS.IS_CLI) { return; }
       Object.keys(EXPORTS.ARGV).forEach(function (key) {
         var val = EXPORTS.ARGV[key];
         if (!val) { return; }
   "author": "kai zhu <kaizhu256@gmail.com>",
   "bin": { "tinyjs": "moduleMain.js" },
   "dependencies": {
+    "commander": "*",
     "express": "*",
     "fs-extra": "*",
     "istanbul": "*",
     "jslint": "*",
     "mime": "*",
-    "nopt": "*",
     "tinyjs-external": "*",
     "uglify-js": "*",
     "uglifycss": "*"