-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ecc070
commit c03020c
Showing
4 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { promisify } = require('util') | ||
const fs = require('fs-extra') | ||
const originalPackage = require('../package.json') | ||
|
||
const readFile = promisify(fs.readFile) | ||
const writeFile = promisify(fs.writeFile) | ||
const targetProps = ['scripts', 'lint-staged'] | ||
|
||
module.exports = async function init(basedir = process.cwd()) { | ||
const packageFile = path.join(basedir, 'package.json') | ||
const packageInfo = JSON.parse(await readFile(packageFile, 'utf8')) | ||
async function updatePackageFile(baseDir) { | ||
const packageFile = path.join(baseDir, 'package.json') | ||
const packageInfo = JSON.parse(await fs.readFile(packageFile, 'utf8')) | ||
|
||
targetProps.forEach((prop) => { | ||
packageInfo[prop] = { ...originalPackage[prop], ...packageInfo[prop] } | ||
}) | ||
packageInfo.scripts['test:watch'] = `${packageInfo.scripts.test} --watch` | ||
|
||
await writeFile(packageFile, `${JSON.stringify(packageInfo, null, 2)}\n`) | ||
await fs.writeFile(packageFile, `${JSON.stringify(packageInfo, null, 2)}\n`) | ||
|
||
process.stdout.write(`${packageFile} was updated.\n`) | ||
} | ||
|
||
async function copyEditorConfig(baseDir) { | ||
const source = path.join(__dirname, '..', '.editorconfig') | ||
const target = path.join(baseDir, '.editorconfig') | ||
await fs.copy(source, target) | ||
|
||
process.stdout.write(`${target} was updated.\n`) | ||
} | ||
|
||
module.exports = async function init(baseDir = process.cwd()) { | ||
await updatePackageFile(baseDir) | ||
|
||
await copyEditorConfig(baseDir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters