-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(setup): add
npx shipjs setup
(#361)
* feat: setup WIP * feat: ask questions WIP * feat: add steps for setup WIP * feat: add steps for setup
- Loading branch information
Eunjae Lee
authored
Oct 24, 2019
1 parent
27afde7
commit df70f0a
Showing
27 changed files
with
748 additions
and
27 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
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
25 changes: 25 additions & 0 deletions
25
packages/shipjs-lib/src/lib/git/__tests__/getRemoteBranches.spec.js
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,25 @@ | ||
import silentExec from '../../shell/silentExec'; | ||
import getRemoteBranches from '../getRemoteBranches'; | ||
jest.mock('../../shell/silentExec'); | ||
|
||
describe('getRemoteBranches', () => { | ||
it('works', () => { | ||
silentExec | ||
.mockImplementationOnce(() => 'origin') | ||
.mockImplementationOnce( | ||
() => ` origin/HEAD -> origin/master | ||
origin/chore/all-contributors | ||
origin/master | ||
origin/renovate/pin-dependencies | ||
origin/renovate/rollup-1.x | ||
` | ||
); | ||
const result = getRemoteBranches(); | ||
expect(result).toEqual([ | ||
'chore/all-contributors', | ||
'master', | ||
'renovate/pin-dependencies', | ||
'renovate/rollup-1.x', | ||
]); | ||
}); | ||
}); |
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,7 @@ | ||
import silentExec from '../shell/silentExec'; | ||
|
||
export default function getGitConfig(key, dir = '.') { | ||
return silentExec(`git config ${key}`, { dir, ignoreError: true }) | ||
.toString() | ||
.trim(); | ||
} |
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,24 @@ | ||
import silentExec from '../shell/silentExec'; | ||
|
||
/* | ||
$ git branch -r | ||
origin/HEAD -> origin/master | ||
origin/chore/all-contributors | ||
origin/master | ||
origin/renovate/pin-dependencies | ||
origin/renovate/rollup-1.x | ||
... | ||
*/ | ||
|
||
export default function getRemoteBranches(dir = '.') { | ||
const remote = silentExec('git remote', { dir }) | ||
.toString() | ||
.trim(); | ||
return silentExec('git branch -r', { dir }) | ||
.toString() | ||
.trim() | ||
.split('\n') | ||
.map(line => line.trim()) | ||
.filter(line => !line.includes(' -> ')) | ||
.map(line => line.slice(remote.length + 1)); | ||
} |
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
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
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,56 @@ | ||
import printHelp from '../step/setup/printHelp'; | ||
import askQuestions from '../step/setup/askQuestions'; | ||
import addDevDependencies from '../step/setup/addDevDependencies'; | ||
import addScriptsToPackageJson from '../step/setup/addScriptsToPackageJson'; | ||
import addShipConfig from '../step/setup/addShipConfig'; | ||
import addCircleCIConfig from '../step/setup/addCircleCIConfig'; | ||
|
||
async function setup({ help = false, dir = '.' }) { | ||
if (help) { | ||
printHelp(); | ||
return; | ||
} | ||
const { | ||
baseBranch, | ||
releaseBranch, | ||
configureCircleCI, | ||
scheduleCircleCI, | ||
cronExpr, | ||
useMonorepo, | ||
mainVersionFile, | ||
packagesToBump, | ||
packagesToPublish, | ||
} = await askQuestions({ dir }); | ||
addDevDependencies({ dependencies: ['shipjs'], dir }); | ||
addScriptsToPackageJson({ dir }); | ||
await addShipConfig({ | ||
baseBranch, | ||
releaseBranch, | ||
useMonorepo, | ||
mainVersionFile, | ||
packagesToBump, | ||
packagesToPublish, | ||
dir, | ||
}); | ||
addCircleCIConfig({ | ||
baseBranch, | ||
configureCircleCI, | ||
scheduleCircleCI, | ||
cronExpr, | ||
dir, | ||
}); | ||
} | ||
|
||
const arg = { | ||
'--dir': String, | ||
'--help': Boolean, | ||
|
||
// Aliases | ||
'-d': '--dir', | ||
'-h': '--help', | ||
}; | ||
|
||
export default { | ||
arg, | ||
fn: setup, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import prettier from 'prettier'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export default async function runPrettier({ filePath, dir }) { | ||
const text = fs.readFileSync(filePath).toString(); | ||
const options = await prettier.resolveConfig(dir); | ||
const formatted = prettier.format(text, { | ||
parser: getParser(filePath), | ||
...(options || {}), | ||
}); | ||
fs.writeFileSync(filePath, formatted); | ||
} | ||
|
||
function getParser(filePath) { | ||
const parser = { | ||
'.json': 'json', | ||
'.js': 'babel', | ||
}[path.extname(filePath)]; | ||
return parser; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import runStep from '../runStep'; | ||
import { gitPush } from '../../helper'; | ||
|
||
export default ({ config, currentBranch, dir, dryRun }) => | ||
export default ({ remote, currentBranch, dir, dryRun }) => | ||
runStep({ title: 'Pushing to remote.' }, () => { | ||
const { remote } = config; | ||
gitPush({ remote, refs: [currentBranch], dir, dryRun }); | ||
}); |
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,7 +1,7 @@ | ||
import runStep from './runStep'; | ||
import { run } from '../util'; | ||
|
||
export default ({ dir, dryRun }) => | ||
export default ({ remote, currentBranch, dir, dryRun }) => | ||
runStep({ title: 'Updating from remote.' }, () => { | ||
run({ command: 'git pull', dir, dryRun }); | ||
run({ command: `git pull ${remote} ${currentBranch}`, dir, dryRun }); | ||
}); |
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
28 changes: 28 additions & 0 deletions
28
packages/shipjs/src/step/setup/__tests__/printHelp.spec.js
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,28 @@ | ||
import { print } from '../../../util'; | ||
import printHelp from '../printHelp'; | ||
import { mockPrint } from '../../../../tests/util'; | ||
|
||
describe('printHelp', () => { | ||
it('prints help', () => { | ||
const output = []; | ||
mockPrint(print, output); | ||
printHelp(); | ||
expect(output).toMatchInlineSnapshot(` | ||
Array [ | ||
"NAME | ||
shipjs setup - Setup Ship.js in your project. | ||
USAGE | ||
npx shipjs setup [--help] [--dir PATH] | ||
OPTIONS | ||
-h, --help | ||
Print this help | ||
-d, --dir PATH | ||
Specify the PATH of the repository (default: the current directory). | ||
", | ||
] | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.