-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.ts
More file actions
43 lines (37 loc) · 1.34 KB
/
Copy pathbuild.ts
File metadata and controls
43 lines (37 loc) · 1.34 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
import {parseArgs} from "@std/cli";
// Run a command in a subprocess, with inherited stdio.
async function run(command: string, args: string[], cwd?: string) {
const cmd = new Deno.Command(command, {
args: args,
cwd: cwd,
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit'
});
return await cmd.spawn().status;
}
// Publish core package to npm.
async function publishCoreToNpm() {
const name = JSON.parse(await Deno.readTextFile('deno.json')).name.replace(/^@nodef\//, '');
console.log(`Publishing the ${name} package to npm...`);
await run('deno', ['pack', '--output', `${name}.tgz`, '--allow-dirty']);
Deno.mkdirSync('.temp-pack', {recursive: true});
await run('tar', ['-xzf', `${name}.tgz`, '-C', '.temp-pack']);
Deno.removeSync(`${name}.tgz`);
const meta = JSON.parse(await Deno.readTextFile('.temp-pack/package/package.json'));
meta.name = name;
await Deno.writeTextFile('.temp-pack/package/package.json', JSON.stringify(meta, null, 2));
await run('npm', ['publish', '--access', 'public'], '.temp-pack/package');
await Deno.remove('.temp-pack', {recursive: true});
}
// Main function, of course.
async function main() {
const args = parseArgs(Deno.args, {
boolean: ['publish-core'],
default: {'publish-core': false}
});
if (args['publish-core']) {
await publishCoreToNpm();
}
}
main();