@gasket/plugin-command
Advanced tools
+0
-2
| /// <reference types="@gasket/plugin-metadata" /> | ||
| import create from './create.js'; | ||
| import configure from './configure.js'; | ||
@@ -17,3 +16,2 @@ import prepare from './prepare.js'; | ||
| hooks: { | ||
| create, | ||
| configure, | ||
@@ -20,0 +18,0 @@ prepare, |
+6
-12
| { | ||
| "name": "@gasket/plugin-command", | ||
| "version": "7.6.3", | ||
| "version": "8.0.0-next.1", | ||
| "description": "Plugin to enable other plugins to inject new gasket commands", | ||
@@ -9,3 +9,2 @@ "type": "module", | ||
| "lib", | ||
| "cjs", | ||
| "EXAMPLES.md" | ||
@@ -16,5 +15,3 @@ ], | ||
| "types": "./lib/index.d.ts", | ||
| "import": "./lib/index.js", | ||
| "require": "./cjs/index.cjs", | ||
| "default": "./cjs/index.cjs" | ||
| "import": "./lib/index.js" | ||
| }, | ||
@@ -38,4 +35,4 @@ "./package.json": "./package.json" | ||
| "commander": "^12.1.0", | ||
| "@gasket/core": "^7.7.2", | ||
| "@gasket/utils": "^7.6.4" | ||
| "@gasket/core": "^8.0.0-next.1", | ||
| "@gasket/utils": "^8.0.0-next.1" | ||
| }, | ||
@@ -45,9 +42,6 @@ "devDependencies": { | ||
| "vitest": "^3.2.0", | ||
| "@gasket/cjs": "^7.1.1", | ||
| "@gasket/plugin-metadata": "^7.5.8", | ||
| "create-gasket-app": "^7.4.18" | ||
| "@gasket/plugin-metadata": "^8.0.0-next.1", | ||
| "create-gasket-app": "^8.0.0-next.1" | ||
| }, | ||
| "scripts": { | ||
| "build": "gasket-cjs ./lib", | ||
| "build:watch": "pnpm run build --watch", | ||
| "lint": "eslint .", | ||
@@ -54,0 +48,0 @@ "lint:fix": "pnpm run lint --fix", |
-20
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "gasketBin", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return gasketBin; | ||
| } | ||
| }); | ||
| const _commander = require("commander"); | ||
| const _logo = require("./utils/logo.cjs"); | ||
| const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| const { version } = _packagejson.default; | ||
| const program = new _commander.Command(); | ||
| const gasketBin = program.name('gasket').description('CLI for custom Gasket commands').version(version).addHelpText('beforeAll', _logo.logo); |
| /** @type {import('@gasket/core').HookHandler<'commands'>} */ Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return commands; | ||
| } | ||
| }); | ||
| function commands(gasket) { | ||
| return { | ||
| id: 'build', | ||
| description: 'Gasket build command', | ||
| action: async function() { | ||
| await gasket.exec('build'); | ||
| } | ||
| }; | ||
| } |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return _default; | ||
| } | ||
| }); | ||
| const _utils = require("@gasket/utils"); | ||
| const isGasketCommand = /gasket[.-\w]*\.(js|ts|cjs|mjs)$/; | ||
| /** @type {import('@gasket/core').HookWithTimings<'configure'>} */ const plugin = { | ||
| timing: { | ||
| first: true | ||
| }, | ||
| handler: function configure(gasket, config) { | ||
| const [, maybeGasketFile, commandId] = process.argv; | ||
| const hasGasket = isGasketCommand.test(maybeGasketFile); | ||
| if (hasGasket && commandId) { | ||
| return { | ||
| command: commandId, | ||
| ...(0, _utils.applyConfigOverrides)(config, { | ||
| env: gasket.config.env, | ||
| commandId | ||
| }) | ||
| }; | ||
| } | ||
| return config; | ||
| } | ||
| }; | ||
| const _default = plugin; |
| /// <reference types="create-gasket-app" /> | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'create'>} */ "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return create; | ||
| } | ||
| }); | ||
| const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| const { name, version } = _packagejson.default; | ||
| function create(gasket, { pkg, gasketConfig }) { | ||
| gasketConfig.addPlugin('pluginCommand', name); | ||
| pkg.add('dependencies', { | ||
| [name]: `^${version}` | ||
| }); | ||
| } |
| /// <reference types="@gasket/plugin-metadata" /> | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return _default; | ||
| } | ||
| }); | ||
| const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs")); | ||
| const _configure = /*#__PURE__*/ _interop_require_default(require("./configure.cjs")); | ||
| const _prepare = /*#__PURE__*/ _interop_require_default(require("./prepare.cjs")); | ||
| const _commands = /*#__PURE__*/ _interop_require_default(require("./commands.cjs")); | ||
| const _ready = /*#__PURE__*/ _interop_require_default(require("./ready.cjs")); | ||
| const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| const { name, version, description } = _packagejson.default; | ||
| /** @type {import('@gasket/core').Plugin} */ const plugin = { | ||
| name, | ||
| version, | ||
| description, | ||
| hooks: { | ||
| create: _create.default, | ||
| configure: _configure.default, | ||
| prepare: _prepare.default, | ||
| commands: _commands.default, | ||
| ready: _ready.default, | ||
| metadata (gasket, meta) { | ||
| return { | ||
| ...meta, | ||
| commands: [ | ||
| { | ||
| name: 'build', | ||
| description: 'Gasket build command', | ||
| link: 'README.md#build' | ||
| } | ||
| ], | ||
| lifecycles: [ | ||
| { | ||
| name: 'commands', | ||
| method: 'exec', | ||
| description: 'Add custom commands to the CLI', | ||
| link: 'README.md#commands', | ||
| parent: 'prepare' | ||
| }, | ||
| { | ||
| name: 'build', | ||
| method: 'exec', | ||
| description: 'Gasket build lifecycle', | ||
| link: 'README.md#build', | ||
| parent: 'commands' | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| } | ||
| }; | ||
| const _default = plugin; |
| {} |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'prepare'>} */ "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return prepare; | ||
| } | ||
| }); | ||
| const _cli = require("./cli.cjs"); | ||
| const _processcommand = require("./utils/process-command.cjs"); | ||
| function prepare(gasket, config) { | ||
| if (!config.command) return config; | ||
| /** @type {(import('./index.d.ts').GasketCommandDefinition | import('./index.d.ts').GasketCommandDefinition[])[]} */ const cmdDefs = gasket.execSync('commands'); | ||
| // Flatten in case some plugins return arrays | ||
| const flattenedCmdDefs = cmdDefs.flatMap((cmdDef)=>Array.isArray(cmdDef) ? cmdDef : [ | ||
| cmdDef | ||
| ]); | ||
| flattenedCmdDefs.forEach((cmdDef)=>{ | ||
| const { command, hidden, isDefault } = (0, _processcommand.processCommand)(cmdDef); | ||
| _cli.gasketBin.addCommand(command, { | ||
| hidden, | ||
| isDefault | ||
| }); | ||
| }); | ||
| return config; | ||
| } |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'ready'>} */ "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return ready; | ||
| } | ||
| }); | ||
| const _cli = require("./cli.cjs"); | ||
| async function ready(gasket) { | ||
| if (gasket.config.command) { | ||
| _cli.gasketBin.parse(); | ||
| } | ||
| } |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "createOption", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createOption; | ||
| } | ||
| }); | ||
| const _commander = require("commander"); | ||
| function createOption(definition) { | ||
| const option = new _commander.Option(...definition.options); | ||
| const { defaultValue, conflicts, parse, hidden, required } = definition; | ||
| if (conflicts.length) option.conflicts(definition.conflicts); | ||
| if (hidden) option.hideHelp(); | ||
| if (typeof defaultValue !== 'undefined') option.default(defaultValue); | ||
| if (parse) option.argParser(parse); | ||
| if (required) option.makeOptionMandatory(); | ||
| return option; | ||
| } |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "logo", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return logo; | ||
| } | ||
| }); | ||
| const logo = ` | ||
| ▄▄▄▄████▀▀█▄ | ||
| ▄███▀▀▀▀▀▀▀█▄▄██ | ||
| ▄██▀ ▄▄▄▄▄ ▀██▌ ▄▄▄ | ||
| ▄██▀ ███▀▀▀▀█ ██ ██ ██ | ||
| █▀▀█ ██▌ ▐█▌ ▄▀▀▀█▄ ▄█▀▀▀▄ ██ ▐██▀ ▄█▀▀█▄ ▀██▀▀ | ||
| █▄▄█ ██▌ ▀▀██ ▐█▌ ▄▄▄▄██ ▀▀█▄▄▄ █████ ██▄▄██ ██ | ||
| ▀██▄ ███▄▄▄▄██ ██ ▀▄▄▄▀█▄ ▀▄▄▄█▀ ▄██▄ ██▄ ▀█▄▄▄▄ ▀█▄▄ | ||
| ▀██▄ ▀▀▀ ▀▀ ▄██▌ | ||
| ▀███▄▄▄▄▄▄▄█▀▀██ | ||
| ▀▀▀▀████▄▄█▀ | ||
| `; |
| /** | ||
| * isValidArg - Validates the argument configuration | ||
| * @type {import('../internal.d.ts').isValidArg} | ||
| */ Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "processArgs", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return processArgs; | ||
| } | ||
| }); | ||
| function isValidArg(arg) { | ||
| const keys = Object.keys(arg); | ||
| if (arg.required && arg.default) return false; | ||
| const isValid = keys.length && keys.length <= 4 && arg.name && arg.description; | ||
| return Boolean(isValid); | ||
| } | ||
| function processArgs(args) { | ||
| if (!Array.isArray(args) || !args.every(isValidArg)) throw new Error('Invalid argument(s) configuration'); | ||
| return args.reduce((acc, arg)=>{ | ||
| const def = []; | ||
| const { name, description, required = false, default: defaultValue } = arg; | ||
| if (required) { | ||
| def.push(`<${name}>`, description); | ||
| } else { | ||
| def.push(`[${name}]`, description); | ||
| } | ||
| if (defaultValue) def.push(defaultValue); | ||
| acc.push(def); | ||
| return acc; | ||
| }, []); | ||
| } |
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "processCommand", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return processCommand; | ||
| } | ||
| }); | ||
| const _commander = require("commander"); | ||
| const _processargs = require("./process-args.cjs"); | ||
| const _processoptions = require("./process-options.cjs"); | ||
| const _createoption = require("./create-option.cjs"); | ||
| const program = new _commander.Command(); | ||
| /** | ||
| * Validates the command configuration | ||
| * @type {import('../internal.d.ts').isValidCommand} | ||
| */ function isValidCommand(command) { | ||
| const keys = Object.keys(command); | ||
| return keys.length && keys.length <= 7 && command && command.id && command.description && command.action && typeof command.action === 'function'; | ||
| } | ||
| function processCommand(command) { | ||
| if (!isValidCommand(command)) throw new Error('Invalid command configuration'); | ||
| const { id, description, action, args, options, hidden = false, default: isDefault = false } = command; | ||
| const cmd = program.command(id).description(description).action(action); | ||
| if (args) { | ||
| const cmdArgs = (0, _processargs.processArgs)(args); | ||
| cmdArgs.forEach((arg)=>cmd.argument(...arg)); | ||
| } | ||
| if (options) { | ||
| const cmdOpts = (0, _processoptions.processOptions)(options); | ||
| cmdOpts.forEach((o)=>{ | ||
| const option = (0, _createoption.createOption)(o); | ||
| cmd.addOption(option); | ||
| }); | ||
| } | ||
| return { | ||
| command: cmd, | ||
| hidden, | ||
| isDefault | ||
| }; | ||
| } |
| /** | ||
| * Validate the option | ||
| * @type {import('../internal.d.ts').isValidOption} | ||
| */ Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "processOptions", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return processOptions; | ||
| } | ||
| }); | ||
| function isValidOption(option) { | ||
| const keys = Object.keys(option); | ||
| const isValid = keys.length && keys.length <= 5 && option.name && option.description; | ||
| return Boolean(isValid); | ||
| } | ||
| function processOptions(options) { | ||
| if (!Array.isArray(options) || !options.every(isValidOption)) throw new Error('Invalid option(s) configuration'); | ||
| return options.reduce((acc, option)=>{ | ||
| const def = []; | ||
| const { name, description, required = false, short, parse, type = 'string', conflicts = [], hidden = false, default: defaultValue } = option; | ||
| const format = required ? `<${name}>` : `[${name}]`; | ||
| const flags = short ? `-${short}, --${name}` : `--${name}`; | ||
| def.push(`${flags}${type !== 'boolean' ? ` ${format}` : ''}`, description); | ||
| acc.push({ | ||
| options: def, | ||
| conflicts, | ||
| hidden, | ||
| defaultValue, | ||
| parse, | ||
| required | ||
| }); | ||
| return acc; | ||
| }, []); | ||
| } |
| /// <reference types="create-gasket-app" /> | ||
| import packageJson from '../package.json' with { type: 'json' }; | ||
| const { name, version } = packageJson; | ||
| /** @type {import('@gasket/core').HookHandler<'create'>} */ | ||
| export default function create(gasket, { pkg, gasketConfig }) { | ||
| gasketConfig.addPlugin('pluginCommand', name); | ||
| pkg.add('dependencies', { | ||
| [name]: `^${version}` | ||
| }); | ||
| } |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
-20%26748
-32.07%17
-45.16%363
-49.86%1
Infinity%+ Added
+ Added
- Removed
- Removed
Updated
Updated