@konce-pt/ui 0.7.11 → 0.7.12
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/commands/add.js +21 -21
- package/dist/commands/init.js +3 -3
- package/dist/commands/list.js +3 -3
- package/dist/config.js +1 -1
- package/dist/index.js +10 -9
- package/dist/registry.js +2 -2
- package/package.json +2 -2
package/dist/commands/add.js
CHANGED
|
@@ -7,7 +7,7 @@ import { satisfies } from "../semver.js";
|
|
|
7
7
|
export async function addCommand(args) {
|
|
8
8
|
const requested = args.positionals;
|
|
9
9
|
if (requested.length === 0)
|
|
10
|
-
throw new UserError('
|
|
10
|
+
throw new UserError('Give a block name: add <name...>');
|
|
11
11
|
const { path: configPath, config } = requireConfig(process.cwd());
|
|
12
12
|
const ctx = {
|
|
13
13
|
base: flag(args, 'registry') ?? config.registry,
|
|
@@ -24,7 +24,7 @@ export async function addCommand(args) {
|
|
|
24
24
|
const toInstall = order.filter((name) => ctx.overwrite || !config.installedBlocks[name]);
|
|
25
25
|
logAlreadyInstalled(order, ctx);
|
|
26
26
|
if (toInstall.length === 0) {
|
|
27
|
-
log.info('
|
|
27
|
+
log.info('Nothing to do.');
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
// 3) Wczytaj definicje, sprawdź zależności npm.
|
|
@@ -36,7 +36,7 @@ export async function addCommand(args) {
|
|
|
36
36
|
const plan = await planWrites(toInstall, metas, ctx);
|
|
37
37
|
// 5) Zapis (albo raport dry-run).
|
|
38
38
|
if (dryRun) {
|
|
39
|
-
log.info('— dry-run:
|
|
39
|
+
log.info('— dry-run: nothing written —');
|
|
40
40
|
for (const p of plan)
|
|
41
41
|
log.step(`${labelFor(p.action)} ${p.target}`);
|
|
42
42
|
}
|
|
@@ -57,7 +57,7 @@ function resolveOrder(requested, index) {
|
|
|
57
57
|
if (done.has(name))
|
|
58
58
|
return;
|
|
59
59
|
if (stack.has(name))
|
|
60
|
-
throw new UserError(`
|
|
60
|
+
throw new UserError(`A registry dependency cycle around the block "${name}".`);
|
|
61
61
|
const entry = index.blocks.find((b) => b.name === name);
|
|
62
62
|
if (!entry)
|
|
63
63
|
throw new UserError(unknownBlockMessage(name, index));
|
|
@@ -77,7 +77,7 @@ function logAlreadyInstalled(order, ctx) {
|
|
|
77
77
|
return;
|
|
78
78
|
for (const name of order) {
|
|
79
79
|
if (ctx.config.installedBlocks[name]) {
|
|
80
|
-
log.step(`${name} —
|
|
80
|
+
log.step(`${name} — already installed (skipping; --overwrite would replace it)`);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -98,7 +98,7 @@ async function planWrites(toInstall, metas, ctx) {
|
|
|
98
98
|
function applyPlan(plan, projectRoot) {
|
|
99
99
|
for (const p of plan) {
|
|
100
100
|
if (p.action === 'skip-identical') {
|
|
101
|
-
log.step(`
|
|
101
|
+
log.step(`unchanged ${p.target}`);
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
104
|
const dest = p.action === 'conflict-new' ? `${p.absolute}.new` : p.absolute;
|
|
@@ -126,10 +126,10 @@ function planWrite(block, absolute, content, projectRoot, overwrite) {
|
|
|
126
126
|
}
|
|
127
127
|
function labelFor(action) {
|
|
128
128
|
switch (action) {
|
|
129
|
-
case 'write': return '
|
|
130
|
-
case 'overwrite': return '
|
|
131
|
-
case 'conflict-new': return '
|
|
132
|
-
case 'skip-identical': return '
|
|
129
|
+
case 'write': return 'new ';
|
|
130
|
+
case 'overwrite': return 'overwrote';
|
|
131
|
+
case 'conflict-new': return 'conflict→.new';
|
|
132
|
+
case 'skip-identical': return 'unchanged';
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
/** Przepisuje placeholdery: `@/` → alias, selektory `kpt-` → prefix (nie rusza `--kpt-`). */
|
|
@@ -163,14 +163,14 @@ function checkNpmDependencies(metas, projectRoot) {
|
|
|
163
163
|
if (verdict === 'missing')
|
|
164
164
|
missing.set(name, range);
|
|
165
165
|
else {
|
|
166
|
-
throw new UserError(`
|
|
167
|
-
`
|
|
166
|
+
throw new UserError(`The ${name} dependency is at version ${have}, the block needs ${range}. ` +
|
|
167
|
+
`Update it yourself and run this again.`);
|
|
168
168
|
}
|
|
169
169
|
continue;
|
|
170
170
|
}
|
|
171
171
|
peerNotes.add(verdict === 'missing'
|
|
172
|
-
? `${name} (peer) —
|
|
173
|
-
: `${name} (peer)
|
|
172
|
+
? `${name} (peer) — not in the project, the block needs ${range}`
|
|
173
|
+
: `${name} (peer) is at version ${have}, the block needs ${range}`);
|
|
174
174
|
}
|
|
175
175
|
reportMissing(missing);
|
|
176
176
|
for (const note of peerNotes)
|
|
@@ -212,12 +212,12 @@ function reportMissing(missing) {
|
|
|
212
212
|
return;
|
|
213
213
|
// Do instalacji podajemy same nazwy — zakres bywa złożony (">=0.6.0 <1.0.0")
|
|
214
214
|
// i wklejony do shella by się rozpadł. Wymagania pokazujemy osobno.
|
|
215
|
-
log.warn(`
|
|
215
|
+
log.warn(`Missing npm dependencies — install them: ${[...missing.keys()].join(' ')}`);
|
|
216
216
|
for (const [name, range] of missing)
|
|
217
|
-
log.step(`${name}
|
|
217
|
+
log.step(`${name} needs ${range}`);
|
|
218
218
|
}
|
|
219
219
|
function printSummary(installed, metas, dryRun) {
|
|
220
|
-
log.info(`\n${dryRun ? '
|
|
220
|
+
log.info(`\n${dryRun ? 'Would install' : 'Installed'}: ${installed.join(', ')}`);
|
|
221
221
|
for (const name of installed) {
|
|
222
222
|
const meta = metas.get(name);
|
|
223
223
|
if (meta.usage) {
|
|
@@ -226,18 +226,18 @@ function printSummary(installed, metas, dryRun) {
|
|
|
226
226
|
}
|
|
227
227
|
const ports = meta.api?.ports ?? [];
|
|
228
228
|
for (const port of ports) {
|
|
229
|
-
log.warn(`port
|
|
229
|
+
log.warn(`port to wire up: ${port.token} — ${port.signature}${port.stubProvided ? ' (a stub is included)' : ''}`);
|
|
230
230
|
}
|
|
231
231
|
if (meta.notes)
|
|
232
|
-
log.step(`
|
|
232
|
+
log.step(`note: ${meta.notes}`);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
function unknownBlockMessage(name, index) {
|
|
236
236
|
const nearest = index.blocks
|
|
237
237
|
.map((b) => ({ name: b.name, d: levenshtein(name, b.name) }))
|
|
238
238
|
.sort((a, b) => a.d - b.d)[0];
|
|
239
|
-
const hint = nearest && nearest.d <= 3 ? `
|
|
240
|
-
return `
|
|
239
|
+
const hint = nearest && nearest.d <= 3 ? ` Did you mean "${nearest.name}"?` : '';
|
|
240
|
+
return `I do not know the block "${name}".${hint} See: npx @konce-pt/ui list`;
|
|
241
241
|
}
|
|
242
242
|
function levenshtein(a, b) {
|
|
243
243
|
const dp = Array.from({ length: a.length + 1 }, (_, i) => i);
|
package/dist/commands/init.js
CHANGED
|
@@ -6,7 +6,7 @@ export function initCommand(args) {
|
|
|
6
6
|
const cwd = process.cwd();
|
|
7
7
|
const configPath = path.join(cwd, CONFIG_FILE);
|
|
8
8
|
if (existsSync(configPath) && !hasFlag(args, 'force')) {
|
|
9
|
-
throw new UserError(`${CONFIG_FILE}
|
|
9
|
+
throw new UserError(`${CONFIG_FILE} already exists. Use --force to overwrite it.`);
|
|
10
10
|
}
|
|
11
11
|
const config = {
|
|
12
12
|
...DEFAULT_CONFIG,
|
|
@@ -18,10 +18,10 @@ export function initCommand(args) {
|
|
|
18
18
|
installedBlocks: {},
|
|
19
19
|
};
|
|
20
20
|
writeConfig(configPath, config);
|
|
21
|
-
log.ok(`
|
|
21
|
+
log.ok(`Created ${CONFIG_FILE}`);
|
|
22
22
|
log.step(`registry: ${config.registry}`);
|
|
23
23
|
log.step(`blocksDir: ${config.blocksDir}`);
|
|
24
24
|
log.step(`alias: ${config.alias}`);
|
|
25
25
|
log.step(`prefix: ${config.prefix}`);
|
|
26
|
-
log.info('\
|
|
26
|
+
log.info('\nAdd a block: npx @konce-pt/ui add <name>');
|
|
27
27
|
}
|
package/dist/commands/list.js
CHANGED
|
@@ -17,14 +17,14 @@ export async function listCommand(args) {
|
|
|
17
17
|
const index = await loadIndex(base);
|
|
18
18
|
const blocks = category ? index.blocks.filter((b) => b.category === category) : index.blocks;
|
|
19
19
|
if (blocks.length === 0) {
|
|
20
|
-
log.warn(category ? `
|
|
20
|
+
log.warn(category ? `No blocks in the "${category}" category.` : 'The registry contains no blocks.');
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
log.info(
|
|
23
|
+
log.info(`@konce-pt blocks (library ${index.libraryVersion}):\n`);
|
|
24
24
|
const width = Math.max(...blocks.map((b) => b.name.length));
|
|
25
25
|
for (const b of blocks) {
|
|
26
26
|
log.info(` ${b.name.padEnd(width)} ${b.title} [${b.category}]`);
|
|
27
27
|
log.info(` ${' '.repeat(width)} ${b.description}`);
|
|
28
28
|
}
|
|
29
|
-
log.info('\
|
|
29
|
+
log.info('\nInstall: npx @konce-pt/ui add <name>');
|
|
30
30
|
}
|
package/dist/config.js
CHANGED
|
@@ -34,7 +34,7 @@ export function writeConfig(configPath, cfg) {
|
|
|
34
34
|
export function requireConfig(cwd) {
|
|
35
35
|
const configPath = findConfigPath(cwd);
|
|
36
36
|
if (!configPath) {
|
|
37
|
-
throw new UserError(`
|
|
37
|
+
throw new UserError(`No ${CONFIG_FILE}. Run this first: npx @konce-pt/ui init`);
|
|
38
38
|
}
|
|
39
39
|
return { path: configPath, config: readConfig(configPath) };
|
|
40
40
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,17 +3,18 @@ import { parseArgs, log, UserError } from "./util.js";
|
|
|
3
3
|
import { initCommand } from "./commands/init.js";
|
|
4
4
|
import { listCommand } from "./commands/list.js";
|
|
5
5
|
import { addCommand } from "./commands/add.js";
|
|
6
|
-
const HELP = `Koncept UI — CLI
|
|
6
|
+
const HELP = `Koncept UI — the block CLI.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
npx @konce-pt/ui <
|
|
8
|
+
Usage:
|
|
9
|
+
npx @konce-pt/ui <command> [options]
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
init
|
|
13
|
-
add <
|
|
14
|
-
list [--category=...]
|
|
11
|
+
Commands:
|
|
12
|
+
init create konce.json (--registry --blocks-dir --alias --prefix --theme --force)
|
|
13
|
+
add <name...> install block(s) + their dependencies (--overwrite --dry-run --path --registry)
|
|
14
|
+
list [--category=...] show the available blocks (--registry)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Options take a value only as --key=value.
|
|
17
|
+
Exit codes: 0 ok, 1 error.`;
|
|
17
18
|
async function main() {
|
|
18
19
|
const [command, ...rest] = process.argv.slice(2);
|
|
19
20
|
const args = parseArgs(rest);
|
|
@@ -34,7 +35,7 @@ async function main() {
|
|
|
34
35
|
log.info(HELP);
|
|
35
36
|
break;
|
|
36
37
|
default:
|
|
37
|
-
throw new UserError(`
|
|
38
|
+
throw new UserError(`Unknown command "${command}". See: npx @konce-pt/ui --help`);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
main().catch((err) => {
|
package/dist/registry.js
CHANGED
|
@@ -7,12 +7,12 @@ async function fetchText(base, relPath) {
|
|
|
7
7
|
const url = `${base.replace(/\/$/, '')}/${relPath}`;
|
|
8
8
|
const res = await fetch(url);
|
|
9
9
|
if (!res.ok)
|
|
10
|
-
throw new UserError(`
|
|
10
|
+
throw new UserError(`Could not fetch ${url} (HTTP ${res.status}).`);
|
|
11
11
|
return res.text();
|
|
12
12
|
}
|
|
13
13
|
const file = path.resolve(base, relPath);
|
|
14
14
|
if (!existsSync(file))
|
|
15
|
-
throw new UserError(`
|
|
15
|
+
throw new UserError(`Missing file in the registry: ${file}`);
|
|
16
16
|
return readFileSync(file, 'utf8');
|
|
17
17
|
}
|
|
18
18
|
export async function loadIndex(base) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konce-pt/ui",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.7.12",
|
|
4
|
+
"description": "The Koncept UI CLI — installs blocks (copy-paste) into an Angular project: init, add, list.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "konce.pt",
|
|
7
7
|
"homepage": "https://ui.konce.pt/",
|