@minnai/create-aura-app 0.0.8 → 0.0.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/dist/scaffold.js +47 -15
- package/package.json +1 -1
package/dist/scaffold.js
CHANGED
|
@@ -10,23 +10,41 @@ const child_process_1 = require("child_process");
|
|
|
10
10
|
const colors_1 = require("kleur/colors");
|
|
11
11
|
async function scaffold(options) {
|
|
12
12
|
const { root, template, install, git, projectName } = options;
|
|
13
|
-
console.log((0, colors_1.dim)(
|
|
13
|
+
console.log((0, colors_1.dim)(`Scaffolding project in ${root}...`));
|
|
14
|
+
console.log((0, colors_1.dim)(`Current working directory: ${process.cwd()}`));
|
|
15
|
+
console.log((0, colors_1.dim)(`PATH: ${process.env.PATH?.substring(0, 100)}...`));
|
|
14
16
|
// Determine template path
|
|
15
|
-
// Assumes templates are in ../templates relative to dist/index.js
|
|
16
17
|
const templateDir = path_1.default.resolve(__dirname, '..', 'templates', template);
|
|
17
|
-
console.log((0, colors_1.dim)(`
|
|
18
|
+
console.log((0, colors_1.dim)(`Template source: ${templateDir}`));
|
|
18
19
|
if (!fs_extra_1.default.existsSync(templateDir)) {
|
|
20
|
+
console.error((0, colors_1.red)(`FATAL: Template source does not exist!`));
|
|
19
21
|
throw new Error(`Template "${template}" not found at ${templateDir}`);
|
|
20
22
|
}
|
|
23
|
+
// Ensure target directory exists
|
|
24
|
+
try {
|
|
25
|
+
fs_extra_1.default.ensureDirSync(root);
|
|
26
|
+
console.log((0, colors_1.dim)(`Confirmed target directory exists: ${root}`));
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.error((0, colors_1.red)(`Failed to create directory: ${e.message}`));
|
|
30
|
+
}
|
|
21
31
|
// Copy template files
|
|
22
32
|
try {
|
|
33
|
+
console.log((0, colors_1.dim)('Copying files...'));
|
|
23
34
|
await fs_extra_1.default.copy(templateDir, root, {
|
|
35
|
+
overwrite: true,
|
|
24
36
|
filter: (src) => {
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
const relative = path_1.default.relative(templateDir, src);
|
|
38
|
+
const parts = relative.split(path_1.default.sep);
|
|
39
|
+
return !parts.includes('node_modules') && !parts.includes('.git');
|
|
27
40
|
}
|
|
28
41
|
});
|
|
29
|
-
|
|
42
|
+
// Immediate verification
|
|
43
|
+
const files = fs_extra_1.default.readdirSync(root);
|
|
44
|
+
console.log((0, colors_1.dim)(`Copy complete. Files in target: ${files.join(', ')}`));
|
|
45
|
+
if (files.length === 0) {
|
|
46
|
+
console.error((0, colors_1.red)('WARNING: Target directory is empty after copy!'));
|
|
47
|
+
}
|
|
30
48
|
}
|
|
31
49
|
catch (e) {
|
|
32
50
|
console.error((0, colors_1.red)(`Failed to copy template: ${e.message}`));
|
|
@@ -34,33 +52,47 @@ async function scaffold(options) {
|
|
|
34
52
|
// Rename _gitignore to .gitignore
|
|
35
53
|
const gitignorePath = path_1.default.join(root, '_gitignore');
|
|
36
54
|
if (fs_extra_1.default.existsSync(gitignorePath)) {
|
|
37
|
-
await fs_extra_1.default.move(gitignorePath, path_1.default.join(root, '.gitignore'));
|
|
55
|
+
await fs_extra_1.default.move(gitignorePath, path_1.default.join(root, '.gitignore'), { overwrite: true });
|
|
56
|
+
console.log((0, colors_1.dim)('Restored .gitignore'));
|
|
38
57
|
}
|
|
39
58
|
// Update package.json name
|
|
40
59
|
const pkgPath = path_1.default.join(root, 'package.json');
|
|
41
60
|
if (fs_extra_1.default.existsSync(pkgPath)) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
try {
|
|
62
|
+
const pkg = await fs_extra_1.default.readJson(pkgPath);
|
|
63
|
+
pkg.name = projectName;
|
|
64
|
+
await fs_extra_1.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
65
|
+
console.log((0, colors_1.dim)(`Updated package.json name to ${projectName}`));
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
console.error((0, colors_1.red)(`Failed to update package.json: ${e.message}`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.warn((0, colors_1.yellow)(`Warning: No package.json found at ${pkgPath}`));
|
|
45
73
|
}
|
|
46
74
|
// Initialize Git
|
|
47
75
|
if (git) {
|
|
48
76
|
try {
|
|
49
77
|
console.log((0, colors_1.dim)('Initializing Git...'));
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(0, child_process_1.execSync)(
|
|
78
|
+
// Use full path to git if possible, or just rely on shell
|
|
79
|
+
const gitCmd = process.platform === 'win32' ? 'git' : 'git';
|
|
80
|
+
(0, child_process_1.execSync)(`${gitCmd} init`, { cwd: root, stdio: 'ignore', shell: true, env: process.env });
|
|
81
|
+
(0, child_process_1.execSync)(`${gitCmd} add -A`, { cwd: root, stdio: 'ignore', shell: true, env: process.env });
|
|
82
|
+
(0, child_process_1.execSync)(`${gitCmd} commit -m "Initial commit from create-aura-app"`, { cwd: root, stdio: 'ignore', shell: true, env: process.env });
|
|
53
83
|
console.log((0, colors_1.dim)('Initialized a git repository.'));
|
|
54
84
|
}
|
|
55
85
|
catch (e) {
|
|
56
|
-
console.warn((0, colors_1.
|
|
86
|
+
console.warn((0, colors_1.yellow)(`Git initialization skipped: ${e.message}`));
|
|
57
87
|
}
|
|
58
88
|
}
|
|
59
89
|
// Install dependencies
|
|
60
90
|
if (install) {
|
|
61
91
|
console.log((0, colors_1.dim)('Installing dependencies... This might take a moment.'));
|
|
62
92
|
try {
|
|
63
|
-
|
|
93
|
+
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
94
|
+
(0, child_process_1.execSync)(`${npmCmd} install`, { cwd: root, stdio: 'inherit', shell: true, env: process.env });
|
|
95
|
+
console.log((0, colors_1.green)('Dependencies installed successfully.'));
|
|
64
96
|
}
|
|
65
97
|
catch (e) {
|
|
66
98
|
console.error((0, colors_1.red)(`Dependency installation failed: ${e.message}`));
|