@cieloazul310/digital-go-pandacss-cli 0.1.0-beta.6 → 0.1.0-beta.8
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/add-snippets.cjs +72 -20
- package/bin/add-snippets.js +79 -21
- package/bin/copy-components.cjs +52 -0
- package/bin/copy-components.js +33 -0
- package/bin/read-config.cjs +48 -0
- package/bin/read-config.js +23 -0
- package/bin/update.cjs +94 -0
- package/bin/update.js +99 -0
- package/package.json +7 -6
package/bin/add-snippets.cjs
CHANGED
|
@@ -4,38 +4,90 @@
|
|
|
4
4
|
// src/add-snippets.ts
|
|
5
5
|
var import_simple_git = require("simple-git");
|
|
6
6
|
var import_os = require("os");
|
|
7
|
+
var import_fs3 = require("fs");
|
|
8
|
+
var import_path3 = require("path");
|
|
9
|
+
|
|
10
|
+
// src/read-config.ts
|
|
7
11
|
var import_fs = require("fs");
|
|
8
12
|
var import_path = require("path");
|
|
9
|
-
|
|
10
|
-
const
|
|
13
|
+
function readConfig(cwd = process.cwd()) {
|
|
14
|
+
const defaultConfig = {
|
|
15
|
+
outDir: "src/components/ui",
|
|
16
|
+
override: true
|
|
17
|
+
};
|
|
11
18
|
const configPath = (0, import_path.join)(cwd, "components.json");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (!(0, import_fs.existsSync)(configPath)) {
|
|
20
|
+
return defaultConfig;
|
|
21
|
+
}
|
|
22
|
+
const config = JSON.parse(
|
|
23
|
+
(0, import_fs.readFileSync)(configPath, "utf-8")
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
...defaultConfig,
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/copy-components.ts
|
|
32
|
+
var import_fs2 = require("fs");
|
|
33
|
+
var import_path2 = require("path");
|
|
34
|
+
function copyComponents({
|
|
35
|
+
templateDir,
|
|
36
|
+
outputDir,
|
|
37
|
+
versionComment,
|
|
38
|
+
override = true
|
|
39
|
+
}) {
|
|
40
|
+
if ((0, import_fs2.existsSync)(outputDir) && !override) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const files = (0, import_fs2.readdirSync)(templateDir, { withFileTypes: true });
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
48
|
+
const filePath = (0, import_path2.join)(templateDir, file.name);
|
|
49
|
+
const content = (0, import_fs2.readFileSync)(filePath, "utf8");
|
|
50
|
+
(0, import_fs2.writeFileSync)(filePath, versionComment + content, "utf8");
|
|
51
|
+
}
|
|
20
52
|
}
|
|
53
|
+
(0, import_fs2.cpSync)(templateDir, outputDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/add-snippets.ts
|
|
57
|
+
async function main() {
|
|
58
|
+
const cwd = process.cwd();
|
|
59
|
+
const { outDir, sourceDir, override } = readConfig(cwd);
|
|
60
|
+
let templateDir = sourceDir ? (0, import_path3.join)(cwd, sourceDir) : void 0;
|
|
21
61
|
if (!templateDir) {
|
|
22
62
|
const git = (0, import_simple_git.simpleGit)();
|
|
23
63
|
const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
|
|
24
64
|
const templateSubdir = "components/src";
|
|
25
|
-
const tmpPath = (0,
|
|
65
|
+
const tmpPath = (0, import_path3.join)((0, import_os.tmpdir)(), `digital-go-pandacss-${Date.now()}`);
|
|
26
66
|
await git.clone(repoUrl, tmpPath);
|
|
27
|
-
|
|
67
|
+
const repoGit = (0, import_simple_git.simpleGit)(tmpPath);
|
|
68
|
+
const tag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
|
|
69
|
+
const commit = (await repoGit.revparse(["HEAD"])).trim();
|
|
70
|
+
templateDir = (0, import_path3.join)(tmpPath, templateSubdir);
|
|
71
|
+
const files = (0, import_fs3.readdirSync)(templateDir, { withFileTypes: true });
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
if (file.isFile() && file.name.endsWith(".tsx")) {
|
|
74
|
+
const filePath = (0, import_path3.join)(templateDir, file.name);
|
|
75
|
+
const content = (0, import_fs3.readFileSync)(filePath, "utf8");
|
|
76
|
+
const versionComment = `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})
|
|
77
|
+
`;
|
|
78
|
+
(0, import_fs3.writeFileSync)(filePath, versionComment + content, "utf8");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
28
81
|
}
|
|
29
|
-
if (!(0,
|
|
82
|
+
if (!(0, import_fs3.existsSync)(templateDir)) {
|
|
30
83
|
throw new Error(`Template directory not found: ${templateDir}`);
|
|
31
84
|
}
|
|
32
|
-
const outputDir = (0,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
(0, import_fs.cpSync)(templateDir, outputDir, { recursive: true });
|
|
85
|
+
const outputDir = (0, import_path3.join)(cwd, outDir);
|
|
86
|
+
copyComponents({
|
|
87
|
+
templateDir,
|
|
88
|
+
outputDir,
|
|
89
|
+
override
|
|
90
|
+
});
|
|
39
91
|
console.log(`\u2705 UI components generated from GitHub at ${outDir}`);
|
|
40
92
|
}
|
|
41
93
|
main().then(() => process.exit(0)).catch((err) => {
|
package/bin/add-snippets.js
CHANGED
|
@@ -3,38 +3,96 @@
|
|
|
3
3
|
// src/add-snippets.ts
|
|
4
4
|
import { simpleGit } from "simple-git";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
|
-
import {
|
|
6
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
7
|
+
import { join as join3 } from "path";
|
|
8
|
+
|
|
9
|
+
// src/read-config.ts
|
|
10
|
+
import { existsSync, readFileSync } from "fs";
|
|
7
11
|
import { join } from "path";
|
|
8
|
-
|
|
9
|
-
const
|
|
12
|
+
function readConfig(cwd = process.cwd()) {
|
|
13
|
+
const defaultConfig = {
|
|
14
|
+
outDir: "src/components/ui",
|
|
15
|
+
override: true
|
|
16
|
+
};
|
|
10
17
|
const configPath = join(cwd, "components.json");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let override = true;
|
|
14
|
-
if (existsSync(configPath)) {
|
|
15
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
16
|
-
outDir = config.outDir ?? outDir;
|
|
17
|
-
templateDir = config.sourceDir ? join(cwd, config.sourceDir) : void 0;
|
|
18
|
-
override = config.override ?? override;
|
|
18
|
+
if (!existsSync(configPath)) {
|
|
19
|
+
return defaultConfig;
|
|
19
20
|
}
|
|
21
|
+
const config = JSON.parse(
|
|
22
|
+
readFileSync(configPath, "utf-8")
|
|
23
|
+
);
|
|
24
|
+
return {
|
|
25
|
+
...defaultConfig,
|
|
26
|
+
...config
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/copy-components.ts
|
|
31
|
+
import {
|
|
32
|
+
readdirSync,
|
|
33
|
+
readFileSync as readFileSync2,
|
|
34
|
+
writeFileSync,
|
|
35
|
+
existsSync as existsSync2,
|
|
36
|
+
cpSync
|
|
37
|
+
} from "fs";
|
|
38
|
+
import { join as join2 } from "path";
|
|
39
|
+
function copyComponents({
|
|
40
|
+
templateDir,
|
|
41
|
+
outputDir,
|
|
42
|
+
versionComment,
|
|
43
|
+
override = true
|
|
44
|
+
}) {
|
|
45
|
+
if (existsSync2(outputDir) && !override) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const files = readdirSync(templateDir, { withFileTypes: true });
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
53
|
+
const filePath = join2(templateDir, file.name);
|
|
54
|
+
const content = readFileSync2(filePath, "utf8");
|
|
55
|
+
writeFileSync(filePath, versionComment + content, "utf8");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
cpSync(templateDir, outputDir, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/add-snippets.ts
|
|
62
|
+
async function main() {
|
|
63
|
+
const cwd = process.cwd();
|
|
64
|
+
const { outDir, sourceDir, override } = readConfig(cwd);
|
|
65
|
+
let templateDir = sourceDir ? join3(cwd, sourceDir) : void 0;
|
|
20
66
|
if (!templateDir) {
|
|
21
67
|
const git = simpleGit();
|
|
22
68
|
const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
|
|
23
69
|
const templateSubdir = "components/src";
|
|
24
|
-
const tmpPath =
|
|
70
|
+
const tmpPath = join3(tmpdir(), `digital-go-pandacss-${Date.now()}`);
|
|
25
71
|
await git.clone(repoUrl, tmpPath);
|
|
26
|
-
|
|
72
|
+
const repoGit = simpleGit(tmpPath);
|
|
73
|
+
const tag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
|
|
74
|
+
const commit = (await repoGit.revparse(["HEAD"])).trim();
|
|
75
|
+
templateDir = join3(tmpPath, templateSubdir);
|
|
76
|
+
const files = readdirSync2(templateDir, { withFileTypes: true });
|
|
77
|
+
for (const file of files) {
|
|
78
|
+
if (file.isFile() && file.name.endsWith(".tsx")) {
|
|
79
|
+
const filePath = join3(templateDir, file.name);
|
|
80
|
+
const content = readFileSync3(filePath, "utf8");
|
|
81
|
+
const versionComment = `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})
|
|
82
|
+
`;
|
|
83
|
+
writeFileSync2(filePath, versionComment + content, "utf8");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
27
86
|
}
|
|
28
|
-
if (!
|
|
87
|
+
if (!existsSync3(templateDir)) {
|
|
29
88
|
throw new Error(`Template directory not found: ${templateDir}`);
|
|
30
89
|
}
|
|
31
|
-
const outputDir =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
cpSync(templateDir, outputDir, { recursive: true });
|
|
90
|
+
const outputDir = join3(cwd, outDir);
|
|
91
|
+
copyComponents({
|
|
92
|
+
templateDir,
|
|
93
|
+
outputDir,
|
|
94
|
+
override
|
|
95
|
+
});
|
|
38
96
|
console.log(`\u2705 UI components generated from GitHub at ${outDir}`);
|
|
39
97
|
}
|
|
40
98
|
main().then(() => process.exit(0)).catch((err) => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/copy-components.ts
|
|
21
|
+
var copy_components_exports = {};
|
|
22
|
+
__export(copy_components_exports, {
|
|
23
|
+
copyComponents: () => copyComponents
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(copy_components_exports);
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
function copyComponents({
|
|
29
|
+
templateDir,
|
|
30
|
+
outputDir,
|
|
31
|
+
versionComment,
|
|
32
|
+
override = true
|
|
33
|
+
}) {
|
|
34
|
+
if ((0, import_fs.existsSync)(outputDir) && !override) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const files = (0, import_fs.readdirSync)(templateDir, { withFileTypes: true });
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
42
|
+
const filePath = (0, import_path.join)(templateDir, file.name);
|
|
43
|
+
const content = (0, import_fs.readFileSync)(filePath, "utf8");
|
|
44
|
+
(0, import_fs.writeFileSync)(filePath, versionComment + content, "utf8");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
(0, import_fs.cpSync)(templateDir, outputDir, { recursive: true });
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
copyComponents
|
|
52
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/copy-components.ts
|
|
2
|
+
import {
|
|
3
|
+
readdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
cpSync
|
|
8
|
+
} from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
function copyComponents({
|
|
11
|
+
templateDir,
|
|
12
|
+
outputDir,
|
|
13
|
+
versionComment,
|
|
14
|
+
override = true
|
|
15
|
+
}) {
|
|
16
|
+
if (existsSync(outputDir) && !override) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const files = readdirSync(templateDir, { withFileTypes: true });
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
24
|
+
const filePath = join(templateDir, file.name);
|
|
25
|
+
const content = readFileSync(filePath, "utf8");
|
|
26
|
+
writeFileSync(filePath, versionComment + content, "utf8");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
cpSync(templateDir, outputDir, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
copyComponents
|
|
33
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/read-config.ts
|
|
21
|
+
var read_config_exports = {};
|
|
22
|
+
__export(read_config_exports, {
|
|
23
|
+
readConfig: () => readConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(read_config_exports);
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
function readConfig(cwd = process.cwd()) {
|
|
29
|
+
const defaultConfig = {
|
|
30
|
+
outDir: "src/components/ui",
|
|
31
|
+
override: true
|
|
32
|
+
};
|
|
33
|
+
const configPath = (0, import_path.join)(cwd, "components.json");
|
|
34
|
+
if (!(0, import_fs.existsSync)(configPath)) {
|
|
35
|
+
return defaultConfig;
|
|
36
|
+
}
|
|
37
|
+
const config = JSON.parse(
|
|
38
|
+
(0, import_fs.readFileSync)(configPath, "utf-8")
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
...defaultConfig,
|
|
42
|
+
...config
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
readConfig
|
|
48
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/read-config.ts
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
function readConfig(cwd = process.cwd()) {
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
outDir: "src/components/ui",
|
|
7
|
+
override: true
|
|
8
|
+
};
|
|
9
|
+
const configPath = join(cwd, "components.json");
|
|
10
|
+
if (!existsSync(configPath)) {
|
|
11
|
+
return defaultConfig;
|
|
12
|
+
}
|
|
13
|
+
const config = JSON.parse(
|
|
14
|
+
readFileSync(configPath, "utf-8")
|
|
15
|
+
);
|
|
16
|
+
return {
|
|
17
|
+
...defaultConfig,
|
|
18
|
+
...config
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
readConfig
|
|
23
|
+
};
|
package/bin/update.cjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/update.ts
|
|
5
|
+
var import_simple_git = require("simple-git");
|
|
6
|
+
var import_os = require("os");
|
|
7
|
+
var import_fs3 = require("fs");
|
|
8
|
+
var import_path3 = require("path");
|
|
9
|
+
|
|
10
|
+
// src/read-config.ts
|
|
11
|
+
var import_fs = require("fs");
|
|
12
|
+
var import_path = require("path");
|
|
13
|
+
function readConfig(cwd = process.cwd()) {
|
|
14
|
+
const defaultConfig = {
|
|
15
|
+
outDir: "src/components/ui",
|
|
16
|
+
override: true
|
|
17
|
+
};
|
|
18
|
+
const configPath = (0, import_path.join)(cwd, "components.json");
|
|
19
|
+
if (!(0, import_fs.existsSync)(configPath)) {
|
|
20
|
+
return defaultConfig;
|
|
21
|
+
}
|
|
22
|
+
const config = JSON.parse(
|
|
23
|
+
(0, import_fs.readFileSync)(configPath, "utf-8")
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
...defaultConfig,
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/copy-components.ts
|
|
32
|
+
var import_fs2 = require("fs");
|
|
33
|
+
var import_path2 = require("path");
|
|
34
|
+
function copyComponents({
|
|
35
|
+
templateDir,
|
|
36
|
+
outputDir,
|
|
37
|
+
versionComment,
|
|
38
|
+
override = true
|
|
39
|
+
}) {
|
|
40
|
+
if ((0, import_fs2.existsSync)(outputDir) && !override) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const files = (0, import_fs2.readdirSync)(templateDir, { withFileTypes: true });
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
48
|
+
const filePath = (0, import_path2.join)(templateDir, file.name);
|
|
49
|
+
const content = (0, import_fs2.readFileSync)(filePath, "utf8");
|
|
50
|
+
(0, import_fs2.writeFileSync)(filePath, versionComment + content, "utf8");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
(0, import_fs2.cpSync)(templateDir, outputDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/update.ts
|
|
57
|
+
async function main() {
|
|
58
|
+
const cwd = process.cwd();
|
|
59
|
+
const { outDir, sourceDir, override } = readConfig(cwd);
|
|
60
|
+
let templateDir = sourceDir ? (0, import_path3.join)(cwd, sourceDir) : void 0;
|
|
61
|
+
let latestTag = "";
|
|
62
|
+
let latestCommit = "";
|
|
63
|
+
if (!templateDir) {
|
|
64
|
+
const git = (0, import_simple_git.simpleGit)();
|
|
65
|
+
const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
|
|
66
|
+
const templateSubdir = "components/src";
|
|
67
|
+
const tmpPath = (0, import_path3.join)((0, import_os.tmpdir)(), `digital-go-pandacss-${Date.now()}`);
|
|
68
|
+
await git.clone(repoUrl, tmpPath);
|
|
69
|
+
const repoGit = (0, import_simple_git.simpleGit)(tmpPath);
|
|
70
|
+
latestTag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
|
|
71
|
+
latestCommit = (await repoGit.revparse(["HEAD"])).trim();
|
|
72
|
+
templateDir = (0, import_path3.join)(tmpPath, templateSubdir);
|
|
73
|
+
}
|
|
74
|
+
if (!(0, import_fs3.existsSync)(templateDir)) {
|
|
75
|
+
throw new Error(`Template directory not found: ${templateDir}`);
|
|
76
|
+
}
|
|
77
|
+
const outputDir = (0, import_path3.join)(cwd, outDir);
|
|
78
|
+
if (!(0, import_fs3.existsSync)(outputDir)) {
|
|
79
|
+
throw new Error(`Output directory not found: ${outputDir}`);
|
|
80
|
+
}
|
|
81
|
+
const versionComment = latestTag ? `// Generated from digital-go-design-system-with-panda@${latestTag} (commit: ${latestCommit})
|
|
82
|
+
` : void 0;
|
|
83
|
+
copyComponents({
|
|
84
|
+
templateDir,
|
|
85
|
+
outputDir,
|
|
86
|
+
versionComment,
|
|
87
|
+
override
|
|
88
|
+
});
|
|
89
|
+
console.log(`\u2705 UI components generated from GitHub at ${outDir}`);
|
|
90
|
+
}
|
|
91
|
+
main().then(() => process.exit(0)).catch((err) => {
|
|
92
|
+
console.error(err);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
package/bin/update.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/update.ts
|
|
4
|
+
import { simpleGit } from "simple-git";
|
|
5
|
+
import { tmpdir } from "os";
|
|
6
|
+
import { existsSync as existsSync3 } from "fs";
|
|
7
|
+
import { join as join3 } from "path";
|
|
8
|
+
|
|
9
|
+
// src/read-config.ts
|
|
10
|
+
import { existsSync, readFileSync } from "fs";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
function readConfig(cwd = process.cwd()) {
|
|
13
|
+
const defaultConfig = {
|
|
14
|
+
outDir: "src/components/ui",
|
|
15
|
+
override: true
|
|
16
|
+
};
|
|
17
|
+
const configPath = join(cwd, "components.json");
|
|
18
|
+
if (!existsSync(configPath)) {
|
|
19
|
+
return defaultConfig;
|
|
20
|
+
}
|
|
21
|
+
const config = JSON.parse(
|
|
22
|
+
readFileSync(configPath, "utf-8")
|
|
23
|
+
);
|
|
24
|
+
return {
|
|
25
|
+
...defaultConfig,
|
|
26
|
+
...config
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/copy-components.ts
|
|
31
|
+
import {
|
|
32
|
+
readdirSync,
|
|
33
|
+
readFileSync as readFileSync2,
|
|
34
|
+
writeFileSync,
|
|
35
|
+
existsSync as existsSync2,
|
|
36
|
+
cpSync
|
|
37
|
+
} from "fs";
|
|
38
|
+
import { join as join2 } from "path";
|
|
39
|
+
function copyComponents({
|
|
40
|
+
templateDir,
|
|
41
|
+
outputDir,
|
|
42
|
+
versionComment,
|
|
43
|
+
override = true
|
|
44
|
+
}) {
|
|
45
|
+
if (existsSync2(outputDir) && !override) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Output directory already exists: ${outputDir}. Use --override to overwrite.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const files = readdirSync(templateDir, { withFileTypes: true });
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
if (file.isFile() && file.name.endsWith(".tsx") && versionComment) {
|
|
53
|
+
const filePath = join2(templateDir, file.name);
|
|
54
|
+
const content = readFileSync2(filePath, "utf8");
|
|
55
|
+
writeFileSync(filePath, versionComment + content, "utf8");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
cpSync(templateDir, outputDir, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/update.ts
|
|
62
|
+
async function main() {
|
|
63
|
+
const cwd = process.cwd();
|
|
64
|
+
const { outDir, sourceDir, override } = readConfig(cwd);
|
|
65
|
+
let templateDir = sourceDir ? join3(cwd, sourceDir) : void 0;
|
|
66
|
+
let latestTag = "";
|
|
67
|
+
let latestCommit = "";
|
|
68
|
+
if (!templateDir) {
|
|
69
|
+
const git = simpleGit();
|
|
70
|
+
const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
|
|
71
|
+
const templateSubdir = "components/src";
|
|
72
|
+
const tmpPath = join3(tmpdir(), `digital-go-pandacss-${Date.now()}`);
|
|
73
|
+
await git.clone(repoUrl, tmpPath);
|
|
74
|
+
const repoGit = simpleGit(tmpPath);
|
|
75
|
+
latestTag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
|
|
76
|
+
latestCommit = (await repoGit.revparse(["HEAD"])).trim();
|
|
77
|
+
templateDir = join3(tmpPath, templateSubdir);
|
|
78
|
+
}
|
|
79
|
+
if (!existsSync3(templateDir)) {
|
|
80
|
+
throw new Error(`Template directory not found: ${templateDir}`);
|
|
81
|
+
}
|
|
82
|
+
const outputDir = join3(cwd, outDir);
|
|
83
|
+
if (!existsSync3(outputDir)) {
|
|
84
|
+
throw new Error(`Output directory not found: ${outputDir}`);
|
|
85
|
+
}
|
|
86
|
+
const versionComment = latestTag ? `// Generated from digital-go-design-system-with-panda@${latestTag} (commit: ${latestCommit})
|
|
87
|
+
` : void 0;
|
|
88
|
+
copyComponents({
|
|
89
|
+
templateDir,
|
|
90
|
+
outputDir,
|
|
91
|
+
versionComment,
|
|
92
|
+
override
|
|
93
|
+
});
|
|
94
|
+
console.log(`\u2705 UI components generated from GitHub at ${outDir}`);
|
|
95
|
+
}
|
|
96
|
+
main().then(() => process.exit(0)).catch((err) => {
|
|
97
|
+
console.error(err);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cieloazul310/digital-go-pandacss-cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/cieloazul310/digital-go-design-system-with-panda",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"public"
|
|
23
23
|
],
|
|
24
24
|
"bin": {
|
|
25
|
-
"add": "./bin/add-snippets.cjs"
|
|
25
|
+
"add": "./bin/add-snippets.cjs",
|
|
26
|
+
"update": "./bin/update.cjs"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"build": "tsup",
|
|
@@ -34,12 +35,12 @@
|
|
|
34
35
|
"simple-git": "^3.28.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@repo/eslint-config": "^0.1.0-beta.
|
|
38
|
-
"@repo/typescript-config": "^0.1.0-beta.
|
|
39
|
-
"eslint": "^9.
|
|
38
|
+
"@repo/eslint-config": "^0.1.0-beta.3",
|
|
39
|
+
"@repo/typescript-config": "^0.1.0-beta.3",
|
|
40
|
+
"eslint": "^9.32.0",
|
|
40
41
|
"execa": "^9.6.0",
|
|
41
42
|
"tsup": "8.5.0",
|
|
42
|
-
"typescript": "5.8.3"
|
|
43
|
+
"typescript": "^5.8.3"
|
|
43
44
|
},
|
|
44
45
|
"lint-staged": {
|
|
45
46
|
"**/*.{js,mjs,cjs,tsx,ts,tsx}": [
|