@aliens-syndicate/cli 0.1.7 → 0.1.9
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/README.es-ES.md +47 -4
- package/README.md +47 -4
- package/README.pt-BR.md +47 -4
- package/README.zh-CN.md +47 -4
- package/package.json +7 -4
- package/tools/build.mjs +217 -34
- package/tools/cli-shared.mjs +42 -11
- package/tools/cli.mjs +10 -7
- package/tools/create.mjs +54 -26
- package/tools/doctor.mjs +12 -10
- package/tools/icon-docs.mjs +9 -8
- package/tools/project-layout.mjs +17 -0
- package/tools/runtime.mjs +252 -41
- package/tools/starter/ai/rules/architecture.rule +2 -2
- package/tools/update.mjs +71 -5
- package/tools/{style-docs.mjs → utilities-docs.mjs} +92 -92
- package/tools/vscode-space/space.tmLanguage.json +1 -1
- package/tools/vscode-space/syntax.cjs +7 -3
package/tools/create.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { copyFile, cp, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { basename, join, relative, resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { createProjectDirectories, styleLayers } from './project-layout.mjs';
|
|
5
|
+
import { createProjectDirectories, dependencyLine, styleLayers } from './project-layout.mjs';
|
|
6
6
|
import {
|
|
7
7
|
CliError, ask, bold, cliPackage, cliVersion, confirm, cyan, defaultPort, dim, extensions, green, interactive, kebab,
|
|
8
8
|
latestVersion, ok, parseFlags, pick, projectToolFiles, runCommand, validName, warn
|
|
@@ -12,26 +12,30 @@ const text = {
|
|
|
12
12
|
en: { usage: 'Usage: aliens new <project-name>', name: 'What is your project named?', fallbackName: 'my-aliens-app',
|
|
13
13
|
badName: 'Use lowercase words separated by hyphens for the project name, like my-app.', exists: 'The folder {path} already exists.',
|
|
14
14
|
utilities: 'Use utility classes in .style ({package})?', icons: 'Use the icon library ({package})?', elements: 'Use ready-made Elements ({package})?',
|
|
15
|
+
reactive: 'Add stream operators like debounce and switchMap ({package})? signal, computed and effect already come with Aliens.',
|
|
15
16
|
creating: 'Creating the Aliens project in {path}', created: 'Aliens project created in {path}', installing: 'Installing the packages with npm…',
|
|
16
|
-
unpublished: '{package} is not on npm yet, so the project starts without it.', installFailed: 'npm install failed. Enter the folder and run npm install.',
|
|
17
|
+
unpublished: '{package} is not on npm yet, so the project starts without it.', offline: 'npm did not answer for {package}, so the project starts without it.', installFailed: 'npm install failed. Enter the folder and run npm install.',
|
|
17
18
|
skipped: 'Packages not installed (--skip-install). Enter the folder and run npm install.', next: 'Next steps:' },
|
|
18
19
|
pt: { usage: 'Uso: aliens new <nome-do-projeto>', name: 'Qual é o nome do projeto?', fallbackName: 'meu-app-aliens',
|
|
19
20
|
badName: 'Use palavras minúsculas separadas por hífen no nome do projeto, como meu-app.', exists: 'A pasta {path} já existe.',
|
|
20
21
|
utilities: 'Usar classes utilitárias no .style ({package})?', icons: 'Usar a biblioteca de ícones ({package})?', elements: 'Usar Elements prontos ({package})?',
|
|
22
|
+
reactive: 'Adicionar operadores de stream como debounce e switchMap ({package})? signal, computed e effect já vêm com o Aliens.',
|
|
21
23
|
creating: 'Criando o projeto Aliens em {path}', created: 'Projeto Aliens criado em {path}', installing: 'Instalando os pacotes com o npm…',
|
|
22
|
-
unpublished: '{package} ainda não está no npm, então o projeto começa sem ele.', installFailed: 'O npm install falhou. Entre na pasta e rode npm install.',
|
|
24
|
+
unpublished: '{package} ainda não está no npm, então o projeto começa sem ele.', offline: 'O npm não respondeu sobre {package}, então o projeto começa sem ele.', installFailed: 'O npm install falhou. Entre na pasta e rode npm install.',
|
|
23
25
|
skipped: 'Pacotes não instalados (--skip-install). Entre na pasta e rode npm install.', next: 'Próximos passos:' },
|
|
24
26
|
es: { usage: 'Uso: aliens new <nombre-del-proyecto>', name: '¿Cómo se llama tu proyecto?', fallbackName: 'mi-app-aliens',
|
|
25
27
|
badName: 'Usa palabras en minúsculas separadas por guiones en el nombre del proyecto, como mi-app.', exists: 'La carpeta {path} ya existe.',
|
|
26
28
|
utilities: '¿Usar clases utilitarias en .style ({package})?', icons: '¿Usar la biblioteca de íconos ({package})?', elements: '¿Usar Elements listos ({package})?',
|
|
29
|
+
reactive: '¿Añadir operadores de stream como debounce y switchMap ({package})? signal, computed y effect ya vienen con Aliens.',
|
|
27
30
|
creating: 'Creando el proyecto Aliens en {path}', created: 'Proyecto Aliens creado en {path}', installing: 'Instalando los paquetes con npm…',
|
|
28
|
-
unpublished: '{package} todavía no está en npm, así que el proyecto empieza sin él.', installFailed: 'npm install falló. Entra en la carpeta y ejecuta npm install.',
|
|
31
|
+
unpublished: '{package} todavía no está en npm, así que el proyecto empieza sin él.', offline: 'npm no respondió sobre {package}, así que el proyecto empieza sin él.', installFailed: 'npm install falló. Entra en la carpeta y ejecuta npm install.',
|
|
29
32
|
skipped: 'Paquetes no instalados (--skip-install). Entra en la carpeta y ejecuta npm install.', next: 'Próximos pasos:' },
|
|
30
33
|
zh: { usage: '用法:aliens new <项目名称>', name: '项目叫什么名字?', fallbackName: 'my-aliens-app',
|
|
31
34
|
badName: '项目名称请使用以连字符分隔的小写单词,例如 my-app。', exists: '文件夹 {path} 已存在。',
|
|
32
35
|
utilities: '在 .style 中使用工具类({package})?', icons: '使用图标库({package})?', elements: '使用现成的 Elements({package})?',
|
|
36
|
+
reactive: '添加 debounce、switchMap 等 stream 操作符({package})?signal、computed 和 effect 已内置于 Aliens。',
|
|
33
37
|
creating: '正在 {path} 中创建 Aliens 项目', created: 'Aliens 项目已创建于 {path}', installing: '正在用 npm 安装依赖包…',
|
|
34
|
-
unpublished: '{package} 尚未发布到 npm,项目将先不包含它。', installFailed: 'npm install 失败。请进入文件夹运行 npm install。',
|
|
38
|
+
unpublished: '{package} 尚未发布到 npm,项目将先不包含它。', offline: 'npm 没有返回 {package} 的信息,项目将先不包含它。', installFailed: 'npm install 失败。请进入文件夹运行 npm install。',
|
|
35
39
|
skipped: '未安装依赖包(--skip-install)。请进入文件夹运行 npm install。', next: '下一步:' }
|
|
36
40
|
};
|
|
37
41
|
const t = (key, values = {}) => Object.entries(values).reduce((message, [name, value]) => message.replaceAll(`{${name}}`, value), pick(text)[key]);
|
|
@@ -78,25 +82,37 @@ The configuration lives in \`.config\` and the build generates the \`ai/.map\` i
|
|
|
78
82
|
The Home includes the style library, with tokens in \`project/styles/settings/\`, components in \`project/styles/components/\` and themes in \`project/styles/settings/theme.style\`.
|
|
79
83
|
Add a \`:root[data-theme="name"]\` block to that file and run the build to make the theme available in the picker.
|
|
80
84
|
|
|
81
|
-
\`.
|
|
85
|
+
\`.config\` lists the framework and every package with its version, under \`dependencies:\` and \`devDependencies:\` as in \`package.json\`. The build stops when a version differs from the installed one, and \`aliens update\` updates both.
|
|
86
|
+
|
|
87
|
+
\`.style\` reads plain CSS (\`property: value\`). To write utility classes like \`flex gap-4 md:flex-row\`, run \`npm install -D @aliens-syndicate/utilities\` and add to \`.config\`, with the installed version:
|
|
82
88
|
|
|
83
89
|
\`\`\`
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
devDependencies:
|
|
91
|
+
utilities:
|
|
92
|
+
@aliens-syndicate/utilities: 0.1.0
|
|
86
93
|
\`\`\`
|
|
87
94
|
|
|
88
95
|
To use buttons, badges, alerts, cards and fields written in Space, run \`npm install @aliens-syndicate/elements\` and add to \`.config\`:
|
|
89
96
|
|
|
90
97
|
\`\`\`
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
dependencies:
|
|
99
|
+
elements:
|
|
100
|
+
@aliens-syndicate/elements: 0.1.0
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
\`signal\`, \`computed\`, \`effect\`, \`watch\`, \`batch\` and \`cleanup:\` come with Aliens. For stream operators like \`debounce\`, \`switchMap\` and \`combineLatest\`, run \`npm install @aliens-syndicate/reactive\` and add to \`.config\`:
|
|
104
|
+
|
|
105
|
+
\`\`\`
|
|
106
|
+
dependencies:
|
|
107
|
+
reactive:
|
|
108
|
+
@aliens-syndicate/reactive: 0.1.0
|
|
93
109
|
\`\`\`
|
|
94
110
|
|
|
95
111
|
Pages and Elements live in \`project/app/pages/\` and \`project/app/elements/\`.
|
|
96
112
|
`;
|
|
97
113
|
}
|
|
98
114
|
|
|
99
|
-
function config(name, chosen) {
|
|
115
|
+
function config(name, chosen, versions) {
|
|
100
116
|
return `${configGuide}
|
|
101
117
|
project:
|
|
102
118
|
name: ${name}
|
|
@@ -113,9 +129,17 @@ build:
|
|
|
113
129
|
target: web
|
|
114
130
|
environment: local
|
|
115
131
|
|
|
132
|
+
console:
|
|
133
|
+
local: true
|
|
134
|
+
dev: true
|
|
135
|
+
|
|
116
136
|
serve:
|
|
117
137
|
port: ${defaultPort}
|
|
118
|
-
${
|
|
138
|
+
${['dependencies', 'devDependencies'].map(group => [
|
|
139
|
+
...(group === 'dependencies' ? [{ section: 'framework', name: '@aliens-syndicate/framework', version: cliVersion }] : []),
|
|
140
|
+
...chosen.filter(extension => extension.group === group).map(extension => ({ ...extension, version: versions.get(extension.name) }))
|
|
141
|
+
]).filter(list => list.length)
|
|
142
|
+
.map((list, index) => `\n${index ? 'devDependencies' : 'dependencies'}:\n${list.map(entry => ` ${entry.section}:\n ${dependencyLine(entry)}\n`).join('')}`).join('')}
|
|
119
143
|
language:
|
|
120
144
|
directory: project/language
|
|
121
145
|
default: en-US
|
|
@@ -183,10 +207,11 @@ export async function create(args) {
|
|
|
183
207
|
if (!validName(name)) throw new CliError(`${t('badName')} (${kebab(name)}?)`);
|
|
184
208
|
|
|
185
209
|
// Each extension is on unless a flag turns it off; without flags, the prompt asks with "yes" as the default.
|
|
210
|
+
// An extension marked off (reactive) works the other way: --reactive or a "yes" adds it.
|
|
186
211
|
const chosen = [];
|
|
187
212
|
for (const extension of extensions) {
|
|
188
213
|
let use = flags[extension.section];
|
|
189
|
-
if (use === undefined) use = asking ? await confirm(t(extension.section, { package: extension.name })) :
|
|
214
|
+
if (use === undefined) use = asking ? await confirm(t(extension.section, { package: extension.name }), !extension.off) : !extension.off;
|
|
190
215
|
if (use) chosen.push(extension);
|
|
191
216
|
}
|
|
192
217
|
|
|
@@ -199,26 +224,29 @@ export async function create(args) {
|
|
|
199
224
|
|
|
200
225
|
try {
|
|
201
226
|
await copyStarter(destination, name);
|
|
202
|
-
//
|
|
227
|
+
// .config and package.json carry the exact version of each package, so npm asks for every one, even with
|
|
228
|
+
// --skip-install. A package npm does not publish, or cannot answer for, stays out of the project.
|
|
203
229
|
const packages = [{ name: cliPackage }, ...chosen];
|
|
204
230
|
const versions = new Map();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
231
|
+
await Promise.all(packages.map(async entry => versions.set(entry.name, await latestVersion(entry.name))));
|
|
232
|
+
versions.set(cliPackage, versions.get(cliPackage) || cliVersion);
|
|
233
|
+
for (const extension of [...chosen]) {
|
|
234
|
+
if (versions.get(extension.name)) continue;
|
|
235
|
+
console.log(warn(t(versions.get(extension.name) === false ? 'unpublished' : 'offline', { package: extension.name })));
|
|
236
|
+
chosen.splice(chosen.indexOf(extension), 1);
|
|
212
237
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
.
|
|
238
|
+
// package.json splits the packages the same way .config does; the CLI is a devDependency.
|
|
239
|
+
const group = name => Object.fromEntries([{ name: cliPackage, group: 'devDependencies' }, ...chosen]
|
|
240
|
+
.filter(entry => entry.group === name)
|
|
241
|
+
.map(entry => [entry.name, versions.get(entry.name)]));
|
|
242
|
+
const dependencies = group('dependencies');
|
|
216
243
|
const manifest = {
|
|
217
244
|
name, version: '0.1.0', private: true, type: 'module',
|
|
218
|
-
scripts: { dev: 'aliens run', build: 'aliens build', doctor: 'aliens doctor' },
|
|
245
|
+
scripts: { dev: 'aliens run', build: 'aliens build', doctor: 'aliens doctor' },
|
|
246
|
+
...(Object.keys(dependencies).length ? { dependencies } : {}), devDependencies: group('devDependencies')
|
|
219
247
|
};
|
|
220
248
|
await writeFile(join(destination, 'package.json'), JSON.stringify(manifest, null, 2) + '\n', { flag: 'wx' });
|
|
221
|
-
await writeFile(join(destination, '.config'), config(name, chosen), { flag: 'wx' });
|
|
249
|
+
await writeFile(join(destination, '.config'), config(name, chosen, versions), { flag: 'wx' });
|
|
222
250
|
} catch (error) {
|
|
223
251
|
await rm(destination, { recursive: true, force: true });
|
|
224
252
|
throw error;
|
package/tools/doctor.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from 'node:path';
|
|
|
5
5
|
import { toolsDifferences } from './update.mjs';
|
|
6
6
|
import {
|
|
7
7
|
bold, captureCommand, installedVersion, cliPackage, cliRoot, cliVersion, compareVersions, cyan, defaultPort, dim, findProject, green,
|
|
8
|
-
latestVersion, minimumNode, parseFlags, pick, readConfig, red, runBuild, yellow
|
|
8
|
+
configExtensions, latestVersion, minimumNode, parseFlags, pick, readConfig, red, runBuild, yellow
|
|
9
9
|
} from './cli-shared.mjs';
|
|
10
10
|
|
|
11
11
|
const text = {
|
|
@@ -16,7 +16,7 @@ const text = {
|
|
|
16
16
|
noProjectFix: 'Create one with aliens new <name>, or open a project folder', project: 'Project {name} in {path}',
|
|
17
17
|
config: '.config is valid', configBad: '.config: {problem}', entryMissing: 'files: entry: {file} does not exist', tools: 'tools/ matches the CLI {version}',
|
|
18
18
|
toolsOld: 'tools/ differs from the CLI {version} in {files}', toolsFix: 'aliens update', toolsSelf: 'tools/ is the CLI itself (framework repository)',
|
|
19
|
-
extension: '{name} {version}', extensionMissing: '{name} is declared in .config ({section}:) but is not installed', extensionFix: 'npm install {name}',
|
|
19
|
+
extension: '{name} {version}', extensionMissing: '{name} is declared in .config ({section}:) but is not installed', extensionFix: 'npm install {name}', extensionVersion: '{name}: .config declares {declared}, but {version} is installed', extensionLegacy: '{name}: .config still uses from:, without the version', updateFix: 'aliens update',
|
|
20
20
|
port: 'Port {port} is free for aliens run', portUsed: 'Port {port} is in use', portDenied: 'Port {port} needs administrator rights on this system',
|
|
21
21
|
portFix: 'aliens run --port <number>, or set serve: port: in .config', build: 'aliens build passes', buildBad: 'aliens build fails: {error}',
|
|
22
22
|
buildFix: 'Fix the file and line in the message, then run aliens build', fine: 'No issues found.', issues: '{count} issue(s) found.', warnings: '{count} warning(s).' },
|
|
@@ -27,7 +27,7 @@ const text = {
|
|
|
27
27
|
noProjectFix: 'Crie um com aliens new <nome> ou abra a pasta de um projeto', project: 'Projeto {name} em {path}',
|
|
28
28
|
config: '.config válido', configBad: '.config: {problem}', entryMissing: 'files: entry: {file} não existe', tools: 'tools/ igual ao da CLI {version}',
|
|
29
29
|
toolsOld: 'tools/ diferente da CLI {version} em {files}', toolsFix: 'aliens update', toolsSelf: 'tools/ é a própria CLI (repositório do framework)',
|
|
30
|
-
extension: '{name} {version}', extensionMissing: '{name} está declarado no .config ({section}:) mas não está instalado', extensionFix: 'npm install {name}',
|
|
30
|
+
extension: '{name} {version}', extensionMissing: '{name} está declarado no .config ({section}:) mas não está instalado', extensionFix: 'npm install {name}', extensionVersion: '{name}: o .config declara {declared}, mas a {version} está instalada', extensionLegacy: '{name}: o .config ainda usa from:, sem a versão', updateFix: 'aliens update',
|
|
31
31
|
port: 'Porta {port} livre para o aliens run', portUsed: 'A porta {port} está em uso', portDenied: 'A porta {port} exige permissão de administrador neste sistema',
|
|
32
32
|
portFix: 'aliens run --port <número> ou defina serve: port: no .config', build: 'aliens build passa', buildBad: 'aliens build falha: {error}',
|
|
33
33
|
buildFix: 'Corrija o arquivo e a linha da mensagem e rode aliens build', fine: 'Nenhum problema encontrado.', issues: '{count} problema(s) encontrado(s).', warnings: '{count} aviso(s).' },
|
|
@@ -38,7 +38,7 @@ const text = {
|
|
|
38
38
|
noProjectFix: 'Crea uno con aliens new <nombre> o abre la carpeta de un proyecto', project: 'Proyecto {name} en {path}',
|
|
39
39
|
config: '.config es válido', configBad: '.config: {problem}', entryMissing: 'files: entry: {file} no existe', tools: 'tools/ coincide con la CLI {version}',
|
|
40
40
|
toolsOld: 'tools/ difiere de la CLI {version} en {files}', toolsFix: 'aliens update', toolsSelf: 'tools/ es la propia CLI (repositorio del framework)',
|
|
41
|
-
extension: '{name} {version}', extensionMissing: '{name} está declarado en .config ({section}:) pero no está instalado', extensionFix: 'npm install {name}',
|
|
41
|
+
extension: '{name} {version}', extensionMissing: '{name} está declarado en .config ({section}:) pero no está instalado', extensionFix: 'npm install {name}', extensionVersion: '{name}: .config declara {declared}, pero está instalada la {version}', extensionLegacy: '{name}: .config todavía usa from:, sin la versión', updateFix: 'aliens update',
|
|
42
42
|
port: 'Puerto {port} libre para aliens run', portUsed: 'El puerto {port} está en uso', portDenied: 'El puerto {port} requiere permisos de administrador en este sistema',
|
|
43
43
|
portFix: 'aliens run --port <número> o define serve: port: en .config', build: 'aliens build pasa', buildBad: 'aliens build falla: {error}',
|
|
44
44
|
buildFix: 'Corrige el archivo y la línea del mensaje y ejecuta aliens build', fine: 'No se encontraron problemas.', issues: '{count} problema(s) encontrado(s).', warnings: '{count} aviso(s).' },
|
|
@@ -49,7 +49,7 @@ const text = {
|
|
|
49
49
|
noProjectFix: '用 aliens new <名称> 创建一个,或打开项目文件夹', project: '项目 {name},位于 {path}',
|
|
50
50
|
config: '.config 有效', configBad: '.config:{problem}', entryMissing: 'files: entry: {file} 不存在', tools: 'tools/ 与 CLI {version} 一致',
|
|
51
51
|
toolsOld: 'tools/ 与 CLI {version} 不同:{files}', toolsFix: 'aliens update', toolsSelf: 'tools/ 就是 CLI 本身(框架仓库)',
|
|
52
|
-
extension: '{name} {version}', extensionMissing: '{name} 已在 .config({section}:)中声明,但尚未安装', extensionFix: 'npm install {name}',
|
|
52
|
+
extension: '{name} {version}', extensionMissing: '{name} 已在 .config({section}:)中声明,但尚未安装', extensionFix: 'npm install {name}', extensionVersion: '{name}:.config 声明的是 {declared},但安装的是 {version}', extensionLegacy: '{name}:.config 仍在使用 from:,没有写版本', updateFix: 'aliens update',
|
|
53
53
|
port: '端口 {port} 可供 aliens run 使用', portUsed: '端口 {port} 已被占用', portDenied: '在此系统上,端口 {port} 需要管理员权限',
|
|
54
54
|
portFix: 'aliens run --port <端口>,或在 .config 中设置 serve: port:', build: 'aliens build 通过', buildBad: 'aliens build 失败:{error}',
|
|
55
55
|
buildFix: '按消息中的文件和行号修复后,运行 aliens build', fine: '未发现问题。', issues: '发现 {count} 个问题。', warnings: '{count} 个警告。' }
|
|
@@ -114,11 +114,13 @@ export async function doctor(args) {
|
|
|
114
114
|
else report('warn', t('toolsOld', { version: cliVersion, files: changed.slice(0, 3).join(', ') + (changed.length > 3 ? '…' : '') }), t('toolsFix'));
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const version = installedVersion(root,
|
|
120
|
-
if (version) report('
|
|
121
|
-
else report('
|
|
117
|
+
// Each package of .config must be installed in the version .config declares; the build stops otherwise.
|
|
118
|
+
for (const { name: section, group, from, version: declared, legacy } of configExtensions(config)) {
|
|
119
|
+
const version = installedVersion(root, from);
|
|
120
|
+
if (!version) report('fail', t('extensionMissing', { name: from, section: `${group}: ${section}` }), t('extensionFix', { name: `${group === 'devDependencies' ? '-D ' : ''}${from}${declared ? `@${declared}` : ''}` }));
|
|
121
|
+
else if (legacy) report('warn', t('extensionLegacy', { name: from }), t('updateFix'));
|
|
122
|
+
else if (version !== 'local' && version !== declared) report('fail', t('extensionVersion', { name: from, declared, version }), t('updateFix'));
|
|
123
|
+
else report('ok', t('extension', { name: from, version }));
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
const port = Number(config?.serve?.port ?? defaultPort);
|
package/tools/icon-docs.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Generates the Icons page (project/app/pages/icon-docs) from the catalog of the icon package that .config declares
|
|
2
|
-
// under icons:
|
|
2
|
+
// under dependencies: icons: (the line @aliens-syndicate/icons/<style>: <version>). The sidebar lists every category; the runtime fills each one with its icons when the page opens,
|
|
3
3
|
// so the catalog stays out of index.html. Run it after updating the package: node tools/icon-docs.mjs
|
|
4
|
-
import { mkdir,
|
|
4
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { join, resolve } from 'node:path';
|
|
7
7
|
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { configExtensions, readConfig } from './cli-shared.mjs';
|
|
8
9
|
|
|
9
10
|
const workspace = resolve(import.meta.dirname, '..');
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
if (!from) throw new Error('icon-docs: declare the icon package in .config under icons: from:.');
|
|
11
|
+
const { from, version } = configExtensions(readConfig(workspace)).find(extension => extension.name === 'icons') ?? {};
|
|
12
|
+
if (!from || !version) throw new Error('icon-docs: declare the icon package in .config under dependencies: icons:, like @aliens-syndicate/icons/stroke-rounded: 0.1.0.');
|
|
13
13
|
const entry = /^\.{1,2}\//.test(from) ? join(workspace, from, 'index.mjs') : createRequire(join(workspace, 'package.json')).resolve(from);
|
|
14
14
|
const { createIconRenderer, readCatalog } = await import(pathToFileURL(entry).href);
|
|
15
15
|
const { categories, icons } = await readCatalog();
|
|
@@ -88,11 +88,12 @@ for (const [key, code] of [['usageInstall', 'npm install @aliens-syndicate/icons
|
|
|
88
88
|
} else if (key === 'usageConfig') {
|
|
89
89
|
add(6, 'pre variant="icon-docs-code" tabindex="0"');
|
|
90
90
|
add(7, 'code');
|
|
91
|
-
add(8, 'span={
|
|
92
|
-
add(8, 'span={
|
|
91
|
+
add(8, 'span={dependencies:} variant="icon-docs-code-line"');
|
|
92
|
+
add(8, 'span={ icons:} variant="icon-docs-code-line"');
|
|
93
93
|
add(8, 'span variant="icon-docs-code-line"');
|
|
94
|
-
add(9,
|
|
94
|
+
add(9, `span={ ${from}/}`);
|
|
95
95
|
add(9, 'span={stroke-rounded} data-icon-style-name');
|
|
96
|
+
add(9, `span={: ${version}}`);
|
|
96
97
|
} else {
|
|
97
98
|
add(6, 'pre variant="icon-docs-code" tabindex="0"');
|
|
98
99
|
add(7, 'code');
|
package/tools/project-layout.mjs
CHANGED
|
@@ -26,6 +26,23 @@ export const exampleMarker = '# Aliens example: Hero';
|
|
|
26
26
|
export const styleLayers = ['settings', 'tools', 'generic', 'elements', 'objects', 'components', 'utilities'];
|
|
27
27
|
export const elementLevels = ['atoms', 'molecules', 'organisms', 'templates'];
|
|
28
28
|
|
|
29
|
+
// .config lists the framework and the extensions as in package.json: dependencies: for what the app uses and
|
|
30
|
+
// devDependencies: for what only the build uses. Each section holds one line, "<package>[/<variant>]: <version>": the
|
|
31
|
+
// package is an npm name or a local folder (./path), the variant picks an option of the package (the icon style, as in
|
|
32
|
+
// @aliens-syndicate/icons/stroke-rounded) and the version is the one installed, quoted or not.
|
|
33
|
+
export const dependencyGroups = ['dependencies', 'devDependencies'];
|
|
34
|
+
export const dependencySections = ['framework', 'utilities', 'icons', 'elements', 'reactive'];
|
|
35
|
+
export function parseDependency(line) {
|
|
36
|
+
const version = '"?(\\d+\\.\\d+\\.\\d+[\\w.+-]*)"?';
|
|
37
|
+
const local = new RegExp(`^(\\.{1,2}\\/[^\\s:]+):\\s*${version}$`).exec(line.trim());
|
|
38
|
+
if (local) return { name: local[1], variant: null, version: local[2], spec: local[1] };
|
|
39
|
+
const match = new RegExp(`^((?:@[a-z0-9][\\w.-]*\\/)?[a-z0-9][\\w.-]*)(?:\\/([a-z0-9][\\w-]*))?:\\s*${version}$`, 'i').exec(line.trim());
|
|
40
|
+
if (!match) return null;
|
|
41
|
+
const [, name, variant = null, installed] = match;
|
|
42
|
+
return { name, variant, version: installed, spec: variant ? `${name}/${variant}` : name };
|
|
43
|
+
}
|
|
44
|
+
export const dependencyLine = ({ name, variant, version }) => `${variant ? `${name}/${variant}` : name}: ${version}`;
|
|
45
|
+
|
|
29
46
|
export async function createProjectDirectories(workspace) {
|
|
30
47
|
const directories = [
|
|
31
48
|
'project/app/pages',
|