forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-package-json.js
executable file
·42 lines (36 loc) · 1.05 KB
/
build-package-json.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
#!/usr/bin/env node
/*
Copyright (c) 2018-2020 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
/* eslint-env node */
// @flow
const fs = require('fs');
const path = require('path');
const util = require('util');
const asyncReaddir = util.promisify(fs.readdir);
const asyncStat = util.promisify(fs.stat);
async function buildPackageJsonFiles() {
const distPath = path.resolve(__dirname, '../dist');
const esmPath = path.join(distPath, 'esm');
const dirs = [];
for (const file of await asyncReaddir(esmPath)) {
const fileStat = await asyncStat(path.join(esmPath, file));
if (fileStat.isDirectory()) {
dirs.push(file);
const data = {
sideEffects: false,
module: path.join('../esm', file, 'index.js'),
};
fs.writeFileSync(
path.join(distPath, file, 'package.json'),
JSON.stringify(data, null, 2),
err => {
if (err) throw err;
},
);
}
}
}
buildPackageJsonFiles();