-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.js
40 lines (35 loc) · 1.02 KB
/
copy.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
const path = require('path');
const fse = require('fs-extra');
function copyReadme() {
return fse.copyFile(path.resolve(__dirname, 'README.md'), path.resolve(__dirname, 'build', 'README.md'));
}
function createPackageFile() {
return new Promise((resolve) => {
fse.readFile(path.resolve(__dirname, 'package.json'), 'utf8', (err, data) => {
if (err) {
throw err;
}
resolve(data);
});
})
.then(data => JSON.parse(data))
.then((packageData) => {
const newPackage = {
...packageData,
main: './index.js',
private: false,
};
return new Promise((resolve) => {
const buildPath = path.resolve(__dirname, 'build', 'package.json');
const data = JSON.stringify(newPackage, null, 2);
fse.writeFile(buildPath, data, (err) => {
if (err) throw err;
console.log(`Created package.json in ${buildPath}`);
resolve();
});
});
});
}
createPackageFile()
.then(() => copyReadme())
.catch(console.log)