UNPKG

@applicaster/zapplicaster-cli

Version:

CLI Tool for the zapp app and Quick Brick project

161 lines (153 loc) 5.23 kB
/** * Commands module * @module @applicaster/zapplicaster-cli/commands * this module provides the declaration of commands provided by the CLI * and a function to automatically register them with the commander module */ const R = require("ramda"); const { prepareWorkspace } = require("./prepareWorkspace"); const { migrateZappPlugin } = require("./migrateZappPlugin"); const { reloadConfig } = require("./reloadConfig"); const { publishPlugin } = require("./publishPlugin"); const { init } = require("./init"); const { runApp } = require("./runApp"); const { publishPackage } = require("./publishPackage"); /** * creates a function that can register commands with a given commander program * * @param {Object} program: a commander program instance * @return {Function} */ function registerCommand(program) { /** * takes a commander command declaration and registers * it with the commander module * Equivalent to running * program.command(command.syntax).option(...options).action(action) * @param {Object} command: a command is an object with three properties * @param {String} command.syntax: declaration of the command syntax * @param {Array} command.options: optional arguments required for the command * @param {Function} command.action : action to perform when this command is invoked */ return function (command) { const { syntax, action, options } = command; return R.compose( R.invoker(1, "action")(action), R.reduce((_program, option) => _program.option(...option), R.__, options), R.invoker(1, "command")(syntax) )(program); }; } /** * @typedef {Object} command - follows the rules of the commander package command syntax * https://www.npmjs.com/package/commander * @typedef {String} command.syntax: syntax of the command. Can contain arguments, the last one being optionnaly * variadic (i.e. fn(arg1, arg2, ...arg3)) * @typedef {Array} command.options: options available for the command - each command is an array represening the * arguments to pass to program.option() * @typedef {Function} command.action: function to execute when the command is invoked in the CLI tool. * The signature of the function contains the arguments passed to the CLI tool, and an object containing all the * options passed like function commandAction(...cliArgs, cliOptions) {} */ /** * Declaration of available cli commands * To add new commands, append a new entry to this array, following the typedef declaration above */ const commands = [ { syntax: "prepare <appVersionId>", options: [ ["-a, --app-version-id", "App Version Id"], ["-n, --new-workspace [name], Creates a new workspace"], [ "-d, --destination-path [path]", "Define a custom output path for the template project", ], ["-v, --verbose", "Verbose option for more output"], ["-y, --yarn", "Use Yarn instead of npm"], ["-t, --template [template]", "App template to use to render the app"], ["-b, --build-mobile", "Builds the native layer of the app"], ], action: prepareWorkspace, }, { syntax: "migrate_plugin", options: [ [ "-r, --project-root [path]", "Root of the plugin path (defaults to '.')", ], [ "-n, --project-name [name]", "Override plugin name (if omited, will use name from package.json)", ], [ "-e, --entry-point [path]", "Entry point for your plugin (defautlts to ./src/App)", ], ], action: migrateZappPlugin, }, { syntax: "reload_config", options: [ ["-a, --app-version-id", "App Version Id"], [ "-d, --destination-path [path]", "Define a custom output path for the template project", ], ["-v, --verbose", "Verbose option for more output"], ], action: reloadConfig, }, { syntax: "publish_plugin [pluginPath]", options: [ ["-y, --yarn", "Use Yarn instead of npm"], ["-d, --dry-run", "skip the actual publish actions for testing purposes"], ["-p, --plugin-path [pluginPath]", "Path of the plugin to publish"], ["-n, --next", "Publish on npm with --next tag"], ["-v, --version [version]", "Version of the plugin to create"], ["-g, --skip-git", "Doesn't commit changes to git"], [ "-s, --single-platform [singlePlatform]", "Platform to deploy. Ommit to publish for all supported platforms", ], [ "-m, --manifest-only", "Only generates the manifest file, doesn't publish the plugin", ], [ "-t, --targets [targets]", "Comma-separated list of targets (e.g., 'tv,mobile,tablet') for iterative releases", ], ], action: publishPlugin, }, { syntax: "publish_package [packageName]", options: [ ["-n, --next", "Publish on npm with --next tag"], ["-v, --version [version]", "Version of the plugin to create"], ], action: publishPackage, }, { syntax: "init", options: [], action: init, }, { syntax: "run <platform>", options: [], action: runApp, }, ]; /** * @export * */ module.exports = { registerCommand, commands, };