lscripts 1.5.1 → 1.5.3
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.
- package/dist/get-package-manager-engine.js +28 -0
- package/dist/get-scripts-from-package-json.js +23 -0
- package/dist/main.js +9 -84
- package/dist/options/callbacks/display-help-message.js +19 -0
- package/dist/options/callbacks/display-version.js +10 -0
- package/dist/options/callbacks/index.js +19 -0
- package/dist/options/callbacks/use-copy-mode.js +8 -0
- package/dist/options/index.js +28 -0
- package/dist/shared-state.js +6 -0
- package/package.json +3 -3
|
@@ -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
CHANGED
|
@@ -6,89 +6,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const search_1 = __importDefault(require("@inquirer/search"));
|
|
8
8
|
const clipboardy_1 = __importDefault(require("clipboardy"));
|
|
9
|
-
const node_fs_1 = require("node:fs");
|
|
10
|
-
const node_process_1 = require("node:process");
|
|
11
9
|
const node_child_process_1 = require("node:child_process");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
console.log(`Usage: lscripts [option]
|
|
20
|
-
Simply list and run a script form the package.json of your current node project.
|
|
21
|
-
|
|
22
|
-
option alias description
|
|
23
|
-
----------- ------- -----------------------------------------------------------------
|
|
24
|
-
--copy -c Enables copy mode: when you pick your script, it will be copied
|
|
25
|
-
to your clipboard instead of being ran immediately
|
|
26
|
-
--version -v Displays your installed version of lscripts
|
|
27
|
-
--help -h Displays this help message
|
|
28
|
-
|
|
29
|
-
You can only pass one argument at a time to lscripts command.`);
|
|
30
|
-
(0, node_process_1.exit)(0);
|
|
31
|
-
};
|
|
32
|
-
const displayVersion = () => {
|
|
33
|
-
console.log(`You are currently using lscripts version ${pkg.version}`);
|
|
34
|
-
(0, node_process_1.exit)(0);
|
|
35
|
-
};
|
|
36
|
-
const possibleFlags = [
|
|
37
|
-
{ flags: ['--copy', '-c'], callback: useCopyMode },
|
|
38
|
-
{ flags: ['--help', '-h'], callback: displayHelpMessage },
|
|
39
|
-
{ flags: ['--version', '-v'], callback: displayVersion }
|
|
40
|
-
];
|
|
41
|
-
const parseArguments = () => {
|
|
42
|
-
if (node_process_1.argv.length < 3)
|
|
43
|
-
return;
|
|
44
|
-
if (node_process_1.argv.length > 3) {
|
|
45
|
-
console.log('You can only pass one argument at a time to lscripts.');
|
|
46
|
-
console.log(`Run 'lscripts --help' for more information.`);
|
|
47
|
-
return (0, node_process_1.exit)(1);
|
|
48
|
-
}
|
|
49
|
-
const arg = node_process_1.argv[2];
|
|
50
|
-
const flag = possibleFlags.find(({ flags }) => flags.includes(arg));
|
|
51
|
-
if (!flag) {
|
|
52
|
-
console.log(`Unkown argument "${arg}".`);
|
|
53
|
-
console.log(`Run 'lscripts --help' for more information.`);
|
|
54
|
-
return (0, node_process_1.exit)(1);
|
|
55
|
-
}
|
|
56
|
-
flag.callback();
|
|
57
|
-
};
|
|
58
|
-
const findPackageJsonInWorkingDirOrParent = (currentDir = './') => {
|
|
59
|
-
if ((0, node_fs_1.existsSync)(`${currentDir}package.json`))
|
|
60
|
-
return JSON.parse((0, node_fs_1.readFileSync)(`${currentDir}package.json`));
|
|
61
|
-
if ((0, node_fs_1.realpathSync)(currentDir) === rootDir)
|
|
62
|
-
return null;
|
|
63
|
-
return findPackageJsonInWorkingDirOrParent(`${currentDir}../`);
|
|
64
|
-
};
|
|
65
|
-
const getScriptsFromPackageJson = (packageJson) => Object.entries(packageJson.scripts);
|
|
66
|
-
const getPackageManagerEngine = (currentDir = './') => {
|
|
67
|
-
if ((0, node_fs_1.existsSync)(`${currentDir}package-lock.json`))
|
|
68
|
-
return 'npm';
|
|
69
|
-
if ((0, node_fs_1.existsSync)(`${currentDir}yarn.lock`))
|
|
70
|
-
return 'yarn';
|
|
71
|
-
if ((0, node_fs_1.existsSync)(`${currentDir}pnpm-lock.yaml`))
|
|
72
|
-
return 'pnpm';
|
|
73
|
-
if ((0, node_fs_1.realpathSync)(currentDir) === rootDir)
|
|
74
|
-
return null;
|
|
75
|
-
return getPackageManagerEngine((`${currentDir}../`));
|
|
76
|
-
};
|
|
77
|
-
parseArguments();
|
|
78
|
-
const packageJson = findPackageJsonInWorkingDirOrParent();
|
|
79
|
-
if (!packageJson) {
|
|
80
|
-
console.log('No package.json was found in current directory or parent directories.');
|
|
81
|
-
console.log('Make sure you are in a NodeJS project before running lscripts.');
|
|
82
|
-
(0, node_process_1.exit)(1);
|
|
83
|
-
}
|
|
84
|
-
const scripts = getScriptsFromPackageJson(packageJson);
|
|
85
|
-
const runner = getPackageManagerEngine();
|
|
86
|
-
if (!runner) {
|
|
87
|
-
console.log('Please install your dependencies at least once before using lscripts.');
|
|
88
|
-
console.log('lscripts uses the lock file to determine which package manager you are using.');
|
|
89
|
-
console.log('lscripts is currently only compatible with npm, yarn and pnpm.');
|
|
90
|
-
(0, node_process_1.exit)(1);
|
|
91
|
-
}
|
|
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)();
|
|
92
17
|
const regex = /^(.+) - /;
|
|
93
18
|
process.on('uncaughtException', (error) => {
|
|
94
19
|
if (error instanceof Error && error.name === 'ExitPromptError')
|
|
@@ -105,14 +30,14 @@ const source = async (input) => {
|
|
|
105
30
|
}, []);
|
|
106
31
|
};
|
|
107
32
|
(0, search_1.default)({
|
|
108
|
-
message:
|
|
33
|
+
message: shared_state_1.sharedState.useCopyMode
|
|
109
34
|
? 'What script do you want to copy to your clipboard ?'
|
|
110
35
|
: 'What script do you want to run ?',
|
|
111
36
|
pageSize: scripts.length,
|
|
112
37
|
source
|
|
113
38
|
}).then((script) => {
|
|
114
39
|
const command = `${runner} run ${script.match(regex)[1]}`;
|
|
115
|
-
if (
|
|
40
|
+
if (shared_state_1.sharedState.useCopyMode) {
|
|
116
41
|
clipboardy_1.default.writeSync(command);
|
|
117
42
|
console.log('✅ Command copied to your clipboard!');
|
|
118
43
|
console.log('You can paste it and run it!');
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "commonjs",
|
|
3
3
|
"name": "lscripts",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.3",
|
|
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": {
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@inquirer/search": "^3.1.1",
|
|
34
|
-
"clipboardy": "^
|
|
34
|
+
"clipboardy": "^5.3.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@commitlint/cli": "^19.8.1",
|
|
38
38
|
"@commitlint/config-conventional": "^19.8.1",
|
|
39
39
|
"husky": "^9.1.7",
|
|
40
|
-
"semantic-release": "^
|
|
40
|
+
"semantic-release": "^25.0.9",
|
|
41
41
|
"typescript": "^5.9.2"
|
|
42
42
|
}
|
|
43
43
|
}
|