Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Add clean init template #186

Merged
merged 2 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions packages/@sanity/cli/src/commands/init/initSanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,25 @@ export default async function initSanity(args, context) {
// Ensure we are using the output path provided by user
const outputPath = answers.outputPath || workDir

// Prompt for template to use
const templateName = await prompt.single({
message: 'Select template to use',
type: 'list',
choices: [
{
value: 'moviedb',
name: 'Movie database (schema + data examples)'
},
{
value: 'clean',
name: 'Clean, minimal project'
}
]
})

// Build a full set of resolved options
const initOptions = {
template: 'moviedb',
template: templateName,
outputDir: outputPath,
name: sluggedName,
displayName: displayName,
Expand Down Expand Up @@ -81,16 +97,10 @@ export default async function initSanity(args, context) {

// Check if we're currently in the output path, so we can give a better start message
if (outputPath === process.cwd()) {
output.print(
`\n${chalk.green('Success!')} You can now run "${chalk.cyan(
'sanity start'
)}"`
)
output.print(`\n${chalk.green('Success!')} You can now run "${chalk.cyan('sanity start')}"`)
} else {
output.print(
`\n${chalk.green(
'Success!'
)} You can now change to directory "${chalk.cyan(
`\n${chalk.green('Success!')} You can now change to directory "${chalk.cyan(
outputPath
)}" and run "${chalk.cyan('sanity start')}"`
)
Expand All @@ -105,17 +115,13 @@ export default async function initSanity(args, context) {
}

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

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

output.print(
"Good stuff, you're now authenticated. You'll need a project to keep your"
)
output.print("Good stuff, you're now authenticated. You'll need a project to keep your")
output.print('data sets and collaborators safe and snug.')
}

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

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

debug(
`User has ${projects.length} project(s) already, showing list of choices`
)
debug(`User has ${projects.length} project(s) already, showing list of choices`)

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

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

const selected = await prompt.single({
Expand Down
8 changes: 8 additions & 0 deletions packages/@sanity/cli/src/commands/init/templates/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const dependencies = {
'@sanity/date-input': '^0.99.0'
}

export const generateSanityManifest = base => ({
...base,
plugins: base.plugins.concat(['@sanity/date-input'])
})
9 changes: 9 additions & 0 deletions packages/@sanity/cli/templates/clean/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Logs
logs
*.log

# Coverage directory used by tools like istanbul
coverage

# Dependency directories
node_modules
3 changes: 3 additions & 0 deletions packages/@sanity/cli/templates/clean/config/.checksums
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"#": "Used by Sanity to keep track of configuration file checksums, do not delete or modify!"
}
1 change: 1 addition & 0 deletions packages/@sanity/cli/templates/clean/plugins/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User-specific packages can be placed here
6 changes: 6 additions & 0 deletions packages/@sanity/cli/templates/clean/schemas/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const createSchema = require('part:@sanity/base/schema-creator')

module.exports = createSchema({
name: 'default',
types: [/* Your types here! */]
})
1 change: 1 addition & 0 deletions packages/@sanity/cli/templates/clean/static/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Files placed here will be served by the Sanity server under the `/static`-prefix
Binary file not shown.
Binary file not shown.