@uns-kit/cli 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aljoša Vister
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @uns-kit/cli
2
+
3
+ Command line scaffolding tool for the UNS toolkit. It bootstraps a new project with `@uns-kit/core` preconfigured and ready to extend with additional plugins.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ pnpm dlx @uns-kit/cli create my-uns-app
9
+ # or after installing globally
10
+ yarn global add @uns-kit/cli
11
+ uns-kit create my-uns-app
12
+ ```
13
+
14
+ The command creates a new directory, copies the starter template, and pins `@uns-kit/core` to the currently published version. After the scaffold finishes:
15
+
16
+ ```bash
17
+ cd my-uns-app
18
+ pnpm install
19
+ pnpm run dev
20
+ ```
21
+
22
+ ## Commands
23
+
24
+ - `uns-kit create <name>` – create a new UNS project in the specified directory.
25
+ - `uns-kit help` – display usage information.
26
+
27
+ ## License
28
+
29
+ MIT © Aljoša Vister
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env node
2
+ import { access, cp, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createRequire } from "node:module";
6
+ import process from "node:process";
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const require = createRequire(import.meta.url);
10
+ const coreVersion = resolveCoreVersion();
11
+ async function main() {
12
+ const args = process.argv.slice(2);
13
+ const command = args[0];
14
+ if (!command || command === "help" || command === "--help" || command === "-h") {
15
+ printHelp();
16
+ return;
17
+ }
18
+ if (command === "create") {
19
+ const projectName = args[1];
20
+ if (!projectName) {
21
+ console.error("Missing project name. Example: uns-kit create my-app");
22
+ process.exitCode = 1;
23
+ return;
24
+ }
25
+ try {
26
+ await createProject(projectName);
27
+ }
28
+ catch (error) {
29
+ console.error(error.message);
30
+ process.exitCode = 1;
31
+ }
32
+ return;
33
+ }
34
+ console.error(`Unknown command: ${command}`);
35
+ printHelp();
36
+ process.exitCode = 1;
37
+ }
38
+ function printHelp() {
39
+ console.log(`\nUsage: uns-kit <command> [options]\n\nCommands:\n create <name> Scaffold a new UNS application\n help Show this message\n`);
40
+ }
41
+ async function createProject(projectName) {
42
+ const targetDir = path.resolve(process.cwd(), projectName);
43
+ await ensureTargetDir(targetDir);
44
+ const templateDir = path.resolve(__dirname, "../templates/default");
45
+ await cp(templateDir, targetDir, { recursive: true, force: false });
46
+ const pkgName = normalizePackageName(projectName);
47
+ await patchPackageJson(targetDir, pkgName);
48
+ await patchConfigJson(targetDir, pkgName);
49
+ await replacePlaceholders(targetDir, pkgName);
50
+ console.log(`\nCreated ${pkgName} in ${path.relative(process.cwd(), targetDir)}`);
51
+ console.log("Next steps:");
52
+ console.log(` cd ${projectName}`);
53
+ console.log(" pnpm install");
54
+ console.log(" pnpm run dev");
55
+ }
56
+ async function ensureTargetDir(dir) {
57
+ try {
58
+ const stats = await stat(dir);
59
+ if (!stats.isDirectory()) {
60
+ throw new Error(`Path ${dir} exists and is not a directory.`);
61
+ }
62
+ const entries = await readdir(dir);
63
+ if (entries.length > 0) {
64
+ throw new Error(`Directory ${dir} is not empty.`);
65
+ }
66
+ }
67
+ catch (error) {
68
+ if (error.code === "ENOENT") {
69
+ await mkdir(dir, { recursive: true });
70
+ return;
71
+ }
72
+ throw error;
73
+ }
74
+ }
75
+ async function patchPackageJson(targetDir, packageName) {
76
+ const pkgFile = path.join(targetDir, "package.json");
77
+ const raw = await readFile(pkgFile, "utf8");
78
+ const pkg = JSON.parse(raw);
79
+ pkg.name = packageName;
80
+ if (pkg.dependencies && pkg.dependencies["@uns-kit/core"]) {
81
+ pkg.dependencies["@uns-kit/core"] = `^${coreVersion}`;
82
+ }
83
+ await writeFile(pkgFile, JSON.stringify(pkg, null, 2) + "\n", "utf8");
84
+ }
85
+ async function patchConfigJson(targetDir, packageName) {
86
+ const configFile = path.join(targetDir, "config.json");
87
+ const raw = await readFile(configFile, "utf8");
88
+ const config = JSON.parse(raw);
89
+ if (config.uns && typeof config.uns === "object") {
90
+ config.uns.processName = packageName;
91
+ }
92
+ await writeFile(configFile, JSON.stringify(config, null, 2) + "\n", "utf8");
93
+ }
94
+ async function replacePlaceholders(targetDir, packageName) {
95
+ const replacements = {
96
+ __APP_NAME__: packageName
97
+ };
98
+ const filesToUpdate = [
99
+ path.join(targetDir, "README.md"),
100
+ path.join(targetDir, "src/index.ts")
101
+ ];
102
+ for (const file of filesToUpdate) {
103
+ try {
104
+ await access(file);
105
+ let content = await readFile(file, "utf8");
106
+ for (const [placeholder, value] of Object.entries(replacements)) {
107
+ content = content.replace(new RegExp(placeholder, "g"), value);
108
+ }
109
+ await writeFile(file, content, "utf8");
110
+ }
111
+ catch (error) {
112
+ if (error.code !== "ENOENT") {
113
+ throw error;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ function normalizePackageName(input) {
119
+ const trimmed = input.trim();
120
+ if (trimmed.startsWith("@")) {
121
+ return trimmed;
122
+ }
123
+ return trimmed
124
+ .toLowerCase()
125
+ .replace(/[^a-z0-9-]+/g, "-")
126
+ .replace(/^-+|-+$/g, "")
127
+ || "uns-app";
128
+ }
129
+ function resolveCoreVersion() {
130
+ try {
131
+ const corePkg = require("@uns-kit/core/package.json");
132
+ if (corePkg?.version) {
133
+ return corePkg.version;
134
+ }
135
+ }
136
+ catch (error) {
137
+ // Ignore and try local path
138
+ }
139
+ try {
140
+ const localPath = path.resolve(__dirname, "../../uns-core/package.json");
141
+ const raw = require(localPath);
142
+ if (raw?.version) {
143
+ return raw.version;
144
+ }
145
+ }
146
+ catch (error) {
147
+ // Ignore
148
+ }
149
+ return "0.0.1";
150
+ }
151
+ void main();
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@uns-kit/cli",
3
+ "version": "0.0.1",
4
+ "description": "Command line scaffolding tool for UNS applications",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Aljoša Vister <aljosa.vister@gmail.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/uns-datahub/uns-kit.git",
11
+ "directory": "packages/uns-cli"
12
+ },
13
+ "bin": {
14
+ "uns-kit": "./dist/index.js",
15
+ "uns": "./dist/index.js"
16
+ },
17
+ "keywords": [
18
+ "uns",
19
+ "cli",
20
+ "scaffold",
21
+ "template",
22
+ "typescript"
23
+ ],
24
+ "files": [
25
+ "dist",
26
+ "templates"
27
+ ],
28
+ "dependencies": {
29
+ "@uns-kit/core": "^0.0.1"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.build.json",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit"
34
+ }
35
+ }
@@ -0,0 +1,21 @@
1
+ # __APP_NAME__
2
+
3
+ Generated with `@uns-kit/cli`.
4
+
5
+ ## Scripts
6
+
7
+ ```bash
8
+ pnpm run dev # start the local development loop
9
+ pnpm run build # emit dist/ output
10
+ pnpm run start # run the compiled entrypoint
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Update `config.json` with your broker, UNS URLs, and credentials. The generated file contains sensible defaults for local development.
16
+
17
+ ## Next Steps
18
+
19
+ - Install additional plugins: `pnpm add @uns-kit/api` etc.
20
+ - Create MQTT proxies or Temporal workflows inside `src/index.ts`.
21
+ - Commit your new project and start building!
@@ -0,0 +1,18 @@
1
+ {
2
+ "uns": {
3
+ "graphql": "http://localhost:3200/graphql",
4
+ "rest": "http://localhost:3200/api",
5
+ "processName": "__APP_NAME__",
6
+ "instanceMode": "wait",
7
+ "handover": true
8
+ },
9
+ "infra": {
10
+ "host": "localhost:1883"
11
+ },
12
+ "output": {
13
+ "host": "localhost:1883"
14
+ },
15
+ "input": {
16
+ "host": "localhost:1883"
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "__APP_NAME__",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "typecheck": "tsc --noEmit",
7
+ "build": "tsc -p tsconfig.json",
8
+ "start": "node ./dist/index.js",
9
+ "dev": "tsx watch src/index.ts"
10
+ },
11
+ "dependencies": {
12
+ "@uns-kit/core": "__UNS_KIT_CORE_VERSION__"
13
+ },
14
+ "devDependencies": {
15
+ "tsx": "^4.20.5",
16
+ "typescript": "^5.9.2"
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
2
+
3
+ async function main(): Promise<void> {
4
+ const name = "__APP_NAME__";
5
+ const process = new UnsProxyProcess("localhost:1883", {
6
+ processName: name,
7
+ });
8
+
9
+ console.log(`UNS process '${name}' is ready. Edit src/index.ts to add your logic.`);
10
+
11
+ // Keep the process alive or add plugin logic here
12
+ void process;
13
+ }
14
+
15
+ void main();
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022"],
5
+ "module": "es2022",
6
+ "moduleResolution": "node",
7
+ "noEmit": false,
8
+ "outDir": "dist",
9
+ "rootDir": "src",
10
+ "strict": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "resolveJsonModule": true
14
+ },
15
+ "include": ["src/**/*.ts"]
16
+ }