forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-npms.js
59 lines (50 loc) · 1.62 KB
/
create-npms.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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const shell = require('shelljs');
const mainpkg = require('./package.json');
const fs = require('fs');
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'dev', type: Boolean }
];
const options = commandLineArgs(optionDefinitions);
// Abort script on any failure from any shelljs invocation
shell.config.fatal = true;
// shelljs has no mktemp, so kludge our own
shell.mktemp = function() {
let dir = shell.tempdir() + "/" + (Date.now() + Math.random());
shell.mkdir(dir);
return dir;
}
function createNpm(dirname) {
if(!shell.test("-e", dirname + "/package.json")) {
throw new Error("Can't find package.json in " + dirname);
}
const here = shell.pwd();
const tmpdir = shell.mktemp("-d");
shell.cp("-R", "*", tmpdir);
shell.cp(dirname + "/*", tmpdir);
shell.cd(tmpdir);
shell.sed("-i", "%VERSION%", mainpkg.version, "package.json");
shell.exec("${YARN:-yarn} pack");
verifyManifest(require(`${here}/${dirname}/package.json`));
shell.cp(dirname + "*.tgz", here);
shell.cd(here);
shell.rm("-rf", tmpdir);
}
function verifyManifest(manifest) {
if (options.dev) return;
// TODO: Handle globs
const files = manifest.files.filter(s => s.indexOf("*") === -1);
for (const file of files) {
if (!fs.existsSync(file)) {
throw `File missing from manifest: ${file}`
}
}
}
const npms = shell.ls("*/package.json").map(c => c.replace(/\/.*/, ''));
npms.forEach(createNpm);