@aliens-syndicate/cli 0.1.4 → 0.1.5
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/package.json +1 -1
- package/tools/cli.mjs +56 -16
package/package.json
CHANGED
package/tools/cli.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Entry point of the @aliens-syndicate/cli package. aliens help lists the commands; each one lives in its own module.
|
|
3
|
-
import
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
4
5
|
import {
|
|
5
|
-
CliError, bold, cliVersion, installedVersion, cyan, defaultPort, dim, findProject, parseFlags, pick, readConfig, red, requireProject, runBuild
|
|
6
|
+
CliError, bold, captureCommand, cliPackage, cliRoot, cliVersion, installedVersion, cyan, defaultPort, dim, findProject, parseFlags, pick, readConfig, red, requireProject, runBuild
|
|
6
7
|
} from './cli-shared.mjs';
|
|
7
8
|
|
|
8
9
|
const commands = [
|
|
@@ -55,13 +56,13 @@ const commands = [
|
|
|
55
56
|
|
|
56
57
|
const labels = {
|
|
57
58
|
en: { usage: 'Usage', commands: 'Commands', options: 'Options', aliases: 'alias', more: 'Run aliens <command> --help to see its options.',
|
|
58
|
-
unknown: 'Unknown command "{command}".', suggestion: 'Did you mean {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'System', project: 'Project', packages: 'Packages' },
|
|
59
|
+
unknown: 'Unknown command "{command}".', suggestion: 'Did you mean {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'System', project: 'Project', packages: 'Packages', packageManager: 'Package Manager', extensions: 'extensions', package: 'Package', version: 'Version', missing: 'not installed', repository: 'this repository', outside: 'Run aliens version inside a project to see its packages.' },
|
|
59
60
|
pt: { usage: 'Uso', commands: 'Comandos', options: 'Opções', aliases: 'atalho', more: 'Rode aliens <comando> --help para ver as opções dele.',
|
|
60
|
-
unknown: 'Comando desconhecido "{command}".', suggestion: 'Você quis dizer {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'Sistema', project: 'Projeto', packages: 'Pacotes' },
|
|
61
|
+
unknown: 'Comando desconhecido "{command}".', suggestion: 'Você quis dizer {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'Sistema', project: 'Projeto', packages: 'Pacotes', packageManager: 'Gerenciador de pacotes', extensions: 'extensões', package: 'Pacote', version: 'Versão', missing: 'não instalado', repository: 'este repositório', outside: 'Rode aliens version dentro de um projeto para ver os pacotes dele.' },
|
|
61
62
|
es: { usage: 'Uso', commands: 'Comandos', options: 'Opciones', aliases: 'atajo', more: 'Ejecuta aliens <comando> --help para ver sus opciones.',
|
|
62
|
-
unknown: 'Comando desconocido "{command}".', suggestion: '¿Quisiste decir {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'Sistema', project: 'Proyecto', packages: 'Paquetes' },
|
|
63
|
+
unknown: 'Comando desconocido "{command}".', suggestion: '¿Quisiste decir {suggestion}?', cli: 'Aliens CLI', node: 'Node.js', os: 'Sistema', project: 'Proyecto', packages: 'Paquetes', packageManager: 'Gestor de paquetes', extensions: 'extensiones', package: 'Paquete', version: 'Versión', missing: 'no instalado', repository: 'este repositorio', outside: 'Ejecuta aliens version dentro de un proyecto para ver sus paquetes.' },
|
|
63
64
|
zh: { usage: '用法', commands: '命令', options: '选项', aliases: '别名', more: '运行 aliens <命令> --help 查看该命令的选项。',
|
|
64
|
-
unknown: '未知命令“{command}”。', suggestion: '你是想输入 {suggestion} 吗?', cli: 'Aliens CLI', node: 'Node.js', os: '系统', project: '项目', packages: '依赖包' }
|
|
65
|
+
unknown: '未知命令“{command}”。', suggestion: '你是想输入 {suggestion} 吗?', cli: 'Aliens CLI', node: 'Node.js', os: '系统', project: '项目', packages: '依赖包', packageManager: '包管理器', extensions: '扩展', package: '依赖包', version: '版本', missing: '未安装', repository: '本仓库', outside: '在项目中运行 aliens version 可查看其依赖包。' }
|
|
65
66
|
};
|
|
66
67
|
const label = pick(labels);
|
|
67
68
|
|
|
@@ -95,20 +96,59 @@ async function build(args) {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
|
|
99
|
+
// The banner of aliens version, in the figlet Standard font, painted in greens from dark to light like Angular's ng version.
|
|
100
|
+
const banner = [
|
|
101
|
+
' _ _ _ ____ _ ___',
|
|
102
|
+
' / \\ | |(_) ___ _ __ ___ / ___|| | |_ _|',
|
|
103
|
+
" / _ \\ | || | / _ \\ | '_ \\ / __| | | | | | |",
|
|
104
|
+
' / ___ \\ | || || __/ | | | |\\__ \\ | |___ | |___ | |',
|
|
105
|
+
'/_/ \\_\\|_||_| \\___| |_| |_||___/ \\____||_____||___|'
|
|
106
|
+
];
|
|
107
|
+
const colorful = () => process.stdout.isTTY && !process.env.NO_COLOR;
|
|
108
|
+
const shade = (code, text) => colorful() ? `\x1b[1;38;5;${code}m${text}\x1b[0m` : text;
|
|
109
|
+
|
|
98
110
|
async function version(args) {
|
|
99
111
|
parseFlags(args);
|
|
100
|
-
const
|
|
112
|
+
const npm = await captureCommand('npm', ['--version'], { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
101
113
|
const root = findProject();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
const config = root ? readConfig(root) : null;
|
|
115
|
+
const info = [[label.cli, cliVersion], [label.node, process.versions.node],
|
|
116
|
+
[label.packageManager, npm.code === 0 ? `npm ${npm.output}` : '—'], [label.os, `${process.platform} ${process.arch}`]];
|
|
117
|
+
const extensionPackages = config ? Object.values(config).map(values => values.from).filter(name => name && !/^\.{1,2}\//.test(name)) : [];
|
|
118
|
+
if (config) info.push([label.project, `${config.project?.name ?? '?'} ${config.project?.version ?? ''}`.trim()]);
|
|
119
|
+
|
|
120
|
+
console.log('');
|
|
121
|
+
banner.forEach((line, index) => console.log(shade([22, 28, 34, 40, 46][index], line)));
|
|
122
|
+
console.log('');
|
|
123
|
+
for (const [name, value] of info) console.log(`${name}: ${value}`);
|
|
124
|
+
if (config) {
|
|
125
|
+
const sections = Object.entries(config).filter(([, values]) => values.from).map(([section]) => section);
|
|
126
|
+
if (sections.length) console.log(dim(`... ${label.extensions}: ${sections.join(', ')}`));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!root) {
|
|
130
|
+
console.log('\n' + dim(label.outside));
|
|
131
|
+
console.log('');
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// The table lists every @aliens-syndicate package of the project: the ones in package.json and the ones .config declares.
|
|
135
|
+
const manifestPath = join(root, 'package.json');
|
|
136
|
+
const manifest = existsSync(manifestPath) ? JSON.parse(readFileSync(manifestPath, 'utf8')) : {};
|
|
137
|
+
const names = new Set([...Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }), ...extensionPackages]
|
|
138
|
+
.filter(name => name.startsWith('@aliens-syndicate/')));
|
|
139
|
+
if (root === cliRoot) names.add(cliPackage);
|
|
140
|
+
const rows = [...names].sort().map(name => {
|
|
141
|
+
const found = name === cliPackage && root === cliRoot ? `${cliVersion} ${dim(`(${label.repository})`)}` : installedVersion(root, name);
|
|
142
|
+
return [name, found ?? red(label.missing)];
|
|
143
|
+
});
|
|
144
|
+
if (!rows.length) {
|
|
145
|
+
console.log('');
|
|
146
|
+
return;
|
|
108
147
|
}
|
|
109
|
-
const width = Math.max(...rows.map(([name]) => name.length)) +
|
|
110
|
-
console.log(`\n
|
|
111
|
-
|
|
148
|
+
const width = Math.max(label.package.length, ...rows.map(([name]) => name.length)) + 6;
|
|
149
|
+
console.log(`\n${bold(label.package.padEnd(width))}${bold(label.version)}`);
|
|
150
|
+
console.log(dim('-'.repeat(width + 18)));
|
|
151
|
+
for (const [name, value] of rows) console.log(`${name.padEnd(width)}${value}`);
|
|
112
152
|
console.log('');
|
|
113
153
|
}
|
|
114
154
|
|