@kosdev-code/kos-ui-cli 0.1.0-dev.5053

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.
Files changed (47) hide show
  1. package/README.md +7 -0
  2. package/package.json +30 -0
  3. package/src/index.d.ts +2 -0
  4. package/src/index.d.ts.map +1 -0
  5. package/src/index.js +1 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/cli.mjs +803 -0
  8. package/src/lib/generators/cache/index.mjs +18 -0
  9. package/src/lib/generators/component/index.mjs +55 -0
  10. package/src/lib/generators/env/index.mjs +42 -0
  11. package/src/lib/generators/i18n/namespace.mjs +61 -0
  12. package/src/lib/generators/kab/index.mjs +82 -0
  13. package/src/lib/generators/metadata.json +341 -0
  14. package/src/lib/generators/model/add-future.mjs +96 -0
  15. package/src/lib/generators/model/companion.mjs +117 -0
  16. package/src/lib/generators/model/container.mjs +96 -0
  17. package/src/lib/generators/model/context.mjs +77 -0
  18. package/src/lib/generators/model/hook.mjs +77 -0
  19. package/src/lib/generators/model/model.mjs +79 -0
  20. package/src/lib/generators/plugin/index.mjs +195 -0
  21. package/src/lib/generators/project/app.mjs +39 -0
  22. package/src/lib/generators/project/content.mjs +41 -0
  23. package/src/lib/generators/project/i18n.mjs +38 -0
  24. package/src/lib/generators/project/plugin.mjs +38 -0
  25. package/src/lib/generators/project/splash.mjs +39 -0
  26. package/src/lib/generators/project/theme.mjs +38 -0
  27. package/src/lib/generators/serve/index.mjs +74 -0
  28. package/src/lib/generators/version/index.mjs +182 -0
  29. package/src/lib/generators/workspace/index.mjs +40 -0
  30. package/src/lib/generators/workspace/list-models.mjs +64 -0
  31. package/src/lib/generators/workspace/list-projects.mjs +167 -0
  32. package/src/lib/plopfile.mjs +67 -0
  33. package/src/lib/routing-plopfile.mjs +53 -0
  34. package/src/lib/scripts/generate-metadata.mjs +39 -0
  35. package/src/lib/utils/action-factory.mjs +9 -0
  36. package/src/lib/utils/cache.mjs +128 -0
  37. package/src/lib/utils/command-builder.mjs +94 -0
  38. package/src/lib/utils/exec.mjs +18 -0
  39. package/src/lib/utils/generator-loader.mjs +65 -0
  40. package/src/lib/utils/index.mjs +1 -0
  41. package/src/lib/utils/java-home.mjs +55 -0
  42. package/src/lib/utils/logger.mjs +0 -0
  43. package/src/lib/utils/nx-context.mjs +395 -0
  44. package/src/lib/utils/prompts.mjs +75 -0
  45. package/src/lib/utils/studio-home.mjs +12 -0
  46. package/src/lib/utils/utils.mjs +126 -0
  47. package/src/lib/utils/validators.mjs +10 -0
@@ -0,0 +1,41 @@
1
+ // generators/project/content.mjs
2
+ import { actionFactory } from "../../utils/action-factory.mjs";
3
+ import { execute } from "../../utils/exec.mjs";
4
+ import { required } from "../../utils/validators.mjs";
5
+
6
+ export const metadata = {
7
+ key: "content",
8
+ name: "KOS Content Project",
9
+ invalidateCache: true,
10
+ namedArguments: { name: "name" },
11
+ };
12
+
13
+ export default async function (plop) {
14
+ plop.setActionType("createContentProject", async function (answers) {
15
+ const command = `npx nx generate @kosdev-code/kos-nx-plugin:kos-content-project \
16
+ --name=${answers.name} \
17
+ --no-interactive`;
18
+
19
+ try {
20
+ await execute(command);
21
+ } catch (error) {
22
+ throw new Error(error);
23
+ }
24
+
25
+ return `Content project ${answers.name} created.`;
26
+ });
27
+
28
+ plop.setGenerator("content", {
29
+ description:
30
+ "Create a new KOS Content project for KAB (Kos Asset Bundle) generation",
31
+ prompts: [
32
+ {
33
+ type: "input",
34
+ name: "name",
35
+ message: "What is the name of the content project?",
36
+ validate: required,
37
+ },
38
+ ],
39
+ actions: actionFactory("createContentProject", metadata),
40
+ });
41
+ }
@@ -0,0 +1,38 @@
1
+ // generators/i18n/index.mjs
2
+ import { actionFactory } from "../../utils/action-factory.mjs";
3
+ import { execute } from "../../utils/exec.mjs";
4
+ import { required } from "../../utils/validators.mjs";
5
+ export const metadata = {
6
+ key: "i18n",
7
+ name: "KOS Localization Project",
8
+ invalidateCache: true,
9
+ namedArguments: { name: "name" },
10
+ };
11
+ export default async function (plop) {
12
+ plop.setActionType("createI18nProject", async function (answers) {
13
+ const command = `npx nx generate @kosdev-code/kos-nx-plugin:kos-i18n-project \
14
+ --name=${answers.name} \
15
+ --no-interactive`;
16
+
17
+ try {
18
+ await execute(command);
19
+ } catch (error) {
20
+ throw new Error(error);
21
+ }
22
+
23
+ return `i18n project ${answers.name} created.`;
24
+ });
25
+
26
+ plop.setGenerator("i18n", {
27
+ description: "Create a new KOS UI i18n project",
28
+ prompts: [
29
+ {
30
+ type: "input",
31
+ name: "name",
32
+ message: "What is the name of the i18n project?",
33
+ validate: required,
34
+ },
35
+ ],
36
+ actions: actionFactory("createI18nProject", metadata),
37
+ });
38
+ }
@@ -0,0 +1,38 @@
1
+ // generators/project/plugin.mjs
2
+ import { actionFactory } from "../../utils/action-factory.mjs";
3
+ import { execute } from "../../utils/exec.mjs";
4
+ import { required } from "../../utils/validators.mjs";
5
+ export const metadata = {
6
+ key: "plugin",
7
+ name: "KOS Plugin Project",
8
+ invalidateCache: true,
9
+ namedArguments: { name: "name" },
10
+ };
11
+ export default async function (plop) {
12
+ plop.setActionType("createPluginProject", async function (answers) {
13
+ const command = `npx nx generate @kosdev-code/kos-nx-plugin:kos-plugin-project \
14
+ --name=${answers.name} \
15
+ --no-interactive`;
16
+
17
+ try {
18
+ await execute(command);
19
+ } catch (error) {
20
+ throw new Error(error);
21
+ }
22
+
23
+ return `Plugin project ${answers.name} created.`;
24
+ });
25
+
26
+ plop.setGenerator("plugin", {
27
+ description: "Create a new KOS UI Plugin project",
28
+ prompts: [
29
+ {
30
+ type: "input",
31
+ name: "name",
32
+ message: "What is the name of the plugin project?",
33
+ validate: required,
34
+ },
35
+ ],
36
+ actions: actionFactory("createPluginProject", metadata),
37
+ });
38
+ }
@@ -0,0 +1,39 @@
1
+ // generators/project/splash.mjs
2
+ import { actionFactory } from "../../utils/action-factory.mjs";
3
+ import { execute } from "../../utils/exec.mjs";
4
+ import { required } from "../../utils/validators.mjs";
5
+
6
+ export const metadata = {
7
+ key: "project:splash",
8
+ name: "KOS Splash Screen Project",
9
+ invalidateCache: true,
10
+ namedArguments: { name: "name" },
11
+ };
12
+ export default async function (plop) {
13
+ plop.setActionType("createSplashProject", async function (answers) {
14
+ const command = `npx nx generate @kosdev-code/kos-nx-plugin:kos-splash-project \
15
+ --name=${answers.name} \
16
+ --no-interactive`;
17
+
18
+ try {
19
+ await execute(command);
20
+ } catch (error) {
21
+ throw new Error(error);
22
+ }
23
+
24
+ return `Splash page project ${answers.name} created.`;
25
+ });
26
+
27
+ plop.setGenerator("project:splash", {
28
+ description: "Create a new KOS Splash Page Project",
29
+ prompts: [
30
+ {
31
+ type: "input",
32
+ name: "name",
33
+ message: "What is the name of the splash project?",
34
+ validate: required,
35
+ },
36
+ ],
37
+ actions: actionFactory("createSplashProject", metadata),
38
+ });
39
+ }
@@ -0,0 +1,38 @@
1
+ // generators/project/theme.mjs
2
+ import { actionFactory } from "../../utils/action-factory.mjs";
3
+ import { execute } from "../../utils/exec.mjs";
4
+ import { required } from "../../utils/validators.mjs";
5
+ export const metadata = {
6
+ key: "theme",
7
+ name: "KOS Theme Project",
8
+ invalidateCache: true,
9
+ namedArguments: { name: "name" },
10
+ };
11
+ export default async function (plop) {
12
+ plop.setActionType("createThemeProject", async function (answers) {
13
+ const command = `npx nx generate @kosdev-code/kos-nx-plugin:kos-theme-project \
14
+ --name=${answers.name} \
15
+ --no-interactive`;
16
+
17
+ try {
18
+ await execute(command);
19
+ } catch (error) {
20
+ throw new Error(error);
21
+ }
22
+
23
+ return `Theme project ${answers.name} created.`;
24
+ });
25
+
26
+ plop.setGenerator("theme", {
27
+ description: "Create a new KOS UI Theme project",
28
+ prompts: [
29
+ {
30
+ type: "input",
31
+ name: "name",
32
+ message: "What is the name of the theme project?",
33
+ validate: required,
34
+ },
35
+ ],
36
+ actions: actionFactory("createThemeProject", metadata),
37
+ });
38
+ }
@@ -0,0 +1,74 @@
1
+ // generators/serve/index.mjs
2
+ import { execSync } from "child_process";
3
+ import { detectWorkspace } from "../../utils/nx-context.mjs";
4
+
5
+ export const metadata = {
6
+ key: "serve",
7
+ name: "Run Serve Target",
8
+ namedArguments: {
9
+ project: "project",
10
+ interactive: "interactive"
11
+ },
12
+ };
13
+
14
+ async function getProjectsWithTarget(target) {
15
+ try {
16
+ const output = execSync(`npx nx show projects --with-target ${target} --json`, {
17
+ encoding: "utf-8",
18
+ stdio: ["pipe", "pipe", "ignore"]
19
+ });
20
+ return JSON.parse(output);
21
+ } catch (error) {
22
+ return [];
23
+ }
24
+ }
25
+
26
+ export default async function (plop) {
27
+ const projects = await getProjectsWithTarget("serve");
28
+
29
+ if (projects.length === 0) {
30
+ console.warn("[kos-cli] No projects found with serve target");
31
+ // Still register the generator but it will fail gracefully
32
+ }
33
+
34
+ plop.setActionType("runServe", async function (answers) {
35
+ const isWorkspace = await detectWorkspace();
36
+
37
+ if (!isWorkspace) {
38
+ console.warn(
39
+ "[kos-cli] Not inside an Nx workspace. Cannot run serve target."
40
+ );
41
+ return "Skipped: Not a workspace";
42
+ }
43
+
44
+ const { project } = answers;
45
+
46
+ console.log(`[kos-cli] Running serve on ${project}...`);
47
+ try {
48
+ // Run serve in foreground with stdio inherited so it stays alive
49
+ execSync(`npx nx run ${project}:serve`, {
50
+ stdio: "inherit",
51
+ });
52
+ return `Serve completed for ${project}`;
53
+ } catch (error) {
54
+ // Don't throw error for Ctrl+C or normal termination
55
+ if (error.signal === "SIGINT") {
56
+ return `Serve terminated for ${project}`;
57
+ }
58
+ throw new Error(`Failed to run serve on ${project}: ${error.message}`);
59
+ }
60
+ });
61
+
62
+ plop.setGenerator("serve", {
63
+ description: "Run the serve target on a project",
64
+ prompts: [
65
+ {
66
+ type: "list",
67
+ name: "project",
68
+ message: "Select a project to serve:",
69
+ choices: projects,
70
+ },
71
+ ],
72
+ actions: () => [{ type: "runServe" }],
73
+ });
74
+ }
@@ -0,0 +1,182 @@
1
+ // generators/version/index.mjs
2
+ import { execSync } from "child_process";
3
+ import { existsSync, readFileSync } from "fs";
4
+ import path from "path";
5
+ import { detectWorkspace } from "../../utils/nx-context.mjs";
6
+
7
+ export const metadata = {
8
+ key: "version",
9
+ name: "Display CLI and SDK Version Information",
10
+ namedArguments: { interactive: "interactive" },
11
+ };
12
+
13
+ function getPackageVersion(packagePath) {
14
+ try {
15
+ const packageJsonPath = path.join(packagePath, "package.json");
16
+ if (existsSync(packageJsonPath)) {
17
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
18
+ return packageJson.version || "unknown";
19
+ }
20
+ } catch (error) {
21
+ // Package not found
22
+ }
23
+ return null;
24
+ }
25
+
26
+ function findWorkspaceRoot(startDir = process.cwd()) {
27
+ let dir = startDir;
28
+ while (dir !== path.dirname(dir)) {
29
+ if (existsSync(path.join(dir, "nx.json"))) {
30
+ return dir;
31
+ }
32
+ dir = path.dirname(dir);
33
+ }
34
+ return null;
35
+ }
36
+
37
+ function getCliVersion() {
38
+ let version = null;
39
+
40
+ // Option 1: Check workspace root package.json for installed CLI
41
+ const workspaceRoot = findWorkspaceRoot();
42
+ if (workspaceRoot) {
43
+ try {
44
+ const output = execSync(
45
+ "npm list @kosdev-code/kos-ui-cli --depth=0 --json",
46
+ {
47
+ cwd: workspaceRoot,
48
+ encoding: "utf-8",
49
+ stdio: ["pipe", "pipe", "ignore"],
50
+ }
51
+ );
52
+ const data = JSON.parse(output);
53
+ version = data?.dependencies?.["@kosdev-code/kos-ui-cli"]?.version;
54
+ } catch (error) {
55
+ // Not in workspace dependencies
56
+ }
57
+ }
58
+
59
+ // Option 2: Check global installation
60
+ if (!version) {
61
+ try {
62
+ const output = execSync(
63
+ "npm list -g @kosdev-code/kos-ui-cli --depth=0 --json",
64
+ {
65
+ encoding: "utf-8",
66
+ stdio: ["pipe", "pipe", "ignore"],
67
+ }
68
+ );
69
+ const data = JSON.parse(output);
70
+ version = data?.dependencies?.["@kosdev-code/kos-ui-cli"]?.version;
71
+ } catch (error) {
72
+ // Not installed globally
73
+ }
74
+ }
75
+
76
+ return version || "unknown";
77
+ }
78
+
79
+ export default async function (plop) {
80
+ plop.setActionType("showVersions", async function () {
81
+ console.log("[kos-cli] Discovering version information...\n");
82
+
83
+ const isWorkspace = await detectWorkspace();
84
+ const workspaceRoot = findWorkspaceRoot();
85
+
86
+ const versions = {};
87
+
88
+ // Get CLI version
89
+ versions.cli = getCliVersion();
90
+
91
+ if (isWorkspace && workspaceRoot) {
92
+ // Get SDK versions from workspace dependencies
93
+ const sdkPackages = {
94
+ sdk: ["@kosdev-code/kos-ui-sdk", "@kosdev-code/kos-dispense-sdk"],
95
+ ddk: [
96
+ "@kosdev-code/kos-ddk-components",
97
+ "@kosdev-code/kos-ddk-model-components",
98
+ ],
99
+ };
100
+
101
+ for (const [type, packages] of Object.entries(sdkPackages)) {
102
+ for (const pkgName of packages) {
103
+ try {
104
+ const output = execSync(`npm list ${pkgName} --depth=0 --json`, {
105
+ cwd: workspaceRoot,
106
+ encoding: "utf-8",
107
+ stdio: ["pipe", "pipe", "ignore"],
108
+ });
109
+ const data = JSON.parse(output);
110
+ const version = data?.dependencies?.[pkgName]?.version;
111
+ if (version) {
112
+ // Store with short name (without @kosdev-code/ prefix)
113
+ const shortName = pkgName.replace("@kosdev-code/", "");
114
+ versions[shortName] = version;
115
+ }
116
+ } catch (error) {
117
+ // Package not installed in workspace
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ // Display results
124
+ console.log("Version Information:");
125
+ console.log("===================\n");
126
+
127
+ if (versions.cli) {
128
+ console.log(`kos-ui-cli: ${versions.cli}`);
129
+ } else {
130
+ console.log("kos-ui-cli: unknown");
131
+ }
132
+
133
+ if (isWorkspace) {
134
+ console.log("");
135
+ console.log("SDK Packages:");
136
+ console.log("-------------");
137
+
138
+ if (versions["kos-ui-sdk"]) {
139
+ console.log(`kos-ui-sdk: ${versions["kos-ui-sdk"]}`);
140
+ }
141
+
142
+ if (versions["kos-dispense-sdk"]) {
143
+ console.log(`kos-dispense-sdk: ${versions["kos-dispense-sdk"]}`);
144
+ }
145
+
146
+ console.log("");
147
+ console.log("DDK Packages:");
148
+ console.log("-------------");
149
+
150
+ if (versions["kos-ddk-components"]) {
151
+ console.log(`kos-ddk-components: ${versions["kos-ddk-components"]}`);
152
+ }
153
+
154
+ if (versions["kos-ddk-model-components"]) {
155
+ console.log(
156
+ `kos-ddk-model-components: ${versions["kos-ddk-model-components"]}`
157
+ );
158
+ }
159
+
160
+ if (!versions["kos-ui-sdk"] && !versions["kos-dispense-sdk"]) {
161
+ console.log("(No SDK packages found in workspace)");
162
+ }
163
+
164
+ if (
165
+ !versions["kos-ddk-components"] &&
166
+ !versions["kos-ddk-model-components"]
167
+ ) {
168
+ console.log("(No DDK packages found in workspace)");
169
+ }
170
+ } else {
171
+ console.log("\n(Not in workspace - SDK versions unavailable)");
172
+ }
173
+
174
+ return "\n";
175
+ });
176
+
177
+ plop.setGenerator("version", {
178
+ description: "Display CLI and SDK version information",
179
+ prompts: [],
180
+ actions: () => [{ type: "showVersions" }],
181
+ });
182
+ }
@@ -0,0 +1,40 @@
1
+ // generators/workspace/index.mjs
2
+ import { createWorkspace } from "create-nx-workspace";
3
+ import { required } from "../../utils/validators.mjs";
4
+ import registerListModels from "./list-models.mjs";
5
+ import registerListProjects from "./list-projects.mjs";
6
+
7
+ export const metadata = {
8
+ key: "workspace",
9
+ name: "Create a new KOS UI Workspace",
10
+ namedArguments: {
11
+ name: "workspaceName",
12
+ workspaceName: "workspaceName"
13
+ }
14
+ };
15
+ export default async function (plop) {
16
+ plop.setActionType("createWorkspace", async function (answers) {
17
+ await createWorkspace("@kosdev-code/kos-nx-plugin", {
18
+ nxCloud: "skip",
19
+ name: answers.workspaceName,
20
+ });
21
+ return `Workspace ${answers.workspaceName} created.`;
22
+ });
23
+
24
+ plop.setGenerator("workspace", {
25
+ description: "KOS UI Workspace Setup",
26
+ prompts: [
27
+ {
28
+ type: "input",
29
+ name: "workspaceName",
30
+ message: "Enter the workspace name",
31
+ validate: required,
32
+ },
33
+ ],
34
+ actions: () => [{ type: "createWorkspace" }],
35
+ });
36
+
37
+ // Register additional workspace generators
38
+ await registerListModels(plop);
39
+ await registerListProjects(plop);
40
+ }
@@ -0,0 +1,64 @@
1
+ import { getAllModels } from "../../utils/nx-context.mjs";
2
+
3
+ /**
4
+ * Generator for listing all models in a workspace
5
+ */
6
+ export default async function register(plop) {
7
+ plop.setGenerator("workspace:list-models", {
8
+ description: "List all available models in the workspace",
9
+ prompts: [
10
+ {
11
+ type: "list",
12
+ name: "outputFormat",
13
+ message: "Output format",
14
+ choices: ["json", "table", "simple"],
15
+ default: "json",
16
+ },
17
+ ],
18
+ actions: function (answers) {
19
+ return [
20
+ async function listModels() {
21
+ const models = await getAllModels();
22
+
23
+ formatModelOutput(models, answers.outputFormat);
24
+
25
+ return `[ok] Found ${models.length} models in workspace`;
26
+ },
27
+ ];
28
+ },
29
+ });
30
+ }
31
+
32
+
33
+ function formatModelOutput(models, format) {
34
+ switch (format) {
35
+ case "json":
36
+ console.log(JSON.stringify(models, null, 2));
37
+ break;
38
+
39
+ case "table":
40
+ console.table(
41
+ models.map((m) => ({
42
+ Model: m.model,
43
+ Project: m.project,
44
+ }))
45
+ );
46
+ break;
47
+
48
+ case "simple":
49
+ for (const model of models) {
50
+ console.log(`${model.project}/${model.model}`);
51
+ }
52
+ break;
53
+ }
54
+ }
55
+
56
+ // Export metadata for CLI integration
57
+ export const metadata = {
58
+ key: "workspace:list-models",
59
+ name: "List all available models in the workspace",
60
+ description: "List all available models in the workspace",
61
+ namedArguments: {
62
+ format: "outputFormat",
63
+ },
64
+ };