-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrank.js
56 lines (46 loc) · 1.51 KB
/
frank.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
/**
* A script to frank the build i.e. to copy the package.json and readme files to the dist folder.
*
* Credit for the script goes to @Izhaki
*/
/* eslint-disable no-console */
const { resolve, join, basename } = require('path');
const { readFile, writeFile, copy } = require('fs-extra');
const packagePath = process.cwd();
const distPath = join(packagePath, './dist');
const iconTypes = ['base', 'component', 'doctype', 'illustrative', 'logo'];
const writeJson = (targetPath, obj) =>
writeFile(targetPath, JSON.stringify(obj, null, 2), 'utf8');
async function createMainPackageFile() {
const packageData = await readFile(
resolve(packagePath, './package.json'),
'utf8'
);
const { scripts, devDependencies, ...packageOthers } =
JSON.parse(packageData);
const newPackageData = {
...packageOthers,
private: false
};
const targetPath = resolve(distPath, './package.json');
await writeJson(targetPath, newPackageData);
console.log(`Created package.json in ${targetPath}`);
}
async function includeFileInBuild(file) {
const sourcePath = resolve(packagePath, file);
const targetPath = resolve(distPath, basename(file));
await copy(sourcePath, targetPath);
console.log(`Copied ${sourcePath} to ${targetPath}`);
}
async function run() {
try {
await createMainPackageFile();
await includeFileInBuild('./README.md');
await includeFileInBuild('./LICENSE');
await includeFileInBuild('./DEVELOPMENT.md');
} catch (err) {
console.error(err);
process.exit(1);
}
}
run();