1 | const path = require('path'); |
||
2 | const fs = require('fs-extra'); |
||
3 | |||
4 | |||
5 | const files = { |
||
6 | 'README.md': '', |
||
7 | 'LICENSE': '' |
||
8 | }; |
||
9 | |||
10 | Promise.all( |
||
11 | Object.keys(files) |
||
12 | .map((file) => copyFile(file, files[file])) |
||
13 | ) |
||
14 | .then(() => createPackageFile()); |
||
15 | |||
16 | |||
17 | function copyFile(file, filePath) { |
||
18 | return new Promise((resolve) => { |
||
19 | console.log(`copying ${file} to ${path.resolve(__dirname, '../lib', filePath)}`) |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
20 | return fs.copy( |
||
21 | file, |
||
22 | path.resolve( |
||
23 | __dirname, |
||
24 | '../lib', |
||
25 | filePath, |
||
26 | path.basename(file) |
||
27 | ), |
||
28 | (error, data) => { |
||
29 | if (error) throw new Error (`error copying file ${file}`, error); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
30 | return resolve(data); |
||
31 | } |
||
32 | ); |
||
33 | }); |
||
34 | } |
||
35 | |||
36 | |||
37 | function createPackageFile() { |
||
38 | return new Promise((resolve) => { |
||
39 | fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', (err, data) => { |
||
40 | if (err) throw err; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
41 | return resolve(data); |
||
42 | }); |
||
43 | }) |
||
44 | .then((data) => JSON.parse(data)) |
||
45 | .then((packageData) => { |
||
46 | const { |
||
47 | author, |
||
48 | version, |
||
49 | description, |
||
50 | keyword, |
||
51 | repository, |
||
52 | license, |
||
53 | bugs, |
||
54 | homepage, |
||
55 | peerDependencies, |
||
56 | dependencies |
||
57 | } = packageData; |
||
58 | const minPackage = { |
||
59 | author, |
||
60 | version, |
||
61 | description, |
||
62 | keyword, |
||
63 | repository, |
||
64 | license, |
||
65 | bugs, |
||
66 | homepage, |
||
67 | peerDependencies, |
||
68 | dependencies, |
||
69 | main: './loader.js', |
||
70 | name: 'yaml-js-loader', |
||
71 | } |
||
72 | return new Promise((resolve) => { |
||
73 | const data = JSON.stringify(minPackage); |
||
74 | fs.writeFile(path.resolve(__dirname, '../lib/package.json'), data, (error) => { |
||
75 | if (error) throw error; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
76 | return resolve(); |
||
77 | }); |
||
78 | }); |
||
79 | }); |
||
80 | } |
||
81 | |||
82 |