create-vault-cms 1.0.1 → 1.0.3

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.
Files changed (3) hide show
  1. package/README.md +0 -1
  2. package/package.json +3 -3
  3. package/src/cli.js +53 -21
package/README.md CHANGED
@@ -68,6 +68,5 @@ If you are not using the CLI, add the following to your Astro project's `.gitign
68
68
  # Obsidian
69
69
  .obsidian/workspace.json
70
70
  .obsidian/workspace-mobile.json
71
- .ref/
72
71
  ```
73
72
  This prevents conflicts between multiple devices and keeps your vault clean.
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "create-vault-cms",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Installer for Vault CMS",
5
5
  "main": "src/cli.js",
6
6
  "bin": {
7
- "create-vault-cms": "src/cli.js",
8
- "create-vaultcms": "src/cli.js"
7
+ "create-vault-cms": "src/cli.js"
9
8
  },
10
9
  "files": [
11
10
  "src",
@@ -28,6 +27,7 @@
28
27
  },
29
28
  "homepage": "https://github.com/davidvkimball/vault-cms#readme",
30
29
  "dependencies": {
30
+ "adm-zip": "^0.5.16",
31
31
  "commander": "^14.0.2",
32
32
  "fs-extra": "^11.3.3"
33
33
  }
package/src/cli.js CHANGED
@@ -3,56 +3,67 @@
3
3
  const { Command } = require('commander');
4
4
  const fs = require('fs-extra');
5
5
  const path = require('path');
6
- const { execSync } = require('child_process');
6
+ const https = require('https');
7
+ const AdmZip = require('adm-zip');
8
+
9
+ // Read version from package.json
10
+ const pkg = require('../package.json');
7
11
 
8
12
  const program = new Command();
9
13
 
10
14
  program
11
15
  .name('create-vault-cms')
12
16
  .description('Official installer for Vault CMS')
13
- .version('1.0.1');
17
+ .version(pkg.version);
14
18
 
15
19
  program
16
20
  .argument('[target]', 'target directory', '.')
17
21
  .option('-t, --template <name>', 'template to use (from vault-cms-presets)')
18
22
  .action(async (target, options) => {
19
23
  const targetDir = path.resolve(target);
20
- const tempDir = path.join(targetDir, '.vault-cms-temp');
24
+ const tempZip = path.join(targetDir, 'vault-cms-temp.zip');
25
+ const extractDir = path.join(targetDir, '.vault-cms-temp-extract');
21
26
 
22
- const repoUrl = options.template
23
- ? 'https://github.com/davidvkimball/vault-cms-presets.git'
24
- : 'https://github.com/davidvkimball/vault-cms.git';
27
+ const repoName = options.template ? 'vault-cms-presets' : 'vault-cms';
28
+ const zipUrl = `https://github.com/davidvkimball/${repoName}/archive/refs/heads/master.zip`;
25
29
 
26
30
  console.log(`šŸš€ Installing Vault CMS${options.template ? ` (template: ${options.template})` : ''}...`);
27
31
 
28
32
  try {
29
- // 1. Download
30
- console.log(' šŸ“¦ Downloading files...');
31
- execSync(`git clone --depth 1 ${repoUrl} "${tempDir}"`, { stdio: 'ignore' });
33
+ // 1. Create target directory
34
+ await fs.ensureDir(targetDir);
35
+
36
+ // 2. Download ZIP
37
+ console.log(' šŸ“¦ Downloading archive...');
38
+ await downloadFile(zipUrl, tempZip);
39
+
40
+ // 3. Extract ZIP
41
+ console.log(' šŸ“‚ Extracting files...');
42
+ const zip = new AdmZip(tempZip);
43
+ zip.extractAllTo(extractDir, true);
44
+
45
+ // 4. Identify the inner folder (GitHub zips wrap content in a folder named repo-branch)
46
+ const folders = await fs.readdir(extractDir);
47
+ const innerFolder = path.join(extractDir, folders[0]);
48
+ const sourcePath = options.template ? path.join(innerFolder, options.template) : innerFolder;
32
49
 
33
- // 2. Determine source path
34
- const sourcePath = options.template ? path.join(tempDir, options.template) : tempDir;
35
-
36
50
  if (!(await fs.pathExists(sourcePath))) {
37
51
  throw new Error(`Template "${options.template}" not found in presets repository.`);
38
52
  }
39
53
 
40
- // 3. Define what to keep
54
+ // 5. Move selected files
41
55
  const toKeep = ['_bases', '.obsidian', 'README.md'];
42
-
43
- // 4. Move selected files
44
- await fs.ensureDir(targetDir);
45
56
  for (const item of toKeep) {
46
57
  const src = path.join(sourcePath, item);
47
58
  const dest = path.join(targetDir, item);
48
59
 
49
60
  if (await fs.pathExists(src)) {
50
- await fs.copy(src, dest);
61
+ await fs.copy(src, dest, { overwrite: true });
51
62
  console.log(` āœ“ Added ${item}`);
52
63
  }
53
64
  }
54
65
 
55
- // 5. Update .gitignore
66
+ // 6. Handle .gitignore
56
67
  const gitignorePath = path.join(targetDir, '.gitignore');
57
68
  const ignores = '\n# Vault CMS / Obsidian\n.obsidian/workspace.json\n.obsidian/workspace-mobile.json\n.ref/\n';
58
69
 
@@ -67,15 +78,36 @@ program
67
78
  console.log(' āœ“ Created .gitignore');
68
79
  }
69
80
 
70
- // 6. Cleanup
71
- await fs.remove(tempDir);
81
+ // 7. Cleanup
82
+ await fs.remove(tempZip);
83
+ await fs.remove(extractDir);
72
84
 
73
85
  console.log('\n✨ Vault CMS is ready!');
74
86
  } catch (err) {
75
87
  console.error('\nāŒ Installation failed:', err.message);
76
- if (await fs.pathExists(tempDir)) await fs.remove(tempDir);
88
+ if (await fs.pathExists(tempZip)) await fs.remove(tempZip);
89
+ if (await fs.pathExists(extractDir)) await fs.remove(extractDir);
77
90
  process.exit(1);
78
91
  }
79
92
  });
80
93
 
94
+ function downloadFile(url, dest) {
95
+ return new Promise((resolve, reject) => {
96
+ https.get(url, (res) => {
97
+ if (res.statusCode === 301 || res.statusCode === 302) {
98
+ return downloadFile(res.headers.location, dest).then(resolve).catch(reject);
99
+ }
100
+ if (res.statusCode !== 200) {
101
+ return reject(new Error(`Failed to download: ${res.statusCode}`));
102
+ }
103
+ const file = fs.createWriteStream(dest);
104
+ res.pipe(file);
105
+ file.on('finish', () => {
106
+ file.close();
107
+ resolve();
108
+ });
109
+ }).on('error', reject);
110
+ });
111
+ }
112
+
81
113
  program.parse();