-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, '✔︎') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters