| Total Complexity | 15 |
| Complexity/F | 1.25 |
| Lines of Code | 81 |
| Function Count | 12 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 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(Object.keys(files).map((file) => copyFile(file, files[file]))) |
||
| 11 | .then(() => createPackageFile()); |
||
| 12 | |||
| 13 | |||
| 14 | function copyFile(file, filePath) { |
||
| 15 | return new Promise(function (resolve) { |
||
| 16 | console.log(`copying ${file} to ${path.resolve(__dirname, '../lib', filePath)}`) |
||
|
|
|||
| 17 | return fs.copy( |
||
| 18 | file, |
||
| 19 | path.resolve( |
||
| 20 | __dirname, |
||
| 21 | '../lib', |
||
| 22 | filePath, |
||
| 23 | path.basename(file) |
||
| 24 | ), |
||
| 25 | function(error, data) { |
||
| 26 | if (error) { |
||
| 27 | throw new Error (`error copying file ${file}`, error); |
||
| 28 | } |
||
| 29 | return resolve(data); |
||
| 30 | } |
||
| 31 | ); |
||
| 32 | }); |
||
| 33 | } |
||
| 34 | |||
| 35 | |||
| 36 | function createPackageFile() { |
||
| 37 | return new Promise(function(resolve) { |
||
| 38 | fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function(err, data) { |
||
| 39 | if (err) { |
||
| 40 | throw err; |
||
| 41 | } |
||
| 42 | return resolve(data); |
||
| 43 | }) |
||
| 44 | }) |
||
| 45 | .then((data) => JSON.parse(data)) |
||
| 46 | .then((packageData) => { |
||
| 47 | const { |
||
| 48 | author, |
||
| 49 | version, |
||
| 50 | description, |
||
| 51 | keyword, |
||
| 52 | repository, |
||
| 53 | license, |
||
| 54 | bugs, |
||
| 55 | homepage, |
||
| 56 | peerDependencies, |
||
| 57 | dependencies |
||
| 58 | } = packageData; |
||
| 59 | const minPackage = { |
||
| 60 | author, |
||
| 61 | version, |
||
| 62 | description, |
||
| 63 | keyword, |
||
| 64 | repository, |
||
| 65 | license, |
||
| 66 | bugs, |
||
| 67 | homepage, |
||
| 68 | peerDependencies, |
||
| 69 | dependencies, |
||
| 70 | main: './loader.js', |
||
| 71 | name: 'yaml-js-loader', |
||
| 72 | } |
||
| 73 | return new Promise((resolve) => { |
||
| 74 | const data = JSON.stringify(minPackage); |
||
| 75 | fs.writeFile(path.resolve(__dirname, '../lib/package.json'), data, function(error) { |
||
| 76 | if (error) throw error; |
||
| 77 | return resolve(); |
||
| 78 | }); |
||
| 79 | }); |
||
| 80 | }); |
||
| 81 | } |
||
| 82 | |||
| 83 |