-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.js
51 lines (45 loc) · 1.83 KB
/
package.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
45
46
47
48
49
50
51
const fs = require('fs-extra');
const pathlib = require('path');
const { promisify } = require('util');
const zipDir = require('zip-dir');
const { yarnToNpm } = require('synp');
if(!__dirname.length) {
throw new Error("Bad __dirname");
}
const distDir = pathlib.join(__dirname, 'dist');
const rootPackageDir = pathlib.join(__dirname, 'package');
const packageDir = pathlib.join(rootPackageDir, 'serial-bridge');
(async () => {
console.log('Generating package directory with the proper runtime layout');
await fs.remove(rootPackageDir);
await fs.mkdirp(packageDir);
await Promise.all([
// Copy dist/client to package/client
fs.copy(pathlib.join(distDir, 'client'), pathlib.join(packageDir, 'client'), {
filter(src, dest) {
// Don't copy map files
return !src.endsWith('.map');
}
}),
// Copy dist/server/* to package/*
fs.copy(pathlib.join(distDir, 'server'), packageDir),
// Copy sample config file
fs.copy('config.example', pathlib.join(packageDir, 'config.example')),
// Generate package.json containing just the dependencies field from the real package.json
(async () => {
const basePackageJson = JSON.parse(await fs.readFile('package.json', { encoding: 'utf8' }));
const deployPackageJson = {
dependencies: basePackageJson.dependencies,
}
await fs.writeFile(pathlib.join(packageDir, 'package.json'), JSON.stringify(deployPackageJson, undefined, '\t') + '\n');
})(),
// Convert yarn.lock to package-lock.json
fs.writeFile(pathlib.join(packageDir, 'package-lock.json'), yarnToNpm(__dirname)),
// Generate .npmrc to silence warnings about the incomplete package.json
fs.writeFile(pathlib.join(packageDir, '.npmrc'), "loglevel=error\n"),
]);
console.log('Generating zip file');
await promisify(zipDir)(rootPackageDir, {
saveTo: pathlib.join(__dirname, 'serial-bridge.zip'),
});
})().catch(console.error);