Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 30c0fc8

Browse files
Merge pull request #100 from amclin/feat/prompt-git
Feat/prompt git
2 parents 8909b42 + 520d435 commit 30c0fc8

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

create-app.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ const templateSettings = require('./templates/default.json')
2121
const ssrTemplateSettings = require('./templates/default-ssr.json')
2222
const staticTemplateSettings = require('./templates/default-static.json')
2323

24-
const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example }) => {
24+
const createApp = async ({
25+
appPath,
26+
example,
27+
gitRemote,
28+
isStatic,
29+
noGit = false,
30+
useNpm
31+
}) => {
32+
const root = path.resolve(appPath)
33+
const appName = path.basename(root)
34+
2535
if (example) {
2636
const found = await hasExample(example)
2737
if (!found) {
@@ -34,8 +44,6 @@ const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example })
3444
}
3545
}
3646

37-
const root = path.resolve(appPath)
38-
const appName = path.basename(root)
3947
const version = '0.1.0'
4048

4149
await makeDir(root)
@@ -54,7 +62,6 @@ const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example })
5462
await makeDir(root)
5563
process.chdir(root)
5664

57-
const gitRemote = `git+ssh://[email protected]/amclin/${appName}.git`
5865
const homepage = `https://github.com/amclin/${appName}`
5966
const author = userName()
6067
const year = new Date().getFullYear()
@@ -103,9 +110,7 @@ const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example })
103110
url: `${homepage}/issues`
104111
}
105112
},
106-
(isStatic) ?
107-
staticTemplateSettings.package :
108-
ssrTemplateSettings.package
113+
isStatic ? staticTemplateSettings.package : ssrTemplateSettings.package
109114
)
110115

111116
fs.writeFileSync(
@@ -142,11 +147,8 @@ const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example })
142147
})
143148
log()
144149

145-
const copyTemplateFiles = (dir) => {
146-
return cpy([
147-
'**',
148-
'.dependabot/**'
149-
], root, {
150+
const copyTemplateFiles = dir => {
151+
return cpy(['**', '.dependabot/**'], root, {
150152
parents: true,
151153
cwd: path.join(__dirname, 'templates', dir),
152154
rename: name => {
@@ -170,11 +172,7 @@ const createApp = async ({ appPath, useNpm, noGit = false, isStatic, example })
170172
// For sites with server-side React (not staticly generated)
171173
// We need a different docker file and different build
172174
// instructions
173-
await copyTemplateFiles(
174-
(isStatic) ?
175-
'default-static' :
176-
'default-ssr'
177-
)
175+
await copyTemplateFiles(isStatic ? 'default-static' : 'default-ssr')
178176

179177
await populateProject({ root, appName, homepage, author, year })
180178
}

helpers/populate-project.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ describe('populate-project', () => {
5555
expect(result.includes('mockAppName'))
5656
expect(result.includes('http://example.com/mockHomepage'))
5757
})
58+
59+
it.skip('logs an error when it cannot replace variables', {})
5860
})

helpers/should-use-yarn.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const childProcess = require('child_process')
2+
const { shouldUseYarn } = require('./should-use-yarn')
3+
4+
jest.mock('child_process')
5+
6+
describe('should-use-yarn', () => {
7+
it('returns true when the system has yarn installed', () => {
8+
childProcess.execSync.mockImplementationOnce(() => true)
9+
expect(shouldUseYarn()).toEqual(true)
10+
})
11+
it('returns false when the system has an error or yarn is not installed', () => {
12+
childProcess.execSync.mockImplementationOnce(() => { throw new Error('mock error') })
13+
expect(shouldUseYarn()).toEqual(false)
14+
})
15+
})

index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const program = new Commander.Command(packageJson.name)
2222
})
2323
.option('--use-npm')
2424
.option('--no-git', 'skip git creation and commits')
25-
.option('--with-ssr', 'the generated project will have React server-side rendering')
25+
.option(
26+
'--with-ssr',
27+
'the generated project will have React server-side rendering'
28+
)
2629
.option(
2730
'-e, --example <example-path>',
2831
'an example to bootstrap the app with'
@@ -56,11 +59,22 @@ async function run() {
5659
questions.push({
5760
type: 'confirm',
5861
name: 'isStatic',
59-
message: 'Is this app a statically-generated site? (For server-side-rendering choose No)',
62+
message:
63+
'Is this app a statically-generated site? (For server-side-rendering choose No)',
6064
initial: true
6165
})
6266
}
6367

68+
const defaultGitUrl = 'git+ssh://[email protected]/example/example.git'
69+
if (program.git) {
70+
questions.push({
71+
type: 'text',
72+
name: 'gitUrl',
73+
message: 'Please provide the full URL used to clone the git repo:',
74+
initial: defaultGitUrl
75+
})
76+
}
77+
6478
const res = await prompts(questions)
6579

6680
if (typeof res.path === 'string') {
@@ -98,7 +112,8 @@ async function run() {
98112
appPath: resolvedProjectPath,
99113
useNpm: !!program.useNpm,
100114
noGit: !program.git,
101-
isStatic: (program.withSsr) ? !program.withSsr : res.isStatic,
115+
isStatic: program.withSsr ? !program.withSsr : res.isStatic,
116+
gitRemote: program.git ? res.gitUrl : defaultGitUrl,
102117
example:
103118
typeof program.example === 'string' && program.example.trim()
104119
? program.example.trim()
@@ -115,7 +130,11 @@ async function notifyUpdate() {
115130
const isYarn = shouldUseYarn()
116131

117132
log()
118-
log(chalk.yellow.bold('A new version of `create-amclin-nextjs-app` is available!'))
133+
log(
134+
chalk.yellow.bold(
135+
'A new version of `create-amclin-nextjs-app` is available!'
136+
)
137+
)
119138
log(`
120139
You can update by running:
121140
${chalk.cyan(
@@ -125,7 +144,9 @@ async function notifyUpdate() {
125144
)}
126145
`)
127146
log()
128-
log(`But an even better option is to globally uninstall and in the future run:`)
147+
log(
148+
`But an even better option is to globally uninstall and in the future run:`
149+
)
129150
log(chalk.cyan()` npx create-amclin-nextjs-app`)
130151
log(`That way you'll always have the latest.`)
131152
}

0 commit comments

Comments
 (0)