Skip to content

Commit 59d58a0

Browse files
authored
[cli] Add clean init template (#186)
1 parent 269a50c commit 59d58a0

File tree

9 files changed

+52
-24
lines changed

9 files changed

+52
-24
lines changed

packages/@sanity/cli/src/commands/init/initSanity.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,25 @@ export default async function initSanity(args, context) {
4848
// Ensure we are using the output path provided by user
4949
const outputPath = answers.outputPath || workDir
5050

51+
// Prompt for template to use
52+
const templateName = await prompt.single({
53+
message: 'Select project template',
54+
type: 'list',
55+
choices: [
56+
{
57+
value: 'moviedb',
58+
name: 'Movie database (schema + sample data)'
59+
},
60+
{
61+
value: 'clean',
62+
name: 'Clean, minimal project'
63+
}
64+
]
65+
})
66+
5167
// Build a full set of resolved options
5268
const initOptions = {
53-
template: 'moviedb',
69+
template: templateName,
5470
outputDir: outputPath,
5571
name: sluggedName,
5672
displayName: displayName,
@@ -81,16 +97,10 @@ export default async function initSanity(args, context) {
8197

8298
// Check if we're currently in the output path, so we can give a better start message
8399
if (outputPath === process.cwd()) {
84-
output.print(
85-
`\n${chalk.green('Success!')} You can now run "${chalk.cyan(
86-
'sanity start'
87-
)}"`
88-
)
100+
output.print(`\n${chalk.green('Success!')} You can now run "${chalk.cyan('sanity start')}"`)
89101
} else {
90102
output.print(
91-
`\n${chalk.green(
92-
'Success!'
93-
)} You can now change to directory "${chalk.cyan(
103+
`\n${chalk.green('Success!')} You can now change to directory "${chalk.cyan(
94104
outputPath
95105
)}" and run "${chalk.cyan('sanity start')}"`
96106
)
@@ -105,17 +115,13 @@ export default async function initSanity(args, context) {
105115
}
106116

107117
async function getOrCreateUser() {
108-
output.print(
109-
"We can't find any auth credentials in your Sanity config - looks like you"
110-
)
118+
output.print("We can't find any auth credentials in your Sanity config - looks like you")
111119
output.print("haven't used Sanity on this system before?\n")
112120

113121
// Provide login options (`sanity login`)
114122
await login(args, context)
115123

116-
output.print(
117-
"Good stuff, you're now authenticated. You'll need a project to keep your"
118-
)
124+
output.print("Good stuff, you're now authenticated. You'll need a project to keep your")
119125
output.print('data sets and collaborators safe and snug.')
120126
}
121127

@@ -124,9 +130,7 @@ export default async function initSanity(args, context) {
124130
try {
125131
projects = await apiClient({requireProject: false}).projects.list()
126132
} catch (err) {
127-
throw new Error(
128-
`Failed to communicate with the Sanity API:\n${err.message}`
129-
)
133+
throw new Error(`Failed to communicate with the Sanity API:\n${err.message}`)
130134
}
131135

132136
if (projects.length === 0) {
@@ -135,9 +139,7 @@ export default async function initSanity(args, context) {
135139
return createProject(apiClient, {displayName: projectName})
136140
}
137141

138-
debug(
139-
`User has ${projects.length} project(s) already, showing list of choices`
140-
)
142+
debug(`User has ${projects.length} project(s) already, showing list of choices`)
141143

142144
const projectChoices = projects.map(project => ({
143145
value: project.id,
@@ -185,9 +187,7 @@ export default async function initSanity(args, context) {
185187
return {datasetName: name}
186188
}
187189

188-
debug(
189-
`User has ${datasets.length} dataset(s) already, showing list of choices`
190-
)
190+
debug(`User has ${datasets.length} dataset(s) already, showing list of choices`)
191191
const datasetChoices = datasets.map(dataset => ({value: dataset.name}))
192192

193193
const selected = await prompt.single({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const dependencies = {
2+
'@sanity/date-input': '^0.99.0'
3+
}
4+
5+
export const generateSanityManifest = base => ({
6+
...base,
7+
plugins: base.plugins.concat(['@sanity/date-input'])
8+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Coverage directory used by tools like istanbul
6+
coverage
7+
8+
# Dependency directories
9+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"#": "Used by Sanity to keep track of configuration file checksums, do not delete or modify!"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
User-specific packages can be placed here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const createSchema = require('part:@sanity/base/schema-creator')
2+
3+
module.exports = createSchema({
4+
name: 'default',
5+
types: [/* Your types here! */]
6+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Files placed here will be served by the Sanity server under the `/static`-prefix
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)