create-antd-skin 1.0.0
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/index.js +15 -0
- package/bin/skin.js +112 -0
- package/package.json +54 -0
package/bin/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const skin_1 = require("./skin");
|
|
6
|
+
const program = new commander_1.Command();
|
|
7
|
+
program
|
|
8
|
+
.name('create-antd-skin')
|
|
9
|
+
.description("Add a leather theme to an antd-layout project")
|
|
10
|
+
.version("1.0.0")
|
|
11
|
+
.argument("<skin-name>", 'Skin name')
|
|
12
|
+
.action(async (skinName) => {
|
|
13
|
+
(0, skin_1.installSkin)(skinName);
|
|
14
|
+
});
|
|
15
|
+
program.parse();
|
package/bin/skin.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.installSkin = installSkin;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const ora_1 = __importDefault(require("ora"));
|
|
12
|
+
async function getSkinList() {
|
|
13
|
+
const skinsDir = path_1.default.join(__dirname, "../skins");
|
|
14
|
+
if (!fs_extra_1.default.existsSync(skinsDir)) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const dirs = await fs_extra_1.default.readdir(skinsDir);
|
|
18
|
+
return dirs
|
|
19
|
+
.map(name => ({
|
|
20
|
+
name,
|
|
21
|
+
path: path_1.default.join(skinsDir, name),
|
|
22
|
+
}))
|
|
23
|
+
.filter(item => {
|
|
24
|
+
return fs_extra_1.default.statSync(item.path).isDirectory();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function copySkinFiles(skinName, skinDir, projectRoot) {
|
|
28
|
+
const skinIndexFile = path_1.default.join(skinDir, "index.ts");
|
|
29
|
+
const skinImagesDir = path_1.default.join(skinDir, "images");
|
|
30
|
+
const targetSkinDir = path_1.default.join(projectRoot, "src/components/warden-skin", skinName);
|
|
31
|
+
const targetImagesDir = path_1.default.join(projectRoot, "public/images", skinName);
|
|
32
|
+
await fs_extra_1.default.ensureDir(targetSkinDir);
|
|
33
|
+
if (!fs_extra_1.default.existsSync(skinIndexFile)) {
|
|
34
|
+
throw new Error(`${skinName}/index.ts not found`);
|
|
35
|
+
}
|
|
36
|
+
await fs_extra_1.default.copy(skinIndexFile, path_1.default.join(targetSkinDir, "index.ts"));
|
|
37
|
+
if (fs_extra_1.default.existsSync(skinImagesDir)) {
|
|
38
|
+
await fs_extra_1.default.copy(skinImagesDir, targetImagesDir);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function updateSkinIndex(skinName, projectRoot) {
|
|
42
|
+
const skinRoot = path_1.default.join(projectRoot, "src/components/warden-skin");
|
|
43
|
+
const indexFile = path_1.default.join(skinRoot, "index.ts");
|
|
44
|
+
await fs_extra_1.default.ensureDir(skinRoot);
|
|
45
|
+
const dirs = (await fs_extra_1.default.readdir(skinRoot))
|
|
46
|
+
.filter(item => item !== "index.ts")
|
|
47
|
+
.filter(item => fs_extra_1.default.statSync(path_1.default.join(skinRoot, item)).isDirectory());
|
|
48
|
+
const skinNames = Array.from(new Set([...dirs, skinName]));
|
|
49
|
+
const imports = skinNames
|
|
50
|
+
.map(name => {
|
|
51
|
+
const varName = toCamelCase(name);
|
|
52
|
+
return `import ${varName} from "./${name}"`;
|
|
53
|
+
})
|
|
54
|
+
.join("\n");
|
|
55
|
+
const exports = skinNames
|
|
56
|
+
.map(name => toCamelCase(name))
|
|
57
|
+
.join(", ");
|
|
58
|
+
const content = `${imports}
|
|
59
|
+
|
|
60
|
+
export default [${exports}]
|
|
61
|
+
`;
|
|
62
|
+
await fs_extra_1.default.writeFile(indexFile, content);
|
|
63
|
+
}
|
|
64
|
+
function toCamelCase(str) {
|
|
65
|
+
return str.replace(/-([a-z])/g, (_, group1) => group1.toUpperCase())
|
|
66
|
+
.replace(/^\w/, s => s.toUpperCase());
|
|
67
|
+
}
|
|
68
|
+
function toKebabCase(str) {
|
|
69
|
+
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
async function installSkin(skinName) {
|
|
72
|
+
const cwd = process.cwd();
|
|
73
|
+
const skins = await getSkinList();
|
|
74
|
+
if (!skins.length) {
|
|
75
|
+
console.error(chalk_1.default.red("❌ No skins found."));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
let selectedSkin = skinName;
|
|
79
|
+
if (!selectedSkin) {
|
|
80
|
+
const answer = await inquirer_1.default.prompt([
|
|
81
|
+
{
|
|
82
|
+
type: "list",
|
|
83
|
+
name: "skin",
|
|
84
|
+
message: "Choose a skin",
|
|
85
|
+
choices: skins.map(item => ({
|
|
86
|
+
name: item.name,
|
|
87
|
+
value: item.name,
|
|
88
|
+
})),
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
selectedSkin = answer.skin;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
selectedSkin = toKebabCase(skinName);
|
|
95
|
+
}
|
|
96
|
+
const skin = skins.find(item => item.name === selectedSkin);
|
|
97
|
+
if (!skin) {
|
|
98
|
+
console.error(chalk_1.default.red(`❌ Skin "${selectedSkin}" not found.`));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const spinner = (0, ora_1.default)(`Installing skin "${selectedSkin}"...`).start();
|
|
102
|
+
try {
|
|
103
|
+
await copySkinFiles(selectedSkin, skin.path, cwd);
|
|
104
|
+
await updateSkinIndex(selectedSkin, cwd);
|
|
105
|
+
spinner.succeed(`Skin "${selectedSkin}" installed.`);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
spinner.fail("Install skin failed.");
|
|
109
|
+
console.error(e);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-antd-skin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "this is skin-cli for @adminui-dev/antd-layout",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "zhouwenqi",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-antd-skin": "./bin/index.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"create-antd-skin",
|
|
12
|
+
"antd-skin"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"templates"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/zhouwenqi/create-antd-skin.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://www.adminui.dev",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"bw": "tsc -w",
|
|
29
|
+
"dev": "ts-node src/index.ts",
|
|
30
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"chalk": "^4.1.2",
|
|
35
|
+
"commander": "^12.1.0",
|
|
36
|
+
"degit": "^2.8.4",
|
|
37
|
+
"execa": "^9.5.1",
|
|
38
|
+
"fs-extra": "^11.0.0",
|
|
39
|
+
"inquirer": "^9.2.15",
|
|
40
|
+
"ora": "^8.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/degit": "^2.8.6",
|
|
44
|
+
"@types/fs-extra": "^11.0.4",
|
|
45
|
+
"@types/inquirer": "^9.0.7",
|
|
46
|
+
"@types/node": "^20.14.0",
|
|
47
|
+
"@types/ora": "^3.2.0",
|
|
48
|
+
"ts-node": "^10.9.2",
|
|
49
|
+
"typescript": "^5.5.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
}
|
|
54
|
+
}
|