-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathbuild-packages.js
executable file
·70 lines (59 loc) · 1.61 KB
/
build-packages.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
const {join: pathJoin} = require('path')
const {cpSync, writeFileSync} = require('fs')
const basePkg = require('./package.json')
const PACKAGES = [
'ffmpeg-static',
'ffprobe-static',
]
const copyFileIntoPackage = (pkgName, filename) => {
const src = pathJoin(__dirname, filename)
const dest = pathJoin(__dirname, 'packages', pkgName, filename)
cpSync(src, dest, {
dereference: true, // dereference symlinks
preserveTimestamps: true,
})
}
const generatePackageJsonForPackages = (pkgName) => {
const tplPath = pathJoin(__dirname, 'packages', pkgName, 'package.template.json')
const tpl = require(tplPath)
const packageJson = {
...basePkg,
// remove fields
private: undefined,
workspaces: undefined,
...Object.fromEntries(
PACKAGES
// remove own entry
.filter(_pkgName => _pkgName !== pkgName)
// remove others by setting `undefined` as value
.map(_pkgName => [_pkgName, undefined])
),
main: 'index.js',
files: [
'index.js',
'install.js',
'example.js',
'types',
],
types: 'types/index.d.ts',
scripts: {
install: 'node install.js',
prepublishOnly: 'npm run install',
},
devDependencies: {
...basePkg.devDependencies,
eslint: undefined, // remove field
},
...tpl,
}
const dest = pathJoin(__dirname, 'packages', pkgName, 'package.json')
writeFileSync(dest, JSON.stringify(packageJson, null, '\t'))
}
for (const pkgName of PACKAGES) {
copyFileIntoPackage(pkgName, 'LICENSE')
copyFileIntoPackage(pkgName, 'index.js')
copyFileIntoPackage(pkgName, 'install.js')
generatePackageJsonForPackages(pkgName)
console.info(pkgName, '✔︎')
}