-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathversion-bump.mjs
More file actions
109 lines (94 loc) · 3.25 KB
/
Copy pathversion-bump.mjs
File metadata and controls
109 lines (94 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { execSync } from 'child_process';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const isPreflight = process.argv.includes('--preflight');
const targetVersion = process.env.npm_package_version;
// ── Pre-flight checks ──
try {
execSync(
'npx eslint . --rule \'no-console: ["error", {"allow": ["warn","error","debug"]}]\'',
{ stdio: 'inherit' }
);
} catch {
console.error(
'\n⚠ ESLint failed. Fix lint errors (or ungated console.log) before releasing.\n'
);
process.exit(1);
}
if (isPreflight) process.exit(0);
if (!targetVersion) {
console.error('npm_package_version is not set. Run via npm version.');
process.exit(1);
}
// ── Sync shared docs ──
const __dirname = dirname(fileURLToPath(import.meta.url));
const knowledgeDir = join(__dirname, '..', 'knowledge');
const sharedDocs = ['release-guide.md'];
for (const doc of sharedDocs) {
const src = join(knowledgeDir, doc);
if (existsSync(src)) {
const dest = join('docs', doc);
writeFileSync(dest, readFileSync(src, 'utf8'));
execSync(`git add "${dest}"`, { stdio: 'inherit' });
console.log(`Synced ${doc} from knowledge/`);
} else {
console.warn(`Skipping ${doc}: not found at ${src}`);
}
}
try {
execSync('npm outdated eslint-plugin-obsidianmd --json', {
encoding: 'utf8',
});
} catch (err) {
let info;
try {
info = JSON.parse(err.stdout)['eslint-plugin-obsidianmd'];
} catch {}
if (info) {
console.log(
`\nUpdating eslint-plugin-obsidianmd: ${info.current} → ${info.latest}`
);
execSync('npm update eslint-plugin-obsidianmd', { stdio: 'inherit' });
execSync('git add package.json', { stdio: 'inherit' });
try {
execSync('npx eslint .', { stdio: 'inherit' });
console.log('ESLint passed with updated plugin\n');
} catch {
console.error(
'\n⚠ ESLint failed after updating eslint-plugin-obsidianmd. Fix lint errors before releasing.\n'
);
process.exit(1);
}
}
}
// ── Side effects ──
try {
execSync('git fetch origin', { stdio: 'inherit' });
const files = execSync('git ls-tree --name-only origin/main', {
encoding: 'utf8',
})
.split('\n')
.filter((f) => f.startsWith('README'));
for (const file of files) {
execSync(`git checkout origin/main -- ${file}`, { stdio: 'inherit' });
console.log(`Updated ${file} from GitHub`);
}
} catch {
console.warn('Could not fetch README files from GitHub');
}
let manifest = JSON.parse(readFileSync('manifest.json', 'utf8'));
manifest.version = targetVersion;
writeFileSync('manifest.json', JSON.stringify(manifest, null, '\t') + '\n');
execSync('git add manifest.json', { stdio: 'inherit' });
let versions = existsSync('versions.json')
? JSON.parse(readFileSync('versions.json', 'utf8'))
: {};
const lastMinVersion = Object.values(versions).pop();
if (lastMinVersion !== manifest.minAppVersion) {
versions[targetVersion] = manifest.minAppVersion;
writeFileSync('versions.json', JSON.stringify(versions, null, '\t') + '\n');
execSync('git add versions.json', { stdio: 'inherit' });
console.log(`Updated versions.json for ${targetVersion}`);
}
console.log(`Updated manifest.json to version ${targetVersion}`);