@connectycube/react-ui-kit 0.0.1 â 0.0.3
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/bin/cli.js +1 -1
- package/cmd/add.js +93 -0
- package/package.json +4 -3
package/bin/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const commandsDir = path.resolve(__dirname, '../
|
|
7
|
+
const commandsDir = path.resolve(__dirname, '../cmd');
|
|
8
8
|
const args = process.argv.slice(2);
|
|
9
9
|
const cmd = args[0];
|
|
10
10
|
|
package/cmd/add.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { execa } from "execa";
|
|
6
|
+
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
async function promptIsTypeScript() {
|
|
11
|
+
const response = await prompts({
|
|
12
|
+
type: "select",
|
|
13
|
+
name: "isTypeScript",
|
|
14
|
+
message: "What language does your project use?",
|
|
15
|
+
choices: [
|
|
16
|
+
{ title: "đ TypeScript (đĻ *.{ts,tsx})", value: true },
|
|
17
|
+
{ title: "đ JavaScript (đ¨ *.{js,jsx})", value: false }
|
|
18
|
+
],
|
|
19
|
+
initial: 0
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return response.isTypeScript;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function installDependencies(component) {
|
|
26
|
+
const input = path.join(__dirname, "..", "configs", "dependencies.json");
|
|
27
|
+
|
|
28
|
+
if (await fs.pathExists(input)) return;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const allDeps = await fs.readJSON(input);
|
|
32
|
+
const cmpDeps = allDeps && allDeps[component];
|
|
33
|
+
|
|
34
|
+
if (cmpDeps && typeof cmpDeps === "object") {
|
|
35
|
+
const deps = Object.entries(cmpDeps).map(([pkg, ver]) => (ver ? `${pkg}@${ver}` : pkg));
|
|
36
|
+
|
|
37
|
+
if (deps.length) {
|
|
38
|
+
const pm = fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))
|
|
39
|
+
? "pnpm" : fs.existsSync(path.join(cwd, "yarn.lock"))
|
|
40
|
+
? "yarn" : "npm";
|
|
41
|
+
|
|
42
|
+
if (!pm || !deps || deps.length === 0) return;
|
|
43
|
+
|
|
44
|
+
console.log(`âšī¸ Installing dependencies for ${component}: ${deps.join(", ")}`);
|
|
45
|
+
|
|
46
|
+
const cmd = pm === "yarn" || pm === "pnpm" ? "add" : "install";
|
|
47
|
+
const flags = pm === "npm" ? ["--save"] : [];
|
|
48
|
+
const opts = { cwd, stdio: "inherit" };
|
|
49
|
+
|
|
50
|
+
await execa(pm, [cmd, ...flags, ...deps], opts);
|
|
51
|
+
console.log("â
Dependencies installed.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.warn(`â ī¸ Failed to read '${input}':`, err.message);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function add(component) {
|
|
60
|
+
if (!component) {
|
|
61
|
+
console.warn(`â ī¸ Usage: npx @connectycube/react-ui-kit add [component-name]`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const isTypeScript = await promptIsTypeScript();
|
|
66
|
+
|
|
67
|
+
if (isTypeScript === undefined) {
|
|
68
|
+
console.error("ī¸â Aborted.");
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const filename = `${component}${isTypeScript ? ".tsx" : ".jsx"}`;
|
|
73
|
+
const base = path.join(__dirname, "..", isTypeScript ? "src" : "gen");
|
|
74
|
+
const input = path.join(base, "templates", filename);
|
|
75
|
+
const utils = path.join(base, "lib");
|
|
76
|
+
|
|
77
|
+
if (!(await fs.pathExists(input))) {
|
|
78
|
+
console.warn(`â ī¸ Component "${component}" does not exist.`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const baseDest = path.join(cwd, "src", "components", "connectycube-ui");
|
|
83
|
+
const libDest = path.join(baseDest, "lib");
|
|
84
|
+
const output = path.join(baseDest, filename);
|
|
85
|
+
|
|
86
|
+
await fs.ensureDir(baseDest);
|
|
87
|
+
await fs.copyFile(input, output);
|
|
88
|
+
console.log(`â
Added file "${output}"`);
|
|
89
|
+
await fs.ensureDir(libDest);
|
|
90
|
+
await fs.copy(utils, libDest);
|
|
91
|
+
console.log(`â
Added "${libDest}/*.${isTypeScript ? "ts" : "js"}" folder.`);
|
|
92
|
+
await installDependencies(component);
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connectycube/react-ui-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Simple React UI Kit generator with TSX/JSX",
|
|
5
5
|
"homepage": "https://github.com/ConnectyCube/react-ui-kit#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
"module": "dist/index.js",
|
|
34
34
|
"types": "dist/types/index.d.ts",
|
|
35
35
|
"files": [
|
|
36
|
-
"dist",
|
|
37
36
|
"bin",
|
|
37
|
+
"cmd",
|
|
38
|
+
"dist",
|
|
38
39
|
"src",
|
|
39
40
|
"gen"
|
|
40
41
|
],
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"@rollup/plugin-commonjs": "^28.0.8",
|
|
71
72
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
72
73
|
"@rollup/plugin-terser": "^0.4.4",
|
|
73
|
-
"@rollup/plugin-typescript": "^12.
|
|
74
|
+
"@rollup/plugin-typescript": "^12.2.0",
|
|
74
75
|
"@stylistic/eslint-plugin": "^5.5.0",
|
|
75
76
|
"@types/node": "^24.9.1",
|
|
76
77
|
"@types/react": "^19.2.2",
|