@pure-ds/create-app 0.5.10
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/create-app.js +96 -0
- package/package.json +24 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { mkdir, writeFile, access } from 'fs/promises';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
|
|
8
|
+
const CWD = process.cwd();
|
|
9
|
+
|
|
10
|
+
function log(message) {
|
|
11
|
+
console.log(message);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getNpmCommand() {
|
|
15
|
+
return process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function ensureDir(dirPath) {
|
|
19
|
+
await mkdir(dirPath, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveTargetDir() {
|
|
23
|
+
const arg = process.argv[2];
|
|
24
|
+
if (!arg || arg === '.' || arg === './') {
|
|
25
|
+
return CWD;
|
|
26
|
+
}
|
|
27
|
+
return path.resolve(CWD, arg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getProjectName(targetDir) {
|
|
31
|
+
return path.basename(targetDir).replace(/[^a-z0-9-]/gi, '-').toLowerCase() || 'pds-app';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function writePackageJson(targetDir) {
|
|
35
|
+
const pkgPath = path.join(targetDir, 'package.json');
|
|
36
|
+
try {
|
|
37
|
+
await access(pkgPath);
|
|
38
|
+
throw new Error('package.json already exists');
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err?.message === 'package.json already exists') {
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const pkg = {
|
|
46
|
+
name: getProjectName(targetDir),
|
|
47
|
+
private: true,
|
|
48
|
+
type: 'module',
|
|
49
|
+
scripts: {
|
|
50
|
+
dev: 'node esbuild-dev.js',
|
|
51
|
+
'pds:bootstrap': 'pds-bootstrap'
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
|
|
56
|
+
log(`✅ Created ${path.relative(CWD, pkgPath)}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function runCommand(command, args, cwd) {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
const child = spawn(command, args, {
|
|
62
|
+
cwd,
|
|
63
|
+
stdio: 'inherit',
|
|
64
|
+
shell: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
child.on('exit', (code) => {
|
|
68
|
+
if (code === 0) resolve();
|
|
69
|
+
else reject(new Error(`${command} ${args.join(' ')} failed (${code})`));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
log('\n✨ Create Pure Design System App\n');
|
|
76
|
+
|
|
77
|
+
const targetDir = resolveTargetDir();
|
|
78
|
+
if (!existsSync(targetDir)) {
|
|
79
|
+
await ensureDir(targetDir);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await writePackageJson(targetDir);
|
|
83
|
+
|
|
84
|
+
const npmCmd = getNpmCommand();
|
|
85
|
+
|
|
86
|
+
log('\n📦 Installing @pure-ds/core...');
|
|
87
|
+
await runCommand(npmCmd, ['install', '@pure-ds/core@latest'], targetDir);
|
|
88
|
+
|
|
89
|
+
log('\n⚡ Bootstrapping project...');
|
|
90
|
+
await runCommand(npmCmd, ['run', 'pds:bootstrap'], targetDir);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
main().catch((err) => {
|
|
94
|
+
console.error('❌ Create app failed:', err?.message || err);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pure-ds/create-app",
|
|
3
|
+
"version": "0.5.10",
|
|
4
|
+
"description": "Create a new Pure Design System app",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-app": "bin/create-app.js",
|
|
8
|
+
"create-pds-app": "bin/create-app.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pure-ds",
|
|
15
|
+
"design-system",
|
|
16
|
+
"create-app",
|
|
17
|
+
"starter"
|
|
18
|
+
],
|
|
19
|
+
"author": "Pure Design System",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
}
|
|
24
|
+
}
|