-
Notifications
You must be signed in to change notification settings - Fork 5
/
prepare-packages.js
69 lines (54 loc) · 1.66 KB
/
prepare-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
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const copyFileAsync = promisify(fs.copyFile);
const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
const rewritePackageJSON = async (dir, transformer) => {
const packageJsonPath = path.join(dir, 'package.json');
const rootPackage = await readFileAsync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(rootPackage);
const transformedJSON = transformer(packageJson);
await writeFileAsync(
packageJsonPath,
JSON.stringify(transformedJSON, undefined, 2)
);
};
const transformNativePackageJSON = package => {
package.name = '@lifeomic/chromicons-native';
package.peerDependencies['react-native-svg'] = '>=12.x';
return package;
};
const transformPngsPackageJSON = package => {
package.name = '@lifeomic/chromicons-png';
delete package.main;
delete package.typings;
delete package.module;
package.files.push('lined');
return package;
};
const prepareLib = async name => {
const libDir = path.resolve(__dirname, 'build', name);
const filesToCopy = ['package.json', 'README.md', 'LICENSE'];
await Promise.all(
filesToCopy.map(fileName =>
copyFileAsync(
path.resolve(__dirname, fileName),
path.join(libDir, fileName)
)
)
);
if (name === 'native') {
await rewritePackageJSON(libDir, transformNativePackageJSON);
} else if (name === 'pngs') {
await rewritePackageJSON(libDir, transformPngsPackageJSON);
}
};
Promise.all([
prepareLib('react'),
prepareLib('native'),
prepareLib('pngs'),
]).catch(err => {
console.error(err);
process.exitCode = 1;
});