Beispiel #1
0
  /**
   * List the registered works into the Justo.json file.
   *
   * @param pth:string  The Justo.json file path.
   * @param opts:object The options.
   */
  static listCatalogedTasks(pth, opts) {
    const Loader = require(path.join(process.cwd(), "node_modules/justo-loader")).Loader;
    const table = require("text-table");
    var justo, config, tbl;

    //(1) read Justo.json and Justo.js
    config = JustoJson.read(pth, opts);
    justo = Loader.loadJusto();
    justo.initialize(config);
    Loader.load(config.runner.main);

    //(2) show works
    tbl = [];
    for (let name of Object.keys(justo.runner.catalog.tasks).sort()) {
      let task = justo.runner.catalog.get(name).__task__;

      tbl.push([
        task.name,
        task.desc || ""
      ]);
    }

    if (tbl.length > 0) tbl = [["Name", "Description"]].concat(tbl);
    console.log(table(tbl));
  }
Beispiel #2
0
  // /**
  //  * Download the standalone project and run the cataloged tasks.
  //  *
  //  * @param src:string        The source URL.
  //  * @param calls:string[]    The tasks to run specified by the user.
  //  * @param opts:object       The CLI options specified by the user: only (boolean).
  //  */
  // static runDownloadableModule(src, calls, opts) {
  //   const download = require("justo-download");
  //   const sync = require("justo-sync");
  //   const unzip = require("justo-unzip");
  //   const url = require("url");
  //   const zip = path.basename(url.parse(src).path);
  //   var res;
  //
  //   //(1) download
  //   sync(function(done) {
  //     console.log(`  Downloading ${src}...`);
  //     download(src, process.cwd(), done);
  //   });
  //
  //   //(2) unzip
  //   sync(function(done) {
  //     console.log(`  Unzipping ${zip}...`);
  //     unzip(zip, process.cwd(), function(error) {
  //       if (error) return done(error);
  //
  //       console.log(`  Removing ${zip}...`);
  //       fs.remove(zip);
  //       done();
  //     });
  //   });
  //
  //
  //   //(3) run tasks
  //   var dir = basename(zip, ".zip");
  //   console.log(`  Changing to ${dir}...`);
  //   process.chdir(dir);
  //
  //   console.log("  Installing dependencies...");
  //   child_process.spawnSync("npm" + (os.platform().startsWith("win") ? ".cmd" : ""), ["install"]);
  //
  //   res = Cli.runCatalogedTasks("./Justo.json", calls, {only: opts.only});
  //   process.chdir("..");
  //
  //   //(4) return
  //   return res;
  // }

  /**
   * Run a module.
   *
   * @param name:string     The module name.
   * @param calls:string[]  The tasks to call.
   */
  static runInstalledModule(name, calls, opts) {
    const Calls = require("./Calls").default;
    var Loader, justo, justojson;

    //(1) cd module dir
    process.chdir(path.dirname(require.resolve(name)));

    //(2) arguments
    if (!calls || calls.length === 0) calls = ["default"];

    //(3) read Justo.json from mmodule
    Loader = require(path.join(process.cwd(), "node_modules/justo-loader")).Loader;
    justojson = JustoJson.read("Justo.json", opts);
    justo = Loader.loadJusto();
    justo.initialize(justojson);

    //(4) load module
    require(name);

    //(5) run tasks
    justo.runner.runCatalogedTasks(Calls.parse(calls, {only: opts.only}));

    //(6) return
    return {state: justo.runner.state};
  }
Beispiel #3
0
  /**
   * Run works.
   *
   * @param justojson:string  The Justo.json file path.
   * @param calls:string[]    The tasks to run specified by the user.
   * @param opts:object       The CLI options specified by the user: only (boolean).
   *
   * @return {state}
   */
  static runCatalogedTasks(justojson, calls, opts) {
    const Loader = require(path.join(process.cwd(), "node_modules/justo-loader")).Loader;
    const Calls = require("./Calls").default;
    var justo;

    //(1) arguments
    if (!calls || calls.length === 0) calls = ["default"];
    if (!opts) opts = {only: false};

    //(2) read Justo.json and Justo.js
    justojson = JustoJson.read(justojson, opts);
    if (opts.hasOwnProperty("only")) justojson.runner.only = opts.only;
    justo = Loader.loadJusto();
    justo.initialize(justojson);
    Loader.load(justojson.runner.main);

    //(3) run
    justo.runner.runCatalogedTasks(Calls.parse(calls, opts));

    //(4) return
    return {state: justo.runner.state};
  }
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

var args = process.argv.slice(2)
  , libPath = __dirname + '/../lib'
  , fs = require('fs')
  , jake = require(libPath + '/jake')
  , api = require(libPath + '/api')
  , utils = require(libPath + '/utils')
  , Program = require(libPath + '/program').Program
  , program = new Program()
  , Loader = require(libPath + '/loader').Loader
  , loader = new Loader()
  , pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString())
  , opts
  , envVars
  , taskNames;

jake.version = pkg.version;

global.jake = jake;

process.addListener('uncaughtException', function (err) {
  program.handleErr(err);
});

program.parseArgs(args);