@g3nomaly/ui 0.3.3 → 0.3.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/README.md +49 -26
- package/dist/cli/adapter.d.ts +25 -8
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +34 -20
- package/dist/cli/adapter.js.map +1 -1
- package/dist/cli/afterInstall.d.ts +26 -0
- package/dist/cli/afterInstall.d.ts.map +1 -0
- package/dist/cli/afterInstall.js +54 -0
- package/dist/cli/afterInstall.js.map +1 -0
- package/dist/cli/commands/add.d.ts +8 -2
- package/dist/cli/commands/add.d.ts.map +1 -1
- package/dist/cli/commands/add.js +10 -5
- package/dist/cli/commands/add.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +16 -5
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +59 -13
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/ls.d.ts +1 -1
- package/dist/cli/commands/ls.js +1 -1
- package/dist/cli/commands/ls.js.map +1 -1
- package/dist/cli/commands/manifest.js +1 -1
- package/dist/cli/commands/manifest.js.map +1 -1
- package/dist/cli/commands/source.d.ts +4 -1
- package/dist/cli/commands/source.d.ts.map +1 -1
- package/dist/cli/commands/source.js +29 -2
- package/dist/cli/commands/source.js.map +1 -1
- package/dist/cli/commands/sourceInit.d.ts +9 -0
- package/dist/cli/commands/sourceInit.d.ts.map +1 -0
- package/dist/cli/commands/sourceInit.js +78 -0
- package/dist/cli/commands/sourceInit.js.map +1 -0
- package/dist/cli/commands/update.d.ts +10 -3
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +9 -4
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.js +17 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/localSources.d.ts +12 -0
- package/dist/cli/localSources.d.ts.map +1 -0
- package/dist/cli/localSources.js +49 -0
- package/dist/cli/localSources.js.map +1 -0
- package/dist/cli/npmDependencies.d.ts +11 -0
- package/dist/cli/npmDependencies.d.ts.map +1 -0
- package/dist/cli/npmDependencies.js +73 -0
- package/dist/cli/npmDependencies.js.map +1 -0
- package/dist/cli/packageFiles.d.ts +15 -0
- package/dist/cli/packageFiles.d.ts.map +1 -0
- package/dist/cli/packageFiles.js +54 -0
- package/dist/cli/packageFiles.js.map +1 -0
- package/dist/cli/themeTokens.d.ts +12 -0
- package/dist/cli/themeTokens.d.ts.map +1 -0
- package/dist/cli/themeTokens.js +60 -0
- package/dist/cli/themeTokens.js.map +1 -0
- package/dist/packages/dependencies.d.ts +48 -0
- package/dist/packages/dependencies.d.ts.map +1 -0
- package/dist/packages/dependencies.js +66 -0
- package/dist/packages/dependencies.js.map +1 -0
- package/dist/packages/install.d.ts +30 -0
- package/dist/packages/install.d.ts.map +1 -0
- package/dist/packages/install.js +54 -0
- package/dist/packages/install.js.map +1 -0
- package/dist/packages/localPack.d.ts +48 -0
- package/dist/packages/localPack.d.ts.map +1 -0
- package/dist/packages/localPack.js +72 -0
- package/dist/packages/localPack.js.map +1 -0
- package/dist/registry/adapters/shadcn.adapter.d.ts +32 -7
- package/dist/registry/adapters/shadcn.adapter.d.ts.map +1 -1
- package/dist/registry/adapters/shadcn.adapter.js +75 -20
- package/dist/registry/adapters/shadcn.adapter.js.map +1 -1
- package/dist/registry/adapters/shadcnImports.d.ts +10 -0
- package/dist/registry/adapters/shadcnImports.d.ts.map +1 -0
- package/dist/registry/adapters/shadcnImports.js +18 -0
- package/dist/registry/adapters/shadcnImports.js.map +1 -0
- package/dist/registry/componentsJson.d.ts +6 -1
- package/dist/registry/componentsJson.d.ts.map +1 -1
- package/dist/registry/componentsJson.js +34 -1
- package/dist/registry/componentsJson.js.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest.d.ts +2 -13
- package/dist/registry/manifest.d.ts.map +1 -1
- package/dist/registry/manifest.js +4 -76
- package/dist/registry/manifest.js.map +1 -1
- package/dist/registry/packageExports.d.ts +9 -0
- package/dist/registry/packageExports.d.ts.map +1 -0
- package/dist/registry/packageExports.js +50 -0
- package/dist/registry/packageExports.js.map +1 -0
- package/dist/registry/packageImports.d.ts +23 -0
- package/dist/registry/packageImports.d.ts.map +1 -0
- package/dist/registry/packageImports.js +51 -0
- package/dist/registry/packageImports.js.map +1 -0
- package/dist/registry/readSource.d.ts +4 -2
- package/dist/registry/readSource.d.ts.map +1 -1
- package/dist/registry/readSource.js +27 -3
- package/dist/registry/readSource.js.map +1 -1
- package/dist/registry/types.d.ts +86 -3
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry/types.js +46 -3
- package/dist/registry/types.js.map +1 -1
- package/dist/sources/builtins.d.ts +1 -5
- package/dist/sources/builtins.d.ts.map +1 -1
- package/dist/sources/builtins.js +2 -7
- package/dist/sources/builtins.js.map +1 -1
- package/dist/theme/cssVars.d.ts +43 -0
- package/dist/theme/cssVars.d.ts.map +1 -0
- package/dist/theme/cssVars.js +107 -0
- package/dist/theme/cssVars.js.map +1 -0
- package/dist/theme/detectCssFile.d.ts +9 -0
- package/dist/theme/detectCssFile.d.ts.map +1 -0
- package/dist/theme/detectCssFile.js +41 -0
- package/dist/theme/detectCssFile.js.map +1 -0
- package/package.json +8 -21
- package/template/build.ts +32 -0
- package/template/package.json +22 -0
- package/template/src/components/example/Example.css +20 -0
- package/template/src/components/example/Example.tsx +26 -0
- package/template/src/components/example/example.meta.ts +69 -0
- package/dist/components/basic/Card.css +0 -32
- package/dist/components/basic/Card.debug.ts +0 -5
- package/dist/components/basic/Card.tsx +0 -31
- package/dist/components/basic/CardFooter.css +0 -16
- package/dist/components/basic/CardFooter.debug.ts +0 -5
- package/dist/components/basic/CardFooter.tsx +0 -29
- package/dist/components/basic/CardHeader.css +0 -14
- package/dist/components/basic/CardHeader.debug.ts +0 -5
- package/dist/components/basic/CardHeader.tsx +0 -29
- package/dist/components/basic/card.meta.ts +0 -14
- package/dist/components/basic/cardfooter.meta.ts +0 -14
- package/dist/components/basic/cardheader.meta.ts +0 -14
- package/dist/components/input/Button.css +0 -34
- package/dist/components/input/Button.debug.ts +0 -5
- package/dist/components/input/Button.tsx +0 -28
- package/dist/components/input/button.meta.ts +0 -14
- package/dist/components.json +0 -138
package/dist/cli/index.js
CHANGED
|
@@ -9,12 +9,13 @@ import { updateCommand } from "./commands/update";
|
|
|
9
9
|
import { lsCommand } from "./commands/ls";
|
|
10
10
|
import { manifestCommand } from "./commands/manifest";
|
|
11
11
|
import { sourceAddCommand, sourceLsCommand, sourceRemoveCommand } from "./commands/source";
|
|
12
|
+
import { sourceInitCommand } from "./commands/sourceInit";
|
|
12
13
|
const program = new Command()
|
|
13
|
-
.name("
|
|
14
|
+
.name("g3n-ui")
|
|
14
15
|
.description("Install components from any registered source into a project");
|
|
15
16
|
program
|
|
16
17
|
.command("init")
|
|
17
|
-
.description("Initialize
|
|
18
|
+
.description("Initialize the ui config in this project")
|
|
18
19
|
.option("-f, --force", "Overwrite existing config without prompting")
|
|
19
20
|
.option("--install-dir <path>", "Components install directory (skips interactive prompt)")
|
|
20
21
|
.action(async (opts) => {
|
|
@@ -23,13 +24,20 @@ program
|
|
|
23
24
|
const source = program
|
|
24
25
|
.command("source")
|
|
25
26
|
.description("Register, list and unregister the sources components are installed from");
|
|
27
|
+
source
|
|
28
|
+
.command("init [dir]")
|
|
29
|
+
.description("Create a component source of your own from a template, in dir (default: the current folder)")
|
|
30
|
+
.action((dir) => {
|
|
31
|
+
sourceInitCommand(dir);
|
|
32
|
+
});
|
|
26
33
|
source
|
|
27
34
|
.command("add <source>")
|
|
28
|
-
.description("Register a git repository, npm package or local folder holding a built dist/components.json")
|
|
35
|
+
.description("Register a git repository, an npm package listed in package.json, or a local folder holding a built dist/components.json")
|
|
29
36
|
.option("--name <name>", "Name to register it under (default: derived from the source)")
|
|
30
37
|
.option("--ref <ref>", "Branch or tag to pin a git source to (default: its default branch)")
|
|
38
|
+
.option("-f, --force", "Point a name that is already registered at this source")
|
|
31
39
|
.action(async (input, opts) => {
|
|
32
|
-
await sourceAddCommand(input, { name: opts.name, ref: opts.ref });
|
|
40
|
+
await sourceAddCommand(input, { name: opts.name, ref: opts.ref, force: opts.force });
|
|
33
41
|
});
|
|
34
42
|
source
|
|
35
43
|
.command("ls")
|
|
@@ -51,8 +59,10 @@ program
|
|
|
51
59
|
.option("-f, --force", "Overwrite locally modified files")
|
|
52
60
|
.option("--debug", "Include .debug.ts files")
|
|
53
61
|
.option("--meta", "Include .meta.ts files")
|
|
62
|
+
.option("--install", "Add the npm packages the components need with bun add")
|
|
63
|
+
.option("--include-unsafe", "Also copy the files the components keep in their package, such as stores, as unsafe copies")
|
|
54
64
|
.action(async (components, opts) => {
|
|
55
|
-
await addCommand(components, { force: opts.force, debug: opts.debug, meta: opts.meta });
|
|
65
|
+
await addCommand(components, { force: opts.force, debug: opts.debug, meta: opts.meta, install: opts.install, includeUnsafe: opts.includeUnsafe });
|
|
56
66
|
});
|
|
57
67
|
program
|
|
58
68
|
.command("remove [components...]")
|
|
@@ -66,8 +76,9 @@ program
|
|
|
66
76
|
.description("Re-install installed components from the source each came from")
|
|
67
77
|
.option("-f, --force", "Overwrite conflicting files without prompting")
|
|
68
78
|
.option("--dry-run", "Preview changes without writing files")
|
|
79
|
+
.option("--install", "Add the npm packages the components need with bun add")
|
|
69
80
|
.action(async (components, opts) => {
|
|
70
|
-
await updateCommand(components, { force: opts.force, dryRun: opts.dryRun });
|
|
81
|
+
await updateCommand(components, { force: opts.force, dryRun: opts.dryRun, install: opts.install });
|
|
71
82
|
});
|
|
72
83
|
program
|
|
73
84
|
.command("ls")
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,+BAA+B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAU,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAW,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAQ,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAQ,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAY,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,+BAA+B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAU,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAW,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAQ,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAQ,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAY,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,MA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K,IAAI,EAAE;IACjB,MAAM,eAAe,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEL,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9C,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/D,OAAO,CAAC,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RegisteredSource } from "@g3nomaly/core/sources";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Installs a packed copy of every npm source the app installs from a folder on disk and whose
|
|
4
|
+
* components keep files in the package, such as stores, or refreshes the copy. The app imports those
|
|
5
|
+
* files, and through a link to the folder they would load the folder's own `node_modules`, such as a
|
|
6
|
+
* second React. Runs before the sources are read, so `update` reads the fresh copy.
|
|
7
|
+
*
|
|
8
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
9
|
+
* @param sources - Sources about to be read.
|
|
10
|
+
*/
|
|
11
|
+
export declare function packLocalSources(projectRoot: string, sources: readonly RegisteredSource[]): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=localSources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localSources.d.ts","sourceRoot":"","sources":["../../src/cli/localSources.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkB/D;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/G"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// packages/ui/src/cli/localSources.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { c, lineError, lineInfo } from "@g3nomaly/core/cli";
|
|
4
|
+
import { installPackedCopy, localPackage } from "../packages/localPack";
|
|
5
|
+
import { readComponentsJson } from "../registry/componentsJson";
|
|
6
|
+
/**
|
|
7
|
+
* @brief Whether a source folder's built components keep any file in the package.
|
|
8
|
+
*
|
|
9
|
+
* @param folder - Absolute folder holding `dist/components.json`.
|
|
10
|
+
* @returns `false` as well when the folder is not built; reading the source reports that.
|
|
11
|
+
*/
|
|
12
|
+
function keepsPackageFiles(folder) {
|
|
13
|
+
try {
|
|
14
|
+
return Object.values(readComponentsJson(folder)).some((meta) => meta.files.some((file) => file.install === "package"));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Installs a packed copy of every npm source the app installs from a folder on disk and whose
|
|
22
|
+
* components keep files in the package, such as stores, or refreshes the copy. The app imports those
|
|
23
|
+
* files, and through a link to the folder they would load the folder's own `node_modules`, such as a
|
|
24
|
+
* second React. Runs before the sources are read, so `update` reads the fresh copy.
|
|
25
|
+
*
|
|
26
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
27
|
+
* @param sources - Sources about to be read.
|
|
28
|
+
*/
|
|
29
|
+
export async function packLocalSources(projectRoot, sources) {
|
|
30
|
+
for (const source of sources) {
|
|
31
|
+
if (source.spec.kind !== "npm")
|
|
32
|
+
continue;
|
|
33
|
+
const pkg = source.spec.package;
|
|
34
|
+
const local = localPackage(projectRoot, pkg);
|
|
35
|
+
if (local === null || !keepsPackageFiles(local.folder))
|
|
36
|
+
continue;
|
|
37
|
+
const result = await installPackedCopy(projectRoot, pkg, local);
|
|
38
|
+
if (result.error !== undefined) {
|
|
39
|
+
console.error(lineError(`${c.key(pkg)}: ${result.error}`));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (result.installed === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const folder = c.dir(path.relative(projectRoot, local.folder) || ".");
|
|
45
|
+
const verb = local.tarball === undefined ? "Installed a packed copy of" : "Refreshed the packed copy of";
|
|
46
|
+
console.log(lineInfo(`${verb} ${c.key(pkg)} from ${folder} (${c.key(result.installed)}), so the files it keeps in the package load this app's packages`));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=localSources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localSources.js","sourceRoot":"","sources":["../../src/cli/localSources.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,MAAc;IACvC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC;IACzH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,WAAmB,EAAE,OAAoC;IAC9F,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK;YAAE,SAAS;QACzC,MAAM,GAAG,GAAK,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QAClC,MAAM,KAAK,GAAG,YAAY,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAC7C,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC;YAAE,SAAS;QAEjE,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAChE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAC3D,SAAS;QACX,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;YAAE,SAAS;QAC7C,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QACtE,MAAM,IAAI,GAAK,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,8BAA8B,CAAC;QAC3G,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,kEAAkE,CAAC,CAAC,CAAC;IAC5J,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentMeta } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Checks the npm packages of components against the app's `package.json`, and reports or adds
|
|
4
|
+
* what is missing or out of range. A runtime package declared in `devDependencies` only is reported, never moved.
|
|
5
|
+
*
|
|
6
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
7
|
+
* @param components - Components by key just installed or updated.
|
|
8
|
+
* @param install - Add the packages with `bun add` instead of only reporting them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function reportNpmDependencies(projectRoot: string, components: Record<string, ComponentMeta>, install: boolean): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=npmDependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npmDependencies.d.ts","sourceRoot":"","sources":["../../src/cli/npmDependencies.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAmDvD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ3I"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// packages/ui/src/cli/npmDependencies.ts
|
|
2
|
+
import { c, lineError, lineSuccess, lineWarn } from "@g3nomaly/core/cli";
|
|
3
|
+
import { findDependencyProblems } from "../packages/dependencies";
|
|
4
|
+
import { bunAdd } from "../packages/install";
|
|
5
|
+
/**
|
|
6
|
+
* @brief One line naming a package the app lacks, declares for build time only or holds at the wrong
|
|
7
|
+
* version, and the components needing it.
|
|
8
|
+
*
|
|
9
|
+
* @param problem - The package and the components that list it.
|
|
10
|
+
* @returns The line, e.g. `radix-ui is not in package.json, needed by @shadcn/dialog`.
|
|
11
|
+
*/
|
|
12
|
+
function problemLine(problem) {
|
|
13
|
+
const neededBy = problem.neededBy.map((key) => c.key(key)).join(", ");
|
|
14
|
+
if (problem.devOnly) {
|
|
15
|
+
return lineWarn(`${c.key(problem.dependency.name)} is in devDependencies, but ${neededBy} import${problem.neededBy.length === 1 ? "s" : ""} it at runtime: move it to dependencies in package.json`);
|
|
16
|
+
}
|
|
17
|
+
return problem.installed === undefined
|
|
18
|
+
? lineWarn(`${c.key(problem.dependency.name)} is not in package.json, needed by ${neededBy}`)
|
|
19
|
+
: lineWarn(`${c.key(problem.dependency.name)} ${problem.installed} is installed, ${neededBy} needs ${c.key(problem.dependency.spec)}`);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @brief Adds the packages with `bun add`, runtime and build-time packages in separate runs, and prints the outcome.
|
|
23
|
+
*
|
|
24
|
+
* @param projectRoot - Absolute project root.
|
|
25
|
+
* @param problems - Packages to add.
|
|
26
|
+
*/
|
|
27
|
+
async function installMissing(projectRoot, problems) {
|
|
28
|
+
for (const dev of [false, true]) {
|
|
29
|
+
const specs = problems.filter((p) => p.dev === dev).map((p) => p.dependency.spec);
|
|
30
|
+
if (specs.length === 0)
|
|
31
|
+
continue;
|
|
32
|
+
const error = await bunAdd(projectRoot, specs, dev);
|
|
33
|
+
console.log(error === undefined
|
|
34
|
+
? lineSuccess(`Added ${specs.map((s) => c.key(s)).join(", ")} with ${c.cmd(dev ? "bun add -d" : "bun add")}`)
|
|
35
|
+
: lineError(`${c.cmd(dev ? "bun add -d" : "bun add")} failed: ${error}`));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @brief Prints the command that adds the packages.
|
|
40
|
+
*
|
|
41
|
+
* @param problems - Packages to add.
|
|
42
|
+
*/
|
|
43
|
+
function printInstallHint(problems) {
|
|
44
|
+
const runtime = problems.filter((p) => !p.dev).map((p) => p.dependency.spec);
|
|
45
|
+
const dev = problems.filter((p) => p.dev).map((p) => p.dependency.spec);
|
|
46
|
+
const commands = [
|
|
47
|
+
...(runtime.length > 0 ? [c.cmd(`bun add ${runtime.join(" ")}`)] : []),
|
|
48
|
+
...(dev.length > 0 ? [c.cmd(`bun add -d ${dev.join(" ")}`)] : []),
|
|
49
|
+
];
|
|
50
|
+
console.log(lineWarn(`Run ${commands.join(" and ")}, or pass ${c.flag("--install")} to add them`));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @brief Checks the npm packages of components against the app's `package.json`, and reports or adds
|
|
54
|
+
* what is missing or out of range. A runtime package declared in `devDependencies` only is reported, never moved.
|
|
55
|
+
*
|
|
56
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
57
|
+
* @param components - Components by key just installed or updated.
|
|
58
|
+
* @param install - Add the packages with `bun add` instead of only reporting them.
|
|
59
|
+
*/
|
|
60
|
+
export async function reportNpmDependencies(projectRoot, components, install) {
|
|
61
|
+
const problems = findDependencyProblems(projectRoot, components);
|
|
62
|
+
for (const problem of problems)
|
|
63
|
+
console.log(problemLine(problem));
|
|
64
|
+
// A misplaced package keeps the range the app gave it, such as `workspace:*`, so it is moved by hand, never re-added.
|
|
65
|
+
const toAdd = problems.filter((problem) => !problem.devOnly);
|
|
66
|
+
if (toAdd.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
if (install)
|
|
69
|
+
await installMissing(projectRoot, toAdd);
|
|
70
|
+
else
|
|
71
|
+
printInstallHint(toAdd);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=npmDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npmDependencies.js","sourceRoot":"","sources":["../../src/cli/npmDependencies.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,OAA0B;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,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AO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;AACrG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,WAAmB,EAAE,UAAyC,EAAE,OAAgB;IAC1H,MAAM,QAAQ,GAAG,sBAAsB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACjE,KAAK,MAAM,OAAO,IAAI,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,sHAAsH;IACtH,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC/B,IAAI,OAAO;QAAE,MAAM,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;;QACjD,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ManifestTarget } from "@g3nomaly/core/cli";
|
|
2
|
+
import type { ComponentMeta } from "../registry/types";
|
|
3
|
+
import type { UiProject } from "./adapter";
|
|
4
|
+
/**
|
|
5
|
+
* @brief Copies the files that stay in the package, such as stores, next to the installed components as
|
|
6
|
+
* unsafe copies. The components keep importing the package's version: the copies are not tracked,
|
|
7
|
+
* `update` and `remove` leave them alone, and pointing an import at one is the user's own edit.
|
|
8
|
+
* A file already at the destination is left as is.
|
|
9
|
+
*
|
|
10
|
+
* @param project - The opened project.
|
|
11
|
+
* @param target - Target the components were installed in.
|
|
12
|
+
* @param components - Components by key just installed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyPackageFiles(project: UiProject, target: ManifestTarget, components: Record<string, ComponentMeta>): void;
|
|
15
|
+
//# sourceMappingURL=packageFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageFiles.d.ts","sourceRoot":"","sources":["../../src/cli/packageFiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAe3C;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CAuB5H"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/ui/src/cli/packageFiles.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { c, lineInfo, lineWarn } from "@g3nomaly/core/cli";
|
|
5
|
+
import { findInstalledPackage } from "@g3nomaly/core/sources";
|
|
6
|
+
import { uiSources } from "./adapter";
|
|
7
|
+
/**
|
|
8
|
+
* @brief Folder the installed source package of a component sits in.
|
|
9
|
+
*
|
|
10
|
+
* @param project - The opened project.
|
|
11
|
+
* @param component - Component whose `origin.source` names the source.
|
|
12
|
+
* @returns The package folder, or `null` when the source is not an npm package or is not installed.
|
|
13
|
+
*/
|
|
14
|
+
function sourcePackageDir(project, component) {
|
|
15
|
+
const source = uiSources(project).find((s) => s.name === component.origin.source);
|
|
16
|
+
if (source?.spec.kind !== "npm")
|
|
17
|
+
return null;
|
|
18
|
+
return findInstalledPackage(project.projectRoot, source.spec.package)?.dir ?? null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Copies the files that stay in the package, such as stores, next to the installed components as
|
|
22
|
+
* unsafe copies. The components keep importing the package's version: the copies are not tracked,
|
|
23
|
+
* `update` and `remove` leave them alone, and pointing an import at one is the user's own edit.
|
|
24
|
+
* A file already at the destination is left as is.
|
|
25
|
+
*
|
|
26
|
+
* @param project - The opened project.
|
|
27
|
+
* @param target - Target the components were installed in.
|
|
28
|
+
* @param components - Components by key just installed.
|
|
29
|
+
*/
|
|
30
|
+
export function copyPackageFiles(project, target, components) {
|
|
31
|
+
for (const [key, component] of Object.entries(components)) {
|
|
32
|
+
const files = component.packageFiles ?? [];
|
|
33
|
+
if (files.length === 0)
|
|
34
|
+
continue;
|
|
35
|
+
const packageDir = sourcePackageDir(project, component);
|
|
36
|
+
if (packageDir === null) {
|
|
37
|
+
console.log(lineWarn(`${c.key(key)}: its source ${c.key(component.origin.source)} is not an installed npm package, nothing copied`));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
const from = path.join(packageDir, component.origin.dir, file.path);
|
|
42
|
+
const to = path.join(target.installDir, file.path);
|
|
43
|
+
const shown = c.file(path.relative(project.projectRoot, to));
|
|
44
|
+
if (fs.existsSync(to)) {
|
|
45
|
+
console.log(lineInfo(`${shown} already exists, left as is`));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
49
|
+
fs.copyFileSync(from, to);
|
|
50
|
+
console.log(lineWarn(`Copied ${shown} as an unsafe copy: ${c.key(key)} still imports it from the package. Point imports at the copy yourself; update and remove leave it alone.`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=packageFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageFiles.js","sourceRoot":"","sources":["../../src/cli/packageFiles.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAA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GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACpE,MAAM,EAAE,GAAK,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7D,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC,CAAC;gBAC7D,SAAS;YACX,CAAC;YACD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACpD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,KAAK,uBAAuB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,2GAA2G,CAAC,CAAC,CAAC;QACrL,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ComponentMeta } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Adds the theme tokens components need to the app's global stylesheet. A token the stylesheet
|
|
4
|
+
* already defines keeps its value. Without a stylesheet set in `ui.settings.cssFile`, prints the tokens
|
|
5
|
+
* to add by hand: only those the detected stylesheet lacks, so a run after they were added prints nothing.
|
|
6
|
+
*
|
|
7
|
+
* @param projectRoot - Absolute project root.
|
|
8
|
+
* @param cssFile - The stylesheet relative to the project root, e.g. `src/index.css`; `undefined` when not set.
|
|
9
|
+
* @param components - Components by key just installed or updated.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyThemeTokens(projectRoot: string, cssFile: string | undefined, components: Record<string, ComponentMeta>): void;
|
|
12
|
+
//# sourceMappingURL=themeTokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeTokens.d.ts","sourceRoot":"","sources":["../../src/cli/themeTokens.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAqBvD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CA0BlI"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// packages/ui/src/cli/themeTokens.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { c, lineError, lineSuccess, lineWarn } from "@g3nomaly/core/cli";
|
|
5
|
+
import { addCssVars, mergeCssVars } from "../theme/cssVars";
|
|
6
|
+
import { detectCssFile } from "../theme/detectCssFile";
|
|
7
|
+
import { UI_COMMAND } from "./adapter";
|
|
8
|
+
/**
|
|
9
|
+
* @brief Tokens as stylesheet blocks, for pasting by hand.
|
|
10
|
+
*
|
|
11
|
+
* @param tokens - Tokens to print, each with its block.
|
|
12
|
+
* @returns One line per block and token, blocks in the order they first appear.
|
|
13
|
+
*/
|
|
14
|
+
function blockLines(tokens) {
|
|
15
|
+
const blocks = [...new Set(tokens.map((token) => token.block))];
|
|
16
|
+
return blocks.flatMap((block) => [
|
|
17
|
+
` ${block} {`,
|
|
18
|
+
...tokens.filter((token) => token.block === block).map((token) => ` ${token.name}: ${token.value};`),
|
|
19
|
+
" }",
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @brief Adds the theme tokens components need to the app's global stylesheet. A token the stylesheet
|
|
24
|
+
* already defines keeps its value. Without a stylesheet set in `ui.settings.cssFile`, prints the tokens
|
|
25
|
+
* to add by hand: only those the detected stylesheet lacks, so a run after they were added prints nothing.
|
|
26
|
+
*
|
|
27
|
+
* @param projectRoot - Absolute project root.
|
|
28
|
+
* @param cssFile - The stylesheet relative to the project root, e.g. `src/index.css`; `undefined` when not set.
|
|
29
|
+
* @param components - Components by key just installed or updated.
|
|
30
|
+
*/
|
|
31
|
+
export function applyThemeTokens(projectRoot, cssFile, components) {
|
|
32
|
+
const withTokens = Object.values(components).flatMap((component) => component.cssVars === undefined ? [] : [component.cssVars]);
|
|
33
|
+
if (withTokens.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
const vars = mergeCssVars(withTokens);
|
|
36
|
+
if (cssFile === undefined) {
|
|
37
|
+
const detected = detectCssFile(projectRoot);
|
|
38
|
+
const css = detected === undefined ? "" : fs.readFileSync(path.join(projectRoot, detected), "utf8");
|
|
39
|
+
const missing = addCssVars(css, vars).added;
|
|
40
|
+
if (missing.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
const from = detected === undefined ? "your global stylesheet" : c.file(detected);
|
|
43
|
+
console.log(lineWarn(`These components use theme tokens that ${from} lacks. Add them by hand, or set the stylesheet with ${c.cmd(`${UI_COMMAND} init`)} so they are added for you:`));
|
|
44
|
+
for (const line of blockLines(missing))
|
|
45
|
+
console.log(line);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const file = path.join(projectRoot, cssFile);
|
|
49
|
+
if (!fs.existsSync(file)) {
|
|
50
|
+
console.error(lineError(`${c.file(cssFile)} does not exist, theme tokens not added. Fix ${c.key("ui.settings.cssFile")} in .g3n.config.json`));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const merged = addCssVars(fs.readFileSync(file, "utf8"), vars);
|
|
54
|
+
if (merged.added.length === 0)
|
|
55
|
+
return;
|
|
56
|
+
fs.writeFileSync(file, merged.css);
|
|
57
|
+
const names = merged.added.map((token) => `${token.block} ${token.name}`);
|
|
58
|
+
console.log(lineSuccess(`Added ${names.length} theme token${names.length === 1 ? "" : "s"} to ${c.file(cssFile)}: ${names.join(", ")}`));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=themeTokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeTokens.js","sourceRoot":"","sources":["../../src/cli/themeTokens.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;GAKG;AACH,SAAS,UAAU,CAAC,MAA6B;IAC/C,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QAC/B,KAAK,KAAK,IAAI;QACd,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC;QACvG,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB,EAAE,OAA2B,EAAE,UAAyC;I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IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,gDAAgD,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC/I,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/D,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACtC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,KAAK,CAAC,MAAM,eAAe,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3I,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ComponentMeta } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief One npm package as a component lists it.
|
|
4
|
+
*
|
|
5
|
+
* @property spec - The text as listed, e.g. `recharts@3.8.0`, passed to `bun add` unchanged.
|
|
6
|
+
* @property name - Package name, e.g. `recharts` or `@base-ui/react`.
|
|
7
|
+
* @property range - Version range or dist-tag after the name, e.g. `3.8.0`; absent when the spec names no version.
|
|
8
|
+
*/
|
|
9
|
+
export interface NpmDependency {
|
|
10
|
+
spec: string;
|
|
11
|
+
name: string;
|
|
12
|
+
range?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @brief An npm package the app lacks, declares only for build time although a component imports it
|
|
16
|
+
* at runtime, or holds at a version outside the range a component asks for.
|
|
17
|
+
*
|
|
18
|
+
* @property dependency - The package as the first component listing it asks for it.
|
|
19
|
+
* @property dev - Whether every component listing it needs it at build time only.
|
|
20
|
+
* @property neededBy - Keys of the components that list it, e.g. `["@shadcn/dialog"]`.
|
|
21
|
+
* @property devOnly - The app declares it in `devDependencies` only, though a component needs it at runtime.
|
|
22
|
+
* @property installed - Installed version when it is outside the range; absent when the package is missing.
|
|
23
|
+
*/
|
|
24
|
+
export interface DependencyProblem {
|
|
25
|
+
dependency: NpmDependency;
|
|
26
|
+
dev: boolean;
|
|
27
|
+
neededBy: string[];
|
|
28
|
+
devOnly?: true;
|
|
29
|
+
installed?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @brief Splits an npm spec into name and version range. The range follows the last `@` that is not a scope's.
|
|
33
|
+
*
|
|
34
|
+
* @param spec - Spec such as `radix-ui`, `recharts@3.8.0` or `@base-ui/react@^1`.
|
|
35
|
+
* @returns The parsed package.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseNpmDependency(spec: string): NpmDependency;
|
|
38
|
+
/**
|
|
39
|
+
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
40
|
+
* does not declare is missing, a runtime package it declares in `devDependencies` only is misplaced,
|
|
41
|
+
* and an installed package outside the requested range is out of range.
|
|
42
|
+
*
|
|
43
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
44
|
+
* @param components - Components by key whose packages to check.
|
|
45
|
+
* @returns One problem per package, in the order the components list them; empty when the app has them all.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findDependencyProblems(projectRoot: string, components: Record<string, ComponentMeta>): DependencyProblem[];
|
|
48
|
+
//# sourceMappingURL=dependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAI,MAAM,CAAC;IACf,IAAI,EAAI,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,aAAa,CAAC;IAC1B,GAAG,EAAS,OAAO,CAAC;IACpB,QAAQ,EAAI,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAI,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAG9D;AAYD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,iBAAiB,EAAE,CAiC1H"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// packages/ui/src/packages/dependencies.ts
|
|
2
|
+
import { findInstalledPackage, readDeclaredDependencies, RUNTIME_SECTIONS } from "@g3nomaly/core/sources";
|
|
3
|
+
/**
|
|
4
|
+
* @brief Splits an npm spec into name and version range. The range follows the last `@` that is not a scope's.
|
|
5
|
+
*
|
|
6
|
+
* @param spec - Spec such as `radix-ui`, `recharts@3.8.0` or `@base-ui/react@^1`.
|
|
7
|
+
* @returns The parsed package.
|
|
8
|
+
*/
|
|
9
|
+
export function parseNpmDependency(spec) {
|
|
10
|
+
const at = spec.lastIndexOf("@");
|
|
11
|
+
return at > 0 ? { spec, name: spec.slice(0, at), range: spec.slice(at + 1) } : { spec, name: spec };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @brief Whether a range can be checked against a version: a dist-tag such as `latest` cannot.
|
|
15
|
+
*
|
|
16
|
+
* @param range - Range or dist-tag after the package name.
|
|
17
|
+
* @returns `true` for a semver range such as `^1.2.0`, `3.8.0` or `*`.
|
|
18
|
+
*/
|
|
19
|
+
function isSemverRange(range) {
|
|
20
|
+
return !/^[a-z]/i.test(range);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
24
|
+
* does not declare is missing, a runtime package it declares in `devDependencies` only is misplaced,
|
|
25
|
+
* and an installed package outside the requested range is out of range.
|
|
26
|
+
*
|
|
27
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
28
|
+
* @param components - Components by key whose packages to check.
|
|
29
|
+
* @returns One problem per package, in the order the components list them; empty when the app has them all.
|
|
30
|
+
*/
|
|
31
|
+
export function findDependencyProblems(projectRoot, components) {
|
|
32
|
+
const declared = readDeclaredDependencies(projectRoot);
|
|
33
|
+
const runtime = readDeclaredDependencies(projectRoot, RUNTIME_SECTIONS);
|
|
34
|
+
const problems = new Map();
|
|
35
|
+
const check = (key, spec, dev) => {
|
|
36
|
+
const dependency = parseNpmDependency(spec);
|
|
37
|
+
const known = problems.get(dependency.name);
|
|
38
|
+
if (known !== undefined) {
|
|
39
|
+
known.neededBy.push(key);
|
|
40
|
+
known.dev &&= dev;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (declared[dependency.name] === undefined) {
|
|
44
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key] });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!dev && runtime[dependency.name] === undefined) {
|
|
48
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key], devOnly: true });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (dependency.range === undefined || !isSemverRange(dependency.range))
|
|
52
|
+
return;
|
|
53
|
+
const installed = findInstalledPackage(projectRoot, dependency.name)?.version;
|
|
54
|
+
if (installed !== undefined && !Bun.semver.satisfies(installed, dependency.range)) {
|
|
55
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key], installed });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
for (const [key, component] of Object.entries(components)) {
|
|
59
|
+
for (const spec of component.dependencies ?? [])
|
|
60
|
+
check(key, spec, false);
|
|
61
|
+
for (const spec of component.devDependencies ?? [])
|
|
62
|
+
check(key, spec, true);
|
|
63
|
+
}
|
|
64
|
+
return [...problems.values()];
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkC1G;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACtG,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB,EAAE,UAAyC;IACn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AAC,EAAE,OAAO,CAAC;QAC9E,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAClF,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACjF,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1D,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,YAAY,IAAI,EAAE;YAAK,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5E,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,eAAe,IAAI,EAAE;YAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Runs `bun add` in the project for the given specs, with `-d` for build-time packages.
|
|
3
|
+
*
|
|
4
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
5
|
+
* @param specs - Specs to add, e.g. `["radix-ui", "recharts@3.8.0"]`.
|
|
6
|
+
* @param dev - Add them as `devDependencies`.
|
|
7
|
+
* @returns `undefined` on success, else the error `bun add` printed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function bunAdd(projectRoot: string, specs: readonly string[], dev: boolean): Promise<string | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* @brief Runs `bun remove` in the project for one package.
|
|
12
|
+
*
|
|
13
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
14
|
+
* @param pkg - Package to remove, e.g. `my-ui`.
|
|
15
|
+
* @returns `undefined` on success, else the error `bun remove` printed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bunRemove(projectRoot: string, pkg: string): Promise<string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* @brief Packs a package folder with `bun pm pack`, which runs its `prepack` script first and keeps
|
|
20
|
+
* only what its `files` field lists, so the tarball holds no `node_modules`.
|
|
21
|
+
*
|
|
22
|
+
* @param folder - Absolute folder holding the package's `package.json`.
|
|
23
|
+
* @returns The tarball's file name inside `folder`, e.g. `my-ui-0.3.0.tgz`, or the error `bun pm pack` printed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bunPack(folder: string): Promise<{
|
|
26
|
+
tarball: string;
|
|
27
|
+
} | {
|
|
28
|
+
error: string;
|
|
29
|
+
}>;
|
|
30
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AA2BA;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAGrH;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7F;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9F"}
|