-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): use auto-updates flag in init (#7401)
* feat(cli): enable autoUpdates by default on new projects * feat(cli): add auto updates flag in init and use in template * refactor: add back early returns * Update packages/@sanity/cli/src/commands/init/initCommand.ts * refactor: replace boolean expressions with literals * refactor: change help text to include both enable/disable flags --------- Co-authored-by: Binoy Patel <[email protected]> Co-authored-by: Rune Botten <[email protected]> Co-authored-by: Espen Hovlandsdal <[email protected]>
- Loading branch information
1 parent
8b0eeff
commit 17c02f9
Showing
8 changed files
with
146 additions
and
8 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
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,94 @@ | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
|
||
import {describe, expect} from '@jest/globals' | ||
|
||
import templates from '../src/actions/init-project/templates' | ||
import {describeCliTest, testConcurrent} from './shared/describe' | ||
import {baseTestPath, cliProjectId, getTestRunArgs, runSanityCmdCommand} from './shared/environment' | ||
|
||
describeCliTest('CLI: `sanity init v3`', () => { | ||
describe.each(Object.keys(templates))('for template %s', (template) => { | ||
testConcurrent('adds autoUpdates: true to cli config', async () => { | ||
const version = 'v3' | ||
const testRunArgs = getTestRunArgs(version) | ||
const outpath = `test-template-${template}-${version}` | ||
|
||
await runSanityCmdCommand(version, [ | ||
'init', | ||
'--y', | ||
'--project', | ||
cliProjectId, | ||
'--dataset', | ||
testRunArgs.dataset, | ||
'--template', | ||
template, | ||
'--output-path', | ||
`${baseTestPath}/${outpath}`, | ||
'--package-manager', | ||
'manual', | ||
]) | ||
|
||
const cliConfig = await fs.readFile( | ||
path.join(baseTestPath, outpath, 'sanity.cli.ts'), | ||
'utf-8', | ||
) | ||
|
||
expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) | ||
expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) | ||
expect(cliConfig).toContain(`autoUpdates: true`) | ||
}) | ||
}) | ||
|
||
testConcurrent('adds autoUpdates: true to cli config for javascript projects', async () => { | ||
const version = 'v3' | ||
const testRunArgs = getTestRunArgs(version) | ||
const outpath = `test-template-${version}` | ||
|
||
await runSanityCmdCommand(version, [ | ||
'init', | ||
'--y', | ||
'--project', | ||
cliProjectId, | ||
'--dataset', | ||
testRunArgs.dataset, | ||
'--output-path', | ||
`${baseTestPath}/${outpath}`, | ||
'--package-manager', | ||
'manual', | ||
'--no-typescript', | ||
]) | ||
|
||
const cliConfig = await fs.readFile(path.join(baseTestPath, outpath, 'sanity.cli.js'), 'utf-8') | ||
|
||
expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) | ||
expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) | ||
expect(cliConfig).toContain(`autoUpdates: true`) | ||
}) | ||
|
||
testConcurrent('adds autoUpdates: false to cli config if flag provided', async () => { | ||
const version = 'v3' | ||
const testRunArgs = getTestRunArgs(version) | ||
const outpath = `test-template-${version}` | ||
|
||
await runSanityCmdCommand(version, [ | ||
'init', | ||
'--y', | ||
'--project', | ||
cliProjectId, | ||
'--dataset', | ||
testRunArgs.dataset, | ||
'--output-path', | ||
`${baseTestPath}/${outpath}`, | ||
'--package-manager', | ||
'manual', | ||
'--no-auto-updates', | ||
]) | ||
|
||
const cliConfig = await fs.readFile(path.join(baseTestPath, outpath, 'sanity.cli.ts'), 'utf-8') | ||
|
||
expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) | ||
expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) | ||
expect(cliConfig).toContain(`autoUpdates: false`) | ||
}) | ||
}) |
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