@stacksjs/cli 0.38.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2022 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Stacks CLI
2
+
3
+ The simple way to build beautiful CLIs.
4
+
5
+ ## ☘️ Features
6
+
7
+ - [x] Easily create beautiful CLI apps
8
+ - [x] Lightweight, beautiful and user-friendly interactive prompts
9
+ - [x] Elegant terminal spinners
10
+ - [x] Helper methods to run commands
11
+
12
+ ## 🤖 Usage
13
+
14
+ ```bash
15
+ pnpm i -D @stacksjs/cli
16
+ ```
17
+
18
+ Now, you can use it in your project:
19
+
20
+ ```js
21
+ // command.ts
22
+ // you may create create a relatively complex CLI UI/UX via the following:
23
+ import { command, log, prompts, spawn, spinner, ExitCode, italic } from '@stacksjs/cli'
24
+
25
+ const stacks = command('stacks')
26
+
27
+ stacks
28
+ .command('example', 'A dummy command') // pnpm stacks example
29
+ .option('-i, --install', 'The install option', { default: true })
30
+ .action(async (options) => {
31
+ if (options.install)
32
+ await install()
33
+
34
+ const answer = await prompts.select({
35
+ type: 'select',
36
+ message: 'Are you trying to run this command?',
37
+ choices: [
38
+ { title: 'Run the command', value: 'run' },
39
+ { title: 'Do not run the command', value: 'do-not-run' },
40
+ ],
41
+ })
42
+
43
+ if (answer === 'run')
44
+ install()
45
+ else if (answer === 'do-not-run')
46
+ log.info('Not running the command')
47
+ else process.exit(ExitCode.InvalidArgument)
48
+ })
49
+
50
+ async function install() {
51
+ try {
52
+ const spin = spinner('Running...').start()
53
+ setTimeout(() => {
54
+ spin.text = italic('This may take a little while...')
55
+ }, 5000)
56
+ await spawn('pnpm install')
57
+ spin.stop()
58
+ } catch (error) {
59
+ log.error(error)
60
+ }
61
+ }
62
+
63
+ command.help() // automatically expose a -h and --help flag
64
+ command.version(version) // automatically expose a -v and --version flag
65
+ command.parse() // parse the command
66
+ ```
67
+
68
+ You may now run the command via:
69
+
70
+ ```bash
71
+ esno command.ts
72
+ ```
73
+
74
+ To view a more detailed example, check out the [Stacks Runtime](../runtime/).
75
+
76
+ _You may also use any of the following CLI utilities:_
77
+
78
+ ```js
79
+ import {
80
+ log,
81
+ ansi256Bg, bold, dim, hidden, inverse, italic, link, reset, strikethrough, underline,
82
+ bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow,
83
+ black, blue, cyan, gray, green, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, magenta, red, white, yellow,
84
+ } from '@stacksjs/cli'
85
+
86
+ log.info(`hello ${bold(italic('world'))`)
87
+ ```
88
+
89
+ To view the full documentation, please visit [https://stacksjs.dev/cli](https://stacksjs.dev/cli).
90
+
91
+ ## 🧪 Testing
92
+
93
+ ```bash
94
+ pnpm test
95
+ ```
96
+
97
+ ## 📈 Changelog
98
+
99
+ Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
100
+
101
+ ## 💪🏼 Contributing
102
+
103
+ Please see [CONTRIBUTING](../../.github/CONTRIBUTING.md) for details.
104
+
105
+ ## 🏝 Community
106
+
107
+ For help, discussion about best practices, or any other conversation that would benefit from being searchable:
108
+
109
+ [Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
110
+
111
+ For casual chit-chat with others using this package:
112
+
113
+ [Join the Open Web Discord Server](https://discord.ow3.org)
114
+
115
+ ## 🙏🏼 Credits
116
+
117
+ Many thanks to the following core technologies & people who have contributed to this package:
118
+
119
+ - [CAC](https://github.com/cacjs/cac)
120
+ - [Ora](https://github.com/sindresorhus/ora)
121
+ - [Consola](https://github.com/unjs/consola)
122
+ - [Chris Breuer](https://github.com/chrisbbreuer)
123
+ - [All Contributors](../../contributors)
124
+
125
+ ## 📄 License
126
+
127
+ The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
128
+
129
+ Made with ❤️
@@ -0,0 +1,2 @@
1
+ export * from './install';
2
+ export * from './run';
@@ -0,0 +1,2 @@
1
+ export * from "./install.mjs";
2
+ export * from "./run.mjs";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Install an npm package.
3
+ *
4
+ * @param pkg - The package name to install.
5
+ * @returns The result of the install.
6
+ */
7
+ export declare function installPackage(pkg: string): Promise<execa.ExecaReturnValue<string>>;
8
+ /**
9
+ * Install a Stack into your project.
10
+ *
11
+ * @param pkg - The Stack name to install.
12
+ * @returns The result of the install.
13
+ */
14
+ export declare function installStack(name: string): Promise<execa.ExecaReturnValue<string>>;
@@ -0,0 +1,7 @@
1
+ import { installPackage as installPkg } from "@antfu/install-pkg";
2
+ export async function installPackage(pkg) {
3
+ return await installPkg(pkg, { silent: true });
4
+ }
5
+ export async function installStack(name) {
6
+ return await installPkg(`@stacksjs/${name}`, { silent: true });
7
+ }
@@ -0,0 +1,26 @@
1
+ import type { CliOptions, CommandResult, Result } from '@stacksjs/types';
2
+ /**
3
+ * Execute a command.
4
+ *
5
+ * @param command The command to execute.
6
+ * @param options The options to pass to the command.
7
+ * @param errorMsg The name of the error to throw if the command fails.
8
+ * @returns The result of the command.
9
+ */
10
+ export declare function exec(command: string, options?: CliOptions): any;
11
+ /**
12
+ * Run a command the Stacks way.
13
+ *
14
+ * @param command The command to run.
15
+ * @param options The options to pass to the command.
16
+ * @returns The result of the command.
17
+ */
18
+ export declare function runCommand(command: string, options?: CliOptions): Promise<any>;
19
+ /**
20
+ * Run many commands—the Stacks way.
21
+ *
22
+ * @param commands The command to run.
23
+ * @param options The options to pass to the command.
24
+ * @returns The result of the command.
25
+ */
26
+ export declare function runCommands(commands: string[], options?: CliOptions): Promise<Result<CommandResult<string>, Error>[]>;
@@ -0,0 +1,37 @@
1
+ import { italic } from "@stacksjs/cli";
2
+ import { determineDebugMode } from "@stacksjs/config";
3
+ import { ResultAsync } from "@stacksjs/errors";
4
+ import { projectPath } from "@stacksjs/path";
5
+ import { spawn } from "../command.mjs";
6
+ import { startAnimation } from "../helpers.mjs";
7
+ export function exec(command, options) {
8
+ const cwd = options?.cwd || projectPath();
9
+ const stdio = determineDebugMode(options) ? "inherit" : "ignore";
10
+ return ResultAsync.fromPromise(
11
+ spawn(command, { stdio, cwd }),
12
+ () => new Error(`Failed to execute command: ${italic(command)}`)
13
+ );
14
+ }
15
+ export async function runCommand(command, options) {
16
+ return await exec(command, options);
17
+ }
18
+ export async function runCommands(commands, options) {
19
+ let spinner;
20
+ if (!determineDebugMode(options))
21
+ spinner = startAnimation();
22
+ const results = [];
23
+ for (const command of commands) {
24
+ const result = await runCommand(command, options);
25
+ if (result.isOk())
26
+ results.push(result);
27
+ if (result.isErr()) {
28
+ if (spinner)
29
+ spinner.fail(`Failed to run command "${command}" with message: ${result.error.message}`);
30
+ results.push(result);
31
+ break;
32
+ }
33
+ }
34
+ if (spinner)
35
+ spinner.stop();
36
+ return results;
37
+ }
@@ -0,0 +1,4 @@
1
+ import { execaCommand } from 'execa';
2
+ declare const spawn: typeof execaCommand;
3
+ declare const command: (name?: string | undefined) => import("cac").CAC;
4
+ export { spawn, command };
@@ -0,0 +1,5 @@
1
+ import cac from "cac";
2
+ import { execaCommand } from "execa";
3
+ const spawn = execaCommand;
4
+ const command = cac;
5
+ export { spawn, command };
@@ -0,0 +1,3 @@
1
+ import { log } from '@stacksjs/logging';
2
+ declare const prompts: any;
3
+ export { log, prompts };
@@ -0,0 +1,4 @@
1
+ import { log } from "@stacksjs/logging";
2
+ import Prompts from "prompts";
3
+ const { prompts } = Prompts;
4
+ export { log, prompts };
@@ -0,0 +1,10 @@
1
+ import type { IntroOptions, OutroOptions } from '@stacksjs/types';
2
+ /**
3
+ * Prints the intro message.
4
+ */
5
+ export declare function intro(command: string, options?: IntroOptions): number | undefined;
6
+ /**
7
+ * Prints the outro message.
8
+ */
9
+ export declare function outro(text: string, options: OutroOptions, error?: Error): void;
10
+ export declare function startAnimation(): import("ora").Ora;
@@ -0,0 +1,42 @@
1
+ import { ExitCode } from "@stacksjs/types";
2
+ import { version } from "../package.json";
3
+ import { log } from "./console.mjs";
4
+ import { spinner } from "./spinner.mjs";
5
+ import { bgCyan, bold, cyan, dim, green, italic, red } from "./utilities.mjs";
6
+ export function intro(command, options) {
7
+ console.log();
8
+ console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
9
+ console.log();
10
+ log.info(`Preparing to run the ${bgCyan(italic(bold(` ${command} `)))} command.`);
11
+ if (options?.showPerformance === false)
12
+ return;
13
+ return performance.now();
14
+ }
15
+ export function outro(text, options, error) {
16
+ if (options.isError)
17
+ log.error(error);
18
+ else
19
+ log.success(text);
20
+ if (options.startTime) {
21
+ let time = performance.now() - options.startTime;
22
+ if (options.useSeconds) {
23
+ time = time / 1e3;
24
+ time = Math.round(time * 100) / 100;
25
+ }
26
+ if (options.isError) {
27
+ log.error(red(`in ${time}${options.useSeconds ? "s" : "ms"}`));
28
+ process.exit(ExitCode.FatalError);
29
+ } else {
30
+ log.success(green(`Done in ${time}${options.useSeconds ? "s" : "ms"}`));
31
+ process.exit(ExitCode.Success);
32
+ }
33
+ }
34
+ }
35
+ export function startAnimation() {
36
+ const spin = spinner("Running...").start();
37
+ const pleaseWait = "This may take a little while...";
38
+ setTimeout(() => {
39
+ spin.text = italic(pleaseWait);
40
+ }, 5e3);
41
+ return spin;
42
+ }
@@ -0,0 +1,7 @@
1
+ export * from './actions';
2
+ export * from './command';
3
+ export * from './console';
4
+ export * from './helpers';
5
+ export * from './spinner';
6
+ export * from './utilities';
7
+ export { ExitCode } from '@stacksjs/types';
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./actions/index.mjs";
2
+ export * from "./command.mjs";
3
+ export * from "./console.mjs";
4
+ export * from "./helpers.mjs";
5
+ export * from "./spinner.mjs";
6
+ export * from "./utilities.mjs";
7
+ export { ExitCode } from "@stacksjs/types";
@@ -0,0 +1,2 @@
1
+ import ora from 'ora';
2
+ export declare const spinner: typeof ora;
@@ -0,0 +1,2 @@
1
+ import ora from "ora";
2
+ export const spinner = ora;
@@ -0,0 +1 @@
1
+ export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from 'kolorist';
@@ -0,0 +1 @@
1
+ export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from "kolorist";
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@stacksjs/cli",
3
+ "type": "module",
4
+ "version": "0.38.1",
5
+ "packageManager": "pnpm@7.15.0",
6
+ "description": "The simple way to create beautiful CLIs.",
7
+ "author": "Chris Breuer",
8
+ "license": "MIT",
9
+ "funding": "https://github.com/sponsors/chrisbbreuer",
10
+ "homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/cli#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/stacksjs/stacks.git",
14
+ "directory": "./.stacks/core/cli"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/stacksjs/stacks/issues"
18
+ },
19
+ "keywords": [
20
+ "cli",
21
+ "commands",
22
+ "command line interface",
23
+ "spinners",
24
+ "utilities",
25
+ "helpers",
26
+ "cac",
27
+ "ora",
28
+ "consola",
29
+ "ez-spawn",
30
+ "stacks"
31
+ ],
32
+ "main": "dist/index.mjs",
33
+ "module": "dist/index.mjs",
34
+ "types": "dist/index.d.ts",
35
+ "contributors": [
36
+ "Chris Breuer <chris@ow3.org>"
37
+ ],
38
+ "files": [
39
+ "dist",
40
+ "README.md"
41
+ ],
42
+ "engines": {
43
+ "node": ">=v18.12.1",
44
+ "pnpm": ">=7.15.0"
45
+ },
46
+ "peerDependencies": {
47
+ "@antfu/install-pkg": "^0.1.1",
48
+ "@stacksjs/config": "0.38.1",
49
+ "@stacksjs/logging": "0.38.1",
50
+ "@stacksjs/path": "0.38.1",
51
+ "@stacksjs/types": "0.38.1",
52
+ "cac": "^6.7.14",
53
+ "execa": "^6.1.0",
54
+ "ora": "^6.1.2",
55
+ "prompts": "^2.4.2"
56
+ },
57
+ "devDependencies": {
58
+ "esno": "^0.16.3",
59
+ "mkdist": "^0.4.0"
60
+ },
61
+ "scripts": {
62
+ "build": "mkdist -d",
63
+ "dev": "mkdist -d",
64
+ "typecheck": "tsc --noEmit"
65
+ }
66
+ }