lscripts 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageManagerEngine = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_process_1 = require("node:process");
6
+ const rootDir = '/';
7
+ const findPackageManagerEngine = (currentDir = './') => {
8
+ if ((0, node_fs_1.existsSync)(`${currentDir}package-lock.json`))
9
+ return 'npm';
10
+ if ((0, node_fs_1.existsSync)(`${currentDir}yarn.lock`))
11
+ return 'yarn';
12
+ if ((0, node_fs_1.existsSync)(`${currentDir}pnpm-lock.yaml`))
13
+ return 'pnpm';
14
+ if ((0, node_fs_1.realpathSync)(currentDir) === rootDir)
15
+ return null;
16
+ return findPackageManagerEngine((`${currentDir}../`));
17
+ };
18
+ const getPackageManagerEngine = () => {
19
+ const packageManagerEngine = findPackageManagerEngine();
20
+ if (!packageManagerEngine) {
21
+ console.log('Please install your dependencies at least once before using lscripts.');
22
+ console.log('lscripts uses the lock file to determine which package manager you are using.');
23
+ console.log('lscripts is currently only compatible with npm, yarn and pnpm.');
24
+ (0, node_process_1.exit)(1);
25
+ }
26
+ return packageManagerEngine;
27
+ };
28
+ exports.getPackageManagerEngine = getPackageManagerEngine;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScriptsFromPackageJson = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_process_1 = require("node:process");
6
+ const rootDir = '/';
7
+ const findPackageJsonInWorkingDirOrParent = (currentDir = './') => {
8
+ if ((0, node_fs_1.existsSync)(`${currentDir}package.json`))
9
+ return JSON.parse((0, node_fs_1.readFileSync)(`${currentDir}package.json`));
10
+ if ((0, node_fs_1.realpathSync)(currentDir) === rootDir)
11
+ return null;
12
+ return findPackageJsonInWorkingDirOrParent(`${currentDir}../`);
13
+ };
14
+ const getScriptsFromPackageJson = () => {
15
+ const packageJson = findPackageJsonInWorkingDirOrParent();
16
+ if (!packageJson) {
17
+ console.log('No package.json was found in current directory or parent directories.');
18
+ console.log('Make sure you are in a NodeJS project before running lscripts.');
19
+ (0, node_process_1.exit)(1);
20
+ }
21
+ return Object.entries(packageJson.scripts);
22
+ };
23
+ exports.getScriptsFromPackageJson = getScriptsFromPackageJson;
package/dist/main.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const search_1 = __importDefault(require("@inquirer/search"));
8
+ const clipboardy_1 = __importDefault(require("clipboardy"));
9
+ const node_child_process_1 = require("node:child_process");
10
+ const options_1 = require("./options");
11
+ const get_scripts_from_package_json_1 = require("./get-scripts-from-package-json");
12
+ const get_package_manager_engine_1 = require("./get-package-manager-engine");
13
+ const shared_state_1 = require("./shared-state");
14
+ (0, options_1.parseOptions)();
15
+ const scripts = (0, get_scripts_from_package_json_1.getScriptsFromPackageJson)();
16
+ const runner = (0, get_package_manager_engine_1.getPackageManagerEngine)();
17
+ const regex = /^(.+) - /;
18
+ process.on('uncaughtException', (error) => {
19
+ if (error instanceof Error && error.name === 'ExitPromptError')
20
+ console.log('👋 until next time!');
21
+ else
22
+ throw error;
23
+ });
24
+ const source = async (input) => {
25
+ return scripts.reduce((acc, [name, command]) => {
26
+ const script = `${name} - "${command}"`;
27
+ if (input === undefined || script.includes(input))
28
+ acc.push(script);
29
+ return acc;
30
+ }, []);
31
+ };
32
+ (0, search_1.default)({
33
+ message: shared_state_1.sharedState.useCopyMode
34
+ ? 'What script do you want to copy to your clipboard ?'
35
+ : 'What script do you want to run ?',
36
+ pageSize: scripts.length,
37
+ source
38
+ }).then((script) => {
39
+ const command = `${runner} run ${script.match(regex)[1]}`;
40
+ if (shared_state_1.sharedState.useCopyMode) {
41
+ clipboardy_1.default.writeSync(command);
42
+ console.log('✅ Command copied to your clipboard!');
43
+ console.log('You can paste it and run it!');
44
+ return;
45
+ }
46
+ console.log(`🚀 ${command}`);
47
+ (0, node_child_process_1.spawn)(command, { stdio: 'inherit', shell: true })
48
+ .on('exit', process.exit);
49
+ });
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayHelpMessage = void 0;
4
+ const node_process_1 = require("node:process");
5
+ const displayHelpMessage = () => {
6
+ console.log(`Usage: lscripts [option]
7
+ Simply list and run a script form the package.json of your current node project.
8
+
9
+ option alias description
10
+ ----------- ------- -----------------------------------------------------------------
11
+ --copy -c Enables copy mode: when you pick your script, it will be copied
12
+ to your clipboard instead of being ran immediately
13
+ --version -v Displays your installed version of lscripts
14
+ --help -h Displays this help message
15
+
16
+ You can only pass one argument at a time to lscripts command.`);
17
+ (0, node_process_1.exit)(0);
18
+ };
19
+ exports.displayHelpMessage = displayHelpMessage;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayVersion = void 0;
4
+ const node_process_1 = require("node:process");
5
+ const pkg = require('../../../package.json');
6
+ const displayVersion = () => {
7
+ console.log(`You are currently using lscripts version ${pkg.version}`);
8
+ (0, node_process_1.exit)(0);
9
+ };
10
+ exports.displayVersion = displayVersion;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./display-help-message"), exports);
18
+ __exportStar(require("./use-copy-mode"), exports);
19
+ __exportStar(require("./display-version"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCopyMode = void 0;
4
+ const shared_state_1 = require("../../shared-state");
5
+ const useCopyMode = () => {
6
+ shared_state_1.sharedState.useCopyMode = true;
7
+ };
8
+ exports.useCopyMode = useCopyMode;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseOptions = void 0;
4
+ const callbacks_1 = require("./callbacks");
5
+ const node_process_1 = require("node:process");
6
+ const availableOptions = [
7
+ { flags: ['--help', '-h'], callback: callbacks_1.displayHelpMessage },
8
+ { flags: ['--version', '-v'], callback: callbacks_1.displayVersion },
9
+ { flags: ['--copy', '-c'], callback: callbacks_1.useCopyMode }
10
+ ];
11
+ const parseOptions = () => {
12
+ if (node_process_1.argv.length < 3)
13
+ return;
14
+ if (node_process_1.argv.length > 3) {
15
+ console.log('You can only pass one argument at a time to lscripts.');
16
+ console.log(`Run 'lscripts --help' for more information.`);
17
+ return (0, node_process_1.exit)(1);
18
+ }
19
+ const arg = node_process_1.argv[2];
20
+ const flag = availableOptions.find(({ flags }) => flags.includes(arg));
21
+ if (!flag) {
22
+ console.log(`Unkown argument "${arg}".`);
23
+ console.log(`Run 'lscripts --help' for more information.`);
24
+ return (0, node_process_1.exit)(1);
25
+ }
26
+ flag.callback();
27
+ };
28
+ exports.parseOptions = parseOptions;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sharedState = void 0;
4
+ exports.sharedState = {
5
+ useCopyMode: false
6
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "commonjs",
3
3
  "name": "lscripts",
4
- "version": "1.5.0",
4
+ "version": "1.5.2",
5
5
  "description": "lscripts is a command tool that allows you to list and choose a script from your package.json easely.",
6
6
  "main": "./dist/main.js",
7
7
  "exports": {