-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (33 loc) · 1.34 KB
/
index.js
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
import { execSync } from 'node:child_process';
import { readFileSync, rmSync, writeFileSync } from 'node:fs';
import { argv, exit } from 'node:process';
const isBump = argv[2] === '--bump';
if (isBump) {
execSync('git checkout main');
execSync('git fetch origin');
execSync('git reset --hard origin/main');
}
const response = await fetch('https://unpkg.com/sv/README.md');
if (!response.ok || !response.redirected) exit(1);
const version = response.url.replace('https://unpkg.com/sv@', '').split('/')[0];
rmSync('./javascript', { recursive: true, force: true });
rmSync('./typescript', { recursive: true, force: true });
// prettier-ignore
execSync('pnpm dlx sv create --template minimal --no-install --no-add-ons --types jsdoc javascript');
execSync('pnpm dlx sv add --no-preconditions --no-install --cwd javascript eslint prettier');
// prettier-ignore
execSync('pnpm dlx sv create --template minimal --no-install --no-add-ons --types ts typescript');
execSync('pnpm dlx sv add --no-preconditions --no-install --cwd typescript eslint prettier');
writeFileSync(
'README.md',
readFileSync('README.md', { encoding: 'utf-8' }).replace(
/sv@[\d\.]+\d/, //
`sv@${version}`,
),
);
if (isBump) {
execSync('git add .');
execSync(`pnpm version ${version} -m "sv@${version}" --force`, { stdio: 'inherit' });
execSync('git push');
execSync('git push --tags');
}