obsidian-plugin-config 1.1.7 → 1.1.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.
@@ -3,6 +3,7 @@
3
3
  /**
4
4
  * Obsidian Plugin Config - CLI Entry Point
5
5
  * Global command: obsidian-inject
6
+ * Version: 1.1.8
6
7
  */
7
8
 
8
9
  import { execSync } from 'child_process';
@@ -50,7 +51,7 @@ Pour plus d'informations: https://github.com/3C0D/obsidian-plugin-config
50
51
 
51
52
  function main() {
52
53
  const args = process.argv.slice(2);
53
-
54
+
54
55
  // Handle help flags
55
56
  if (args.includes('--help') || args.includes('-h')) {
56
57
  showHelp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obsidian-plugin-config",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Système d'injection pour plugins Obsidian autonomes",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -34,6 +34,7 @@
34
34
  "lint:fix": "eslint . --ext .ts --fix",
35
35
  "inject-path": "tsx scripts/inject-path.ts",
36
36
  "inject-prompt": "tsx scripts/inject-prompt.ts",
37
+ "inject": "tsx scripts/inject-prompt.ts",
37
38
  "check-plugin": "tsx scripts/inject-path.ts --dry-run",
38
39
  "build-npm": "tsx scripts/build-npm.ts",
39
40
  "publish-npm": "tsx scripts/build-npm.ts",
@@ -1,135 +1,284 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
3
  import fs from "fs";
4
+ import path from "path";
4
5
  import { execSync } from "child_process";
5
- import {
6
- askConfirmation,
7
- createReadlineInterface
8
- } from "./utils.js";
9
6
 
10
- const rl = createReadlineInterface();
7
+ /**
8
+ * Generate bin/obsidian-inject.js from template
9
+ */
10
+ async function generateBinFile(): Promise<void> {
11
+ console.log(`\n🔧 Generating bin/obsidian-inject.js...`);
12
+
13
+ const binDir = "bin";
14
+ const binPath = path.join(binDir, "obsidian-inject.js");
15
+
16
+ // Ensure bin directory exists
17
+ if (!fs.existsSync(binDir)) {
18
+ fs.mkdirSync(binDir, { recursive: true });
19
+ console.log(` 📁 Created ${binDir} directory`);
20
+ }
21
+
22
+ // Read package.json for version info
23
+ const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
24
+
25
+ const binContent = `#!/usr/bin/env node
11
26
 
12
27
  /**
13
- * Build NPM package from local development
28
+ * Obsidian Plugin Config - CLI Entry Point
29
+ * Global command: obsidian-inject
30
+ * Version: ${packageJson.version}
14
31
  */
15
- async function buildNpmPackage(): Promise<void> {
16
- console.log(`🏗️ Building NPM package from local development...`);
32
+
33
+ import { execSync } from 'child_process';
34
+ import { fileURLToPath } from 'url';
35
+ import { dirname, join, isAbsolute, resolve } from 'path';
36
+ import fs from 'fs';
37
+
38
+ // Get the directory of this script
39
+ const __filename = fileURLToPath(import.meta.url);
40
+ const __dirname = dirname(__filename);
41
+ const packageRoot = dirname(__dirname);
42
+
43
+ // Path to the injection script
44
+ const injectScriptPath = join(packageRoot, 'scripts', 'inject-path.ts');
45
+
46
+ function showHelp() {
47
+ console.log(\`
48
+ Obsidian Plugin Config - Global CLI
49
+ Système d'injection pour plugins Obsidian autonomes
50
+
51
+ UTILISATION:
52
+ obsidian-inject # Injection dans le répertoire courant
53
+ obsidian-inject <chemin> # Injection par chemin
54
+ obsidian-inject --help, -h # Afficher cette aide
55
+
56
+ EXEMPLES:
57
+ cd mon-plugin && obsidian-inject
58
+ obsidian-inject ../mon-autre-plugin
59
+ obsidian-inject "C:\\\\Users\\\\dev\\\\plugins\\\\mon-plugin"
60
+
61
+ CE QUI EST INJECTÉ:
62
+ ✅ Scripts locaux (esbuild.config.ts, acp.ts, utils.ts, etc.)
63
+ ✅ Configuration package.json (scripts, dépendances)
64
+ ✅ Protection yarn obligatoire
65
+ ✅ Installation automatique des dépendances
66
+
67
+ ARCHITECTURE:
68
+ - Plugin devient AUTONOME avec scripts locaux
69
+ - Aucune dépendance externe requise après injection
70
+ - Mise à jour possible via re-injection
71
+
72
+ Pour plus d'informations: https://github.com/3C0D/obsidian-plugin-config
73
+ \`);
74
+ }
75
+
76
+ function main() {
77
+ const args = process.argv.slice(2);
78
+
79
+ // Handle help flags
80
+ if (args.includes('--help') || args.includes('-h')) {
81
+ showHelp();
82
+ process.exit(0);
83
+ }
84
+
85
+ // Check if injection script exists
86
+ if (!fs.existsSync(injectScriptPath)) {
87
+ console.error(\`❌ Erreur: Script d'injection non trouvé à \${injectScriptPath}\`);
88
+ console.error(\` Vérifiez que obsidian-plugin-config est correctement installé.\`);
89
+ process.exit(1);
90
+ }
91
+
92
+ // Determine target path (resolve relative to user's current directory)
93
+ const userCwd = process.cwd();
94
+ let targetPath = args[0] || userCwd;
95
+
96
+ // If relative path, resolve from user's current directory
97
+ if (args[0] && !isAbsolute(args[0])) {
98
+ targetPath = resolve(userCwd, args[0]);
99
+ }
100
+
101
+ console.log(\`🎯 Obsidian Plugin Config - Injection Globale\`);
102
+ console.log(\`📁 Cible: \${targetPath}\`);
103
+ console.log(\`📦 Depuis: \${packageRoot}\\n\`);
17
104
 
18
105
  try {
19
- // Step 1: Verify all scripts are ready
20
- console.log(`\n📋 Verifying scripts...`);
21
-
22
- const requiredScripts = [
23
- "scripts/inject-path.ts",
24
- "scripts/inject-prompt.ts",
25
- "scripts/utils.ts",
26
- "scripts/esbuild.config.ts",
27
- "scripts/acp.ts",
28
- "scripts/update-version.ts",
29
- "scripts/release.ts",
30
- "scripts/help.ts"
31
- ];
32
-
33
- for (const script of requiredScripts) {
34
- if (!fs.existsSync(script)) {
35
- throw new Error(`Missing required script: ${script}`);
36
- }
37
- console.log(` ✅ ${script}`);
106
+ // Check if target directory has package.json
107
+ const targetPackageJson = join(targetPath, 'package.json');
108
+ if (!fs.existsSync(targetPackageJson)) {
109
+ console.error(\`❌ Erreur: package.json non trouvé dans \${targetPath}\`);
110
+ console.error(\` Assurez-vous que c'est un projet Node.js valide.\`);
111
+ process.exit(1);
38
112
  }
39
113
 
40
- // Step 2: Update bin/obsidian-inject.js if needed
41
- console.log(`\n📦 Checking bin/obsidian-inject.js...`);
42
- const binPath = "bin/obsidian-inject.js";
114
+ // Clean NPM artifacts if package-lock.json exists
115
+ const packageLockPath = join(targetPath, 'package-lock.json');
116
+ if (fs.existsSync(packageLockPath)) {
117
+ console.log(\`🧹 Installation NPM détectée, nettoyage...\`);
43
118
 
44
- if (fs.existsSync(binPath)) {
45
- console.log(` ✅ ${binPath} exists`);
46
- } else {
47
- throw new Error(`Missing bin file: ${binPath}`);
48
- }
119
+ try {
120
+ // Remove package-lock.json
121
+ fs.unlinkSync(packageLockPath);
122
+ console.log(\` 🗑️ package-lock.json supprimé\`);
123
+
124
+ // Remove node_modules if it exists
125
+ const nodeModulesPath = join(targetPath, 'node_modules');
126
+ if (fs.existsSync(nodeModulesPath)) {
127
+ fs.rmSync(nodeModulesPath, { recursive: true, force: true });
128
+ console.log(\` 🗑️ node_modules supprimé (sera réinstallé avec Yarn)\`);
129
+ }
49
130
 
50
- // Step 3: Verify package.json is ready for NPM
51
- console.log(`\n📄 Verifying package.json for NPM...`);
52
- const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
53
-
54
- const requiredFields = {
55
- name: packageJson.name,
56
- version: packageJson.version,
57
- description: packageJson.description,
58
- bin: packageJson.bin,
59
- repository: packageJson.repository,
60
- author: packageJson.author
61
- };
62
-
63
- for (const [field, value] of Object.entries(requiredFields)) {
64
- if (!value) {
65
- throw new Error(`Missing required package.json field: ${field}`);
131
+ console.log(\` ✅ Artefacts NPM nettoyés pour éviter les conflits Yarn\`);
132
+
133
+ } catch (cleanError) {
134
+ console.error(\` ❌ Échec du nettoyage:\`, cleanError.message);
135
+ console.log(\` 💡 Supprimez manuellement package-lock.json et node_modules\`);
66
136
  }
67
- console.log(` ✅ ${field}: ${typeof value === 'object' ? JSON.stringify(value) : value}`);
68
137
  }
69
138
 
70
- // Step 4: Check if we're logged into NPM
71
- console.log(`\n🔐 Checking NPM authentication...`);
139
+ // Check if tsx is available locally in target
140
+ let tsxCommand = 'npx tsx';
72
141
  try {
73
- const whoami = execSync('npm whoami', { encoding: 'utf8' }).trim();
74
- console.log(` ✅ Logged in as: ${whoami}`);
142
+ execSync('npx tsx --version', {
143
+ cwd: targetPath,
144
+ stdio: 'pipe'
145
+ });
146
+ console.log(\`✅ tsx disponible localement\`);
75
147
  } catch {
76
- console.log(` ❌ Not logged into NPM`);
77
- console.log(` 💡 Run: npm login`);
78
- throw new Error("NPM authentication required");
79
- }
148
+ console.log(\`⚠️ tsx non trouvé, installation en cours...\`);
80
149
 
81
- // Step 5: Run tests to ensure everything works
82
- console.log(`\n🧪 Running quick test...`);
83
- try {
84
- execSync('yarn build', { stdio: 'inherit' });
85
- console.log(` ✅ Build test passed`);
86
- } catch {
87
- throw new Error("Build test failed");
150
+ // Install tsx locally in target directory
151
+ try {
152
+ execSync('yarn add -D tsx', {
153
+ cwd: targetPath,
154
+ stdio: 'inherit'
155
+ });
156
+ console.log(\`✅ tsx installé avec succès\`);
157
+ } catch (installError) {
158
+ console.error(\`❌ Échec de l'installation de tsx:\`, installError.message);
159
+ console.error(\` Essayez d'installer tsx manuellement: cd "\${targetPath}" && yarn add -D tsx\`);
160
+ process.exit(1);
161
+ }
88
162
  }
89
163
 
90
- console.log(`\n✅ Package is ready for NPM publication!`);
164
+ // Execute the injection script with tsx
165
+ const command = \`npx tsx "\${injectScriptPath}" "\${targetPath}"\`;
91
166
 
92
- // Step 6: Ask for confirmation
93
- const shouldPublish = await askConfirmation(`\nProceed with NPM publication?`, rl);
167
+ execSync(command, {
168
+ stdio: 'inherit',
169
+ cwd: targetPath // Use target directory to ensure tsx is available
170
+ });
94
171
 
95
- if (!shouldPublish) {
96
- console.log(`❌ Publication cancelled`);
97
- return;
98
- }
172
+ console.log(\`\\n✅ Injection terminée avec succès !\`);
173
+
174
+ } catch (error) {
175
+ console.error(\`\\n❌ Erreur lors de l'injection:\`, error.message);
176
+ process.exit(1);
177
+ }
178
+ }
179
+
180
+ // Run the CLI
181
+ main();
182
+ `;
183
+
184
+ fs.writeFileSync(binPath, binContent, "utf8");
185
+ console.log(` ✅ Generated ${binPath}`);
186
+ }
187
+
188
+ /**
189
+ * Build and publish NPM package - Complete workflow
190
+ */
191
+ function buildAndPublishNpm(): void {
192
+ console.log(`🚀 Obsidian Plugin Config - NPM Build & Publish`);
193
+ console.log(`Complete workflow: exports → bin → verify → publish\n`);
194
+
195
+ try {
196
+ // Step 1: Update exports automatically
197
+ console.log(`📦 Step 1/4: Updating exports...`);
198
+ execSync('yarn update-exports', { stdio: 'inherit' });
199
+
200
+ // Step 2: Generate bin file
201
+ console.log(`\n🔧 Step 2/4: Generating bin/obsidian-inject.js...`);
202
+ generateBinFile();
203
+
204
+ // Step 3: Verify package is ready
205
+ console.log(`\n📋 Step 3/4: Verifying package...`);
206
+ verifyPackage();
99
207
 
100
- // Step 7: Publish to NPM
101
- console.log(`\n📤 Publishing to NPM...`);
102
- execSync('npm publish', { stdio: 'inherit' });
208
+ // Step 4: Publish to NPM
209
+ console.log(`\n📤 Step 4/4: Publishing to NPM...`);
210
+ execSync('npm publish --registry https://registry.npmjs.org/', { stdio: 'inherit' });
103
211
 
104
212
  console.log(`\n🎉 Package published successfully!`);
105
213
  console.log(`\n📋 Next steps:`);
106
- console.log(` 1. npm install -g ${packageJson.name}`);
107
- console.log(` 2. cd any-obsidian-plugin && obsidian-inject`);
108
- console.log(` 3. Test the global installation`);
214
+ console.log(` 1. npm install -g obsidian-plugin-config`);
215
+ console.log(` 2. Test injection: cd any-plugin && obsidian-inject`);
109
216
 
110
217
  } catch (error) {
111
218
  console.error(`\n❌ Build failed: ${error instanceof Error ? error.message : String(error)}`);
112
- throw error;
219
+ process.exit(1);
113
220
  }
114
221
  }
115
222
 
116
223
  /**
117
- * Main function
224
+ * Verify package is ready for publication
118
225
  */
119
- async function main(): Promise<void> {
120
- try {
121
- console.log(`🎯 Obsidian Plugin Config - NPM Package Builder`);
122
- console.log(`📦 Prepare and publish NPM package\n`);
226
+ function verifyPackage(): void {
227
+ // Check required scripts
228
+ const requiredScripts = [
229
+ "scripts/inject-path.ts",
230
+ "scripts/inject-prompt.ts",
231
+ "scripts/utils.ts",
232
+ "scripts/esbuild.config.ts",
233
+ "scripts/acp.ts",
234
+ "scripts/update-version-config.ts",
235
+ "scripts/help.ts"
236
+ ];
237
+
238
+ for (const script of requiredScripts) {
239
+ if (!fs.existsSync(script)) {
240
+ throw new Error(`Missing required script: ${script}`);
241
+ }
242
+ }
243
+ console.log(` ✅ All required scripts present`);
123
244
 
124
- await buildNpmPackage();
245
+ // Check package.json
246
+ const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
247
+ const requiredFields = ['name', 'version', 'description', 'bin', 'repository', 'author'];
125
248
 
126
- } catch (error) {
127
- console.error(`💥 Error: ${error instanceof Error ? error.message : String(error)}`);
128
- process.exit(1);
129
- } finally {
130
- rl.close();
249
+ for (const field of requiredFields) {
250
+ if (!packageJson[field]) {
251
+ throw new Error(`Missing required package.json field: ${field}`);
252
+ }
131
253
  }
254
+ console.log(` ✅ Package.json valid (v${packageJson.version})`);
255
+
256
+ // Check bin file exists
257
+ if (!fs.existsSync("bin/obsidian-inject.js")) {
258
+ throw new Error(`Missing bin file: bin/obsidian-inject.js`);
259
+ }
260
+ console.log(` ✅ Bin file ready`);
261
+
262
+ // Sync versions.json
263
+ const versionsPath = "versions.json";
264
+ let versions: Record<string, string> = {};
265
+
266
+ if (fs.existsSync(versionsPath)) {
267
+ versions = JSON.parse(fs.readFileSync(versionsPath, "utf8"));
268
+ }
269
+
270
+ if (!versions[packageJson.version]) {
271
+ versions[packageJson.version] = "1.8.9";
272
+ fs.writeFileSync(versionsPath, JSON.stringify(versions, null, "\t"), "utf8");
273
+ console.log(` ✅ Added version ${packageJson.version} to versions.json`);
274
+ } else {
275
+ console.log(` ✅ Version ${packageJson.version} in versions.json`);
276
+ }
277
+
278
+ // Quick build test
279
+ execSync('yarn build', { stdio: 'pipe' });
280
+ console.log(` ✅ Build test passed`);
132
281
  }
133
282
 
134
283
  // Run the script
135
- main().catch(console.error);
284
+ buildAndPublishNpm();
package/scripts/help.ts CHANGED
@@ -9,24 +9,27 @@ Injection system for autonomous Obsidian plugins
9
9
  📋 PLUGIN CONFIG COMMANDS
10
10
 
11
11
  DEVELOPMENT:
12
- yarn start # Install dependencies + update exports
13
- yarn build # Build the project
14
- yarn dev # Development build
15
- yarn real # Build to real vault
12
+ yarn start, i # Install dependencies + update exports
13
+ yarn update-exports, ue # Update package.json exports
14
+ yarn build # TypeScript check (no build needed)
15
+ yarn lint, lint:fix # ESLint verification/correction
16
16
 
17
17
  INJECTION:
18
- yarn inject-path <path> --yes # Automatic injection
19
- yarn inject-prompt <path> # Interactive injection with prompts
18
+ yarn inject-prompt <path> # Interactive injection (recommended)
19
+ yarn inject-path <path> --yes # Direct injection with auto-confirm
20
20
  yarn check-plugin <path> # Verification without injection
21
21
 
22
22
  GIT & VERSION:
23
- yarn acp # Add, commit, push
23
+ yarn acp # Add, commit, push (with Git sync)
24
24
  yarn bacp # Build + add, commit, push
25
- yarn v, update-version # Update version
25
+ yarn v, update-version # Update version (package.json + versions.json)
26
26
 
27
27
  NPM PUBLISHING:
28
- yarn build-npm # Build NPM package
29
- yarn publish-npm # Publish to NPM
28
+ yarn build-npm # Build + publish NPM package
29
+ yarn publish-npm # Alias for build-npm
30
+
31
+ HELP:
32
+ yarn run help, h # This help
30
33
 
31
34
  ═══════════════════════════════════════════════════════════════════
32
35
 
@@ -45,5 +48,17 @@ Usage:
45
48
 
46
49
  ═══════════════════════════════════════════════════════════════════
47
50
 
51
+ 🚀 COMPLETE WORKFLOW (Development → NPM)
52
+
53
+ 1. Make changes to obsidian-plugin-config
54
+ 2. yarn lint:fix # Fix any linting issues
55
+ 3. yarn v # Update version (package.json + versions.json)
56
+ 4. yarn bacp # Commit and push to GitHub
57
+ 5. yarn build-npm # Build and publish to NPM
58
+ 6. npm install -g obsidian-plugin-config # Update global package
59
+ 7. Test injection on target plugins
60
+
61
+ ═══════════════════════════════════════════════════════════════════
62
+
48
63
  `);
49
64
 
package/versions.json CHANGED
@@ -11,5 +11,6 @@
11
11
  "1.0.9": "1.8.9",
12
12
  "1.0.10": "1.8.9",
13
13
  "1.1.6": "1.8.9",
14
- "1.1.7": "1.8.9"
14
+ "1.1.7": "1.8.9",
15
+ "1.1.8": "1.8.9"
15
16
  }
@@ -1,104 +0,0 @@
1
- import {
2
- writeFile,
3
- stat
4
- } from "fs/promises";
5
- import { execSync } from "child_process";
6
- import dedent from "dedent";
7
- import {
8
- askConfirmation,
9
- createReadlineInterface,
10
- ensureGitSync
11
- } from "./utils.js";
12
-
13
- const rl = createReadlineInterface();
14
-
15
- const body = ".github/workflows/release-body.md";
16
-
17
- async function checkOrCreateFile(filename: string): Promise<void> {
18
- try {
19
- await stat(filename);
20
- } catch {
21
- console.log(`Creating ${filename} because it doesn't exist. Avoid deleting it.`);
22
- await writeFile(filename, "");
23
- }
24
- }
25
-
26
- async function createReleaseNotesFile(tagMessage: string, tag: string): Promise<void> {
27
- await writeFile(body, tagMessage);
28
- console.log(`Release notes for tag ${tag} have been written to release-body.md`);
29
- }
30
-
31
- async function handleExistingTag(tag: string): Promise<boolean> {
32
- const confirmed = await askConfirmation(`Tag ${tag} already exists. Do you want to replace it?`, rl);
33
-
34
- if (!confirmed) {
35
- console.log("Operation aborted");
36
- return false;
37
- }
38
-
39
- execSync(`git tag -d ${tag}`);
40
- execSync(`git push origin :refs/tags/${tag}`);
41
- console.log(`Deleted existing tag ${tag} locally and remotely.`);
42
- return true;
43
- }
44
-
45
- async function createTag(): Promise<void> {
46
- const currentVersion = process.env.npm_package_version;
47
- const tag = `${currentVersion}`;
48
-
49
- await checkOrCreateFile(body);
50
- const exists = execSync("git ls-remote --tags origin").toString().includes(`refs/tags/${tag}`);
51
-
52
- if (exists && !(await handleExistingTag(tag))) {
53
- rl.close();
54
- return;
55
- }
56
- await doCommit(currentVersion, tag);
57
- }
58
-
59
-
60
-
61
- async function doCommit(currentVersion: string | undefined, tag: string): Promise<void> {
62
- rl.question(`Enter the commit message for version ${currentVersion}: `, async (message) => {
63
- doNextSteps(message, tag);
64
- rl.close();
65
- });
66
- }
67
-
68
- async function doNextSteps(message: string, tag: string): Promise<void> {
69
- const messages = message.split("\\n");
70
- const toShow = message.replace(/\\n/g, "\n");
71
- await createReleaseNotesFile(toShow, tag);
72
- const tagMessage = messages.map(m => `-m "${m}"`).join(" ");
73
-
74
- try {
75
- execSync("git add -A");
76
- execSync("git commit -m \"update tag description\"");
77
-
78
- // Ensure Git is synchronized before pushing
79
- await ensureGitSync();
80
-
81
- execSync("git push");
82
- } catch (error: any) {
83
- console.error("Error:", error.message);
84
- }
85
- try {
86
- execSync(`git tag -a ${tag} ${tagMessage}`);
87
- } catch {
88
- execSync(`git tag -d ${tag}`);
89
- execSync(`git push origin :refs/tags/${tag}`);
90
- console.log("Fixed");
91
- execSync(`git tag -a ${tag} ${tagMessage}`);
92
- }
93
- // Ensure Git is synchronized before pushing tag
94
- await ensureGitSync();
95
-
96
- execSync(`git push origin ${tag}`);
97
- console.log(`Release ${tag} pushed to repo.`);
98
- console.log(dedent`
99
- with message:
100
- ${toShow}
101
- `);
102
- }
103
-
104
- createTag().catch(console.error);
@@ -1,105 +0,0 @@
1
- import { readFile, writeFile } from "fs/promises";
2
- import dedent from "dedent";
3
- import { inc, valid } from "semver";
4
- import { askQuestion, createReadlineInterface, gitExec, ensureGitSync } from "./utils.js";
5
-
6
- const rl = createReadlineInterface();
7
-
8
- async function getTargetVersion(currentVersion: string): Promise<string> {
9
- const updateType = await askQuestion(dedent`
10
- Current version: ${currentVersion}
11
- Kind of update:
12
- patch(1.0.1) -> type 1 or p
13
- minor(1.1.0) -> type 2 or min
14
- major(2.0.0) -> type 3 or maj
15
- or version number (e.g. 2.0.0)
16
- Enter choice: `, rl);
17
-
18
- switch (updateType.trim()) {
19
- case "p":
20
- case "1":
21
- return inc(currentVersion, "patch") || "";
22
- case "min":
23
- case "2":
24
- return inc(currentVersion, "minor") || "";
25
- case "maj":
26
- case "3":
27
- return inc(currentVersion, "major") || "";
28
- default:
29
- return valid(updateType.trim()) || "";
30
- }
31
- }
32
-
33
- async function updateJsonFile(filename: string, updateFn: (json: any) => void): Promise<void> {
34
- try {
35
- const content = JSON.parse(await readFile(filename, "utf8"));
36
- updateFn(content);
37
- await writeFile(filename, JSON.stringify(content, null, "\t"));
38
- } catch (error) {
39
- console.error(`Error updating ${filename}:`, error instanceof Error ? error.message : String(error));
40
- throw error;
41
- }
42
- }
43
-
44
- async function updateManifestVersions(targetVersion: string): Promise<void> {
45
- try {
46
- const manifest = JSON.parse(await readFile("manifest.json", "utf8"));
47
- const { minAppVersion } = manifest;
48
-
49
- await Promise.all([
50
- updateJsonFile("manifest.json", json => json.version = targetVersion),
51
- updateJsonFile("versions.json", json => json[targetVersion] = minAppVersion),
52
- updateJsonFile("package.json", json => json.version = targetVersion),
53
- // updateJsonFile("package-lock.json", json => json.version = targetVersion)
54
- ]);
55
- } catch (error) {
56
- console.error("Error updating manifest versions:", error instanceof Error ? error.message : String(error));
57
- throw error;
58
- }
59
- }
60
-
61
- async function updateVersion(): Promise<void> {
62
- try {
63
- const currentVersion = process.env.npm_package_version || "1.0.0";
64
- const targetVersion = await getTargetVersion(currentVersion);
65
-
66
- if (!targetVersion) {
67
- console.log("Invalid version");
68
- return;
69
- }
70
-
71
- try {
72
- // Update all files first
73
- await updateManifestVersions(targetVersion);
74
- console.log(`Files updated to version ${targetVersion}`);
75
-
76
- // Add files to git
77
- gitExec("git add manifest.json package.json versions.json");
78
- gitExec(`git commit -m "Updated to version ${targetVersion}"`);
79
- console.log("Changes committed");
80
- } catch (error) {
81
- console.error("Error during update or commit:", error instanceof Error ? error.message : String(error));
82
- console.log("Operation failed.");
83
- return;
84
- }
85
-
86
- try {
87
- // Ensure Git is synchronized before pushing
88
- await ensureGitSync();
89
-
90
- gitExec("git push");
91
- console.log(`Version successfully updated to ${targetVersion} and pushed.`);
92
- } catch (pushError) {
93
- console.error("Failed to push version update:", pushError instanceof Error ? pushError.message : String(pushError));
94
- }
95
- } catch (error) {
96
- console.error("Error:", error instanceof Error ? error.message : String(error));
97
- } finally {
98
- rl.close();
99
- }
100
- }
101
-
102
- updateVersion().catch(console.error).finally(() => {
103
- console.log("Exiting...");
104
- process.exit();
105
- });