-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): ncm config updates config files from template repo
- Loading branch information
Showing
7 changed files
with
84 additions
and
92 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import cosmiconfig from 'cosmiconfig'; | ||
import { exec } from 'lib/child-process'; | ||
|
||
// TODO: setup schema and sanitise config file | ||
export const readConfig = async () => { | ||
const MODULE_NAME = 'ncm'; | ||
const { config } = await cosmiconfig(MODULE_NAME).search(); | ||
return config; | ||
}; | ||
|
||
export const cloneTemplateRepo = async config => { | ||
const DEFAULT_TEMPLATE = `opbi/ncm-preset-${config.component.type}`; | ||
const template = config.component.template || DEFAULT_TEMPLATE; | ||
await exec(`rm -rf .template`); | ||
await exec(`git clone git@github.com:${template}.git .template`); | ||
}; | ||
|
||
export const removeTemplateDir = async () => exec('rm -rf .template'); |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as commonSteps from '../common-steps'; | ||
import * as steps from './steps'; | ||
|
||
export default async () => { | ||
const config = await commonSteps.readConfig(); | ||
|
||
await commonSteps.cloneTemplateRepo(config); | ||
|
||
await steps.copyConfigFiles(); | ||
|
||
await steps.updatePackageJson(); | ||
|
||
await commonSteps.removeTemplateDir(); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import cpy from 'cpy'; | ||
import jsonfile from 'jsonfile'; | ||
import { exec } from 'lib/child-process'; | ||
import { sortObjectByKeys } from 'lib/util'; | ||
|
||
/* | ||
copy only config files | ||
*/ | ||
export const copyConfigFiles = async () => { | ||
await cpy( | ||
[ | ||
'.template/*', | ||
'.template/.*', | ||
'!.template/.ncmrc.yml', // there can be .ncmrc.yml in template | ||
'!.template/*.md', | ||
'!.template/package.json', | ||
'!.template/yarn.lock', | ||
], | ||
'.', | ||
); | ||
await exec('cp -r .template/.circleci .'); | ||
}; | ||
|
||
/** | ||
* merge devDependencies and optionalDependencies from template package.json | ||
*/ | ||
export const updatePackageJson = async () => { | ||
const template = await jsonfile.readFile('.template/package.json'); | ||
const target = await jsonfile.readFile('./package.json'); | ||
const updated = Object.assign({}, target); | ||
updated.devDependencies = sortObjectByKeys({ | ||
...target.devDependencies, | ||
...template.devDependencies, | ||
}); | ||
updated.optionalDependencies = sortObjectByKeys({ | ||
...target.optionalDependencies, | ||
...template.optionalDependencies, | ||
}); | ||
await jsonfile.writeFile('./package.json', updated, { spaces: 2 }); | ||
}; |
This file was deleted.
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
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