-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildPack.js
44 lines (35 loc) · 1.21 KB
/
buildPack.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
43
44
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const os = require('os');
const exec = require('child_process').execSync;
// create temp directory
const tempDirectory = fs.mkdtempSync(`${os.tmpdir()}/your-project-tarball-`);
const packageDirectory = `${tempDirectory}/package`;
// create subfolder package
fs.mkdirSync(packageDirectory);
// get current directory
const currentDirectory = exec('pwd')
.toString()
.replace(/(\r\n|\n|\r)/gm, '')
.trim();
// clean output folder
exec(`npx rimraf out/*`);
// read existing package.json
const packageJSON = require('./package.json');
// copy all necessary files
exec(`copyfiles README.md CHANGELOG.md LICENSE ${packageDirectory}`);
exec(`copyfiles -u 1 "dist/**/*" ${packageDirectory}`);
// modify package.json
Reflect.deleteProperty(packageJSON, 'scripts');
Reflect.deleteProperty(packageJSON, 'devDependencies');
// and save it in temp folder
fs.writeFileSync(
`${packageDirectory}/package.json`,
JSON.stringify(packageJSON, null, 2),
);
// pack everything and send to out folder
exec(
`cd ${packageDirectory} && yarn pack --out %s-%v.tgz && npx copyfiles *.tgz ${currentDirectory}/out`,
);
// clean after
exec(`npx rimraf ${tempDirectory}`);