create-vault-cms 1.0.7 ā 1.0.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/package.json +2 -2
- package/src/cli.js +37 -15
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ program
|
|
|
24
24
|
console.log('š Initializing Vault CMS Installer...');
|
|
25
25
|
|
|
26
26
|
const availableTemplates = await fetchTemplates();
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
let template = options.template;
|
|
29
29
|
let targetPath = target;
|
|
30
30
|
|
|
@@ -67,11 +67,12 @@ program
|
|
|
67
67
|
const targetDir = path.resolve(targetPath);
|
|
68
68
|
const tempZip = path.join(targetDir, 'vault-cms-temp.zip');
|
|
69
69
|
const extractDir = path.join(targetDir, '.vault-cms-temp-extract');
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
const repoName = template ? 'vault-cms-presets' : 'vault-cms';
|
|
72
72
|
const zipUrl = `https://github.com/davidvkimball/${repoName}/archive/refs/heads/master.zip`;
|
|
73
73
|
|
|
74
74
|
console.log(`\nš Installing Vault CMS${template ? ` (template: ${template})` : ''}...`);
|
|
75
|
+
console.log(` š Target directory: ${targetDir}`);
|
|
75
76
|
|
|
76
77
|
await fs.ensureDir(targetDir);
|
|
77
78
|
|
|
@@ -82,7 +83,13 @@ program
|
|
|
82
83
|
const zip = new AdmZip(tempZip);
|
|
83
84
|
zip.extractAllTo(extractDir, true);
|
|
84
85
|
|
|
85
|
-
const
|
|
86
|
+
const items = await fs.readdir(extractDir);
|
|
87
|
+
const folders = items.filter(item => fs.statSync(path.join(extractDir, item)).isDirectory());
|
|
88
|
+
|
|
89
|
+
if (folders.length === 0) {
|
|
90
|
+
throw new Error('Could not find content in the downloaded archive.');
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
const innerFolder = path.join(extractDir, folders[0]);
|
|
87
94
|
const sourcePath = template ? path.join(innerFolder, template) : innerFolder;
|
|
88
95
|
|
|
@@ -94,7 +101,7 @@ program
|
|
|
94
101
|
for (const item of toKeep) {
|
|
95
102
|
const src = path.join(sourcePath, item);
|
|
96
103
|
const dest = path.join(targetDir, item);
|
|
97
|
-
|
|
104
|
+
|
|
98
105
|
if (await fs.pathExists(src)) {
|
|
99
106
|
await fs.copy(src, dest, { overwrite: true });
|
|
100
107
|
console.log(` ā Added ${item}`);
|
|
@@ -105,21 +112,30 @@ program
|
|
|
105
112
|
const projectRoot = await findProjectRoot(targetDir);
|
|
106
113
|
const gitignorePath = path.join(projectRoot, '.gitignore');
|
|
107
114
|
const ignores = '\n# Vault CMS / Obsidian\n.obsidian/workspace.json\n.obsidian/workspace-mobile.json\n.ref/\n';
|
|
108
|
-
|
|
115
|
+
|
|
116
|
+
const isExternalRoot = projectRoot !== targetDir && !targetDir.startsWith(projectRoot);
|
|
117
|
+
|
|
109
118
|
if (await fs.pathExists(gitignorePath)) {
|
|
110
119
|
const content = await fs.readFile(gitignorePath, 'utf8');
|
|
111
120
|
if (!content.includes('.obsidian/workspace.json')) {
|
|
112
121
|
await fs.appendFile(gitignorePath, ignores);
|
|
113
122
|
console.log(` ā Updated .gitignore at ${path.relative(process.cwd(), gitignorePath)}`);
|
|
114
123
|
}
|
|
115
|
-
} else {
|
|
124
|
+
} else if (!isExternalRoot) {
|
|
116
125
|
await fs.writeFile(gitignorePath, ignores.trim() + '\n');
|
|
117
126
|
console.log(` ā Created .gitignore at ${path.relative(process.cwd(), gitignorePath)}`);
|
|
127
|
+
} else {
|
|
128
|
+
console.log(` ā ļø Skipped .gitignore (could not find a safe project root)`);
|
|
118
129
|
}
|
|
119
130
|
|
|
120
131
|
await fs.remove(tempZip);
|
|
121
132
|
await fs.remove(extractDir);
|
|
122
133
|
|
|
134
|
+
if (projectRoot === targetDir) {
|
|
135
|
+
console.log('\n ā ļø Note: No Astro project or package.json found in parent directories.');
|
|
136
|
+
console.log(' Installation completed, but you may need to move these files into your content folder manually.');
|
|
137
|
+
}
|
|
138
|
+
|
|
123
139
|
console.log('\n⨠Vault CMS is ready!');
|
|
124
140
|
process.exit(0);
|
|
125
141
|
} catch (err) {
|
|
@@ -129,14 +145,20 @@ program
|
|
|
129
145
|
});
|
|
130
146
|
|
|
131
147
|
async function findProjectRoot(startDir) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
let current = startDir;
|
|
149
|
+
// Look up to 6 levels up for a project root (Astro config, package.json, or .git)
|
|
150
|
+
let depth = 0;
|
|
151
|
+
while (current !== path.parse(current).root && depth < 6) {
|
|
152
|
+
const hasPkg = await fs.pathExists(path.join(current, 'package.json'));
|
|
153
|
+
const hasAstro = await fs.pathExists(path.join(current, 'astro.config.mjs')) || await fs.pathExists(path.join(current, 'astro.config.ts'));
|
|
154
|
+
const hasGit = await fs.pathExists(path.join(current, '.git'));
|
|
155
|
+
|
|
156
|
+
if (hasPkg || hasAstro || hasGit) return current;
|
|
157
|
+
|
|
158
|
+
current = path.dirname(current);
|
|
159
|
+
depth++;
|
|
160
|
+
}
|
|
161
|
+
return startDir; // Fallback to target dir
|
|
140
162
|
}
|
|
141
163
|
|
|
142
164
|
function downloadFile(url, dest) {
|
|
@@ -172,7 +194,7 @@ function fetchTemplates() {
|
|
|
172
194
|
.map(item => item.name);
|
|
173
195
|
resolve(dirs);
|
|
174
196
|
} catch (e) {
|
|
175
|
-
resolve(['starlight', 'slate', 'chiri']);
|
|
197
|
+
resolve(['starlight', 'slate', 'chiri']);
|
|
176
198
|
}
|
|
177
199
|
});
|
|
178
200
|
}).on('error', () => resolve(['starlight', 'slate', 'chiri']));
|