@sanity/plugin-kit 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +53 -38
- package/assets/inject/semver-workflow/lint-staged.template.js +1 -1
- package/bin/plugin-kit.js +2 -0
- package/dist/_chunks/cli-9f3b6fb3.js +162 -0
- package/dist/_chunks/cli-9f3b6fb3.js.map +1 -0
- package/dist/_chunks/init-3ad3f71f.js +104 -0
- package/dist/_chunks/init-3ad3f71f.js.map +1 -0
- package/dist/_chunks/init-ed4b5e78.js +952 -0
- package/dist/_chunks/init-ed4b5e78.js.map +1 -0
- package/dist/_chunks/inject-c90dc62d.js +49 -0
- package/dist/_chunks/inject-c90dc62d.js.map +1 -0
- package/dist/_chunks/link-watch-7f10aeab.js +94 -0
- package/dist/_chunks/link-watch-7f10aeab.js.map +1 -0
- package/dist/_chunks/package-ad838e5c.js +2246 -0
- package/dist/_chunks/package-ad838e5c.js.map +1 -0
- package/dist/_chunks/package-fa6580ba.js +152 -0
- package/dist/_chunks/package-fa6580ba.js.map +1 -0
- package/dist/_chunks/ts-89567e57.js +167 -0
- package/dist/_chunks/ts-89567e57.js.map +1 -0
- package/dist/_chunks/verify-package-27b93f01.js +96 -0
- package/dist/_chunks/verify-package-27b93f01.js.map +1 -0
- package/dist/_chunks/verify-studio-3633e659.js +75 -0
- package/dist/_chunks/verify-studio-3633e659.js.map +1 -0
- package/dist/_chunks/version-d6a290e2.js +58 -0
- package/dist/_chunks/version-d6a290e2.js.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -16
- package/src/actions/init.ts +2 -0
- package/src/actions/inject.ts +66 -87
- package/src/actions/link-watch.ts +8 -5
- package/src/actions/verify/types.ts +0 -23
- package/src/actions/verify/validations.ts +65 -39
- package/src/actions/verify/verify-common.ts +4 -4
- package/src/actions/verify-package.ts +13 -7
- package/src/actions/verify-studio.ts +7 -4
- package/src/cli.ts +1 -3
- package/src/cmds/index.ts +18 -6
- package/src/cmds/inject.ts +5 -2
- package/src/cmds/link-watch.ts +0 -1
- package/src/configs/default-source.ts +10 -14
- package/src/configs/eslint.ts +51 -0
- package/src/configs/forced-package-versions.ts +8 -7
- package/src/configs/git.ts +68 -0
- package/src/configs/pkg-config.ts +31 -0
- package/src/configs/prettier.ts +11 -0
- package/src/configs/tsconfig.ts +79 -0
- package/src/constants.ts +2 -0
- package/src/index.ts +1 -4
- package/src/npm/package.ts +62 -26
- package/src/presets/presets.ts +2 -1
- package/src/presets/renovatebot.ts +10 -1
- package/src/presets/semver-workflow.ts +26 -14
- package/src/presets/ui-workshop.ts +28 -12
- package/src/presets/ui.ts +68 -0
- package/src/sanity/manifest.ts +2 -2
- package/src/util/files.ts +8 -8
- package/src/util/readme.ts +17 -15
- package/src/util/ts.ts +13 -0
- package/assets/inject/gitignore +0 -57
- package/assets/inject/package.config.template +0 -16
- package/assets/inject/template-tsconfig.json +0 -24
- package/lib/package.json +0 -129
- package/lib/src/actions/init.d.ts +0 -73
- package/lib/src/actions/init.js +0 -79
- package/lib/src/actions/init.js.map +0 -1
- package/lib/src/actions/inject.d.ts +0 -31
- package/lib/src/actions/inject.js +0 -350
- package/lib/src/actions/inject.js.map +0 -1
- package/lib/src/actions/link-watch.d.ts +0 -3
- package/lib/src/actions/link-watch.js +0 -87
- package/lib/src/actions/link-watch.js.map +0 -1
- package/lib/src/actions/verify/types.d.ts +0 -75
- package/lib/src/actions/verify/types.js +0 -3
- package/lib/src/actions/verify/types.js.map +0 -1
- package/lib/src/actions/verify/validations.d.ts +0 -27
- package/lib/src/actions/verify/validations.js +0 -410
- package/lib/src/actions/verify/validations.js.map +0 -1
- package/lib/src/actions/verify/verify-common.d.ts +0 -44
- package/lib/src/actions/verify/verify-common.js +0 -89
- package/lib/src/actions/verify/verify-common.js.map +0 -1
- package/lib/src/actions/verify-package.d.ts +0 -5
- package/lib/src/actions/verify-package.js +0 -73
- package/lib/src/actions/verify-package.js.map +0 -1
- package/lib/src/actions/verify-studio.d.ts +0 -5
- package/lib/src/actions/verify-studio.js +0 -55
- package/lib/src/actions/verify-studio.js.map +0 -1
- package/lib/src/cli.d.ts +0 -2
- package/lib/src/cli.js +0 -87
- package/lib/src/cli.js.map +0 -1
- package/lib/src/cmds/index.d.ts +0 -9
- package/lib/src/cmds/index.js +0 -11
- package/lib/src/cmds/index.js.map +0 -1
- package/lib/src/cmds/init.d.ts +0 -4
- package/lib/src/cmds/init.js +0 -95
- package/lib/src/cmds/init.js.map +0 -1
- package/lib/src/cmds/inject.d.ts +0 -4
- package/lib/src/cmds/inject.js +0 -76
- package/lib/src/cmds/inject.js.map +0 -1
- package/lib/src/cmds/link-watch.d.ts +0 -4
- package/lib/src/cmds/link-watch.js +0 -49
- package/lib/src/cmds/link-watch.js.map +0 -1
- package/lib/src/cmds/verify-package.d.ts +0 -4
- package/lib/src/cmds/verify-package.js +0 -38
- package/lib/src/cmds/verify-package.js.map +0 -1
- package/lib/src/cmds/verify-studio.d.ts +0 -4
- package/lib/src/cmds/verify-studio.js +0 -38
- package/lib/src/cmds/verify-studio.js.map +0 -1
- package/lib/src/cmds/verify.d.ts +0 -0
- package/lib/src/cmds/verify.js +0 -42
- package/lib/src/cmds/verify.js.map +0 -1
- package/lib/src/cmds/version.d.ts +0 -4
- package/lib/src/cmds/version.js +0 -55
- package/lib/src/cmds/version.js.map +0 -1
- package/lib/src/configs/banned-packages.d.ts +0 -2
- package/lib/src/configs/banned-packages.js +0 -30
- package/lib/src/configs/banned-packages.js.map +0 -1
- package/lib/src/configs/buildExtensions.d.ts +0 -1
- package/lib/src/configs/buildExtensions.js +0 -5
- package/lib/src/configs/buildExtensions.js.map +0 -1
- package/lib/src/configs/default-source.d.ts +0 -3
- package/lib/src/configs/default-source.js +0 -70
- package/lib/src/configs/default-source.js.map +0 -1
- package/lib/src/configs/forced-package-versions.d.ts +0 -16
- package/lib/src/configs/forced-package-versions.js +0 -14
- package/lib/src/configs/forced-package-versions.js.map +0 -1
- package/lib/src/configs/uselessFiles.d.ts +0 -1
- package/lib/src/configs/uselessFiles.js +0 -33
- package/lib/src/configs/uselessFiles.js.map +0 -1
- package/lib/src/constants.d.ts +0 -11
- package/lib/src/constants.js +0 -15
- package/lib/src/constants.js.map +0 -1
- package/lib/src/dependencies/find.d.ts +0 -0
- package/lib/src/dependencies/find.js +0 -195
- package/lib/src/dependencies/find.js.map +0 -1
- package/lib/src/dependencies/import-linter.d.ts +0 -3
- package/lib/src/dependencies/import-linter.js +0 -112
- package/lib/src/dependencies/import-linter.js.map +0 -1
- package/lib/src/index.d.ts +0 -2
- package/lib/src/index.js +0 -6
- package/lib/src/index.js.map +0 -1
- package/lib/src/npm/manager.d.ts +0 -7
- package/lib/src/npm/manager.js +0 -62
- package/lib/src/npm/manager.js.map +0 -1
- package/lib/src/npm/package.d.ts +0 -11
- package/lib/src/npm/package.js +0 -302
- package/lib/src/npm/package.js.map +0 -1
- package/lib/src/npm/publish.d.ts +0 -1
- package/lib/src/npm/publish.js +0 -14
- package/lib/src/npm/publish.js.map +0 -1
- package/lib/src/npm/resolveLatestVersions.d.ts +0 -3
- package/lib/src/npm/resolveLatestVersions.js +0 -37
- package/lib/src/npm/resolveLatestVersions.js.map +0 -1
- package/lib/src/presets/presets.d.ts +0 -8
- package/lib/src/presets/presets.js +0 -53
- package/lib/src/presets/presets.js.map +0 -1
- package/lib/src/presets/renovatebot.d.ts +0 -2
- package/lib/src/presets/renovatebot.js +0 -24
- package/lib/src/presets/renovatebot.js.map +0 -1
- package/lib/src/presets/semver-workflow.d.ts +0 -8
- package/lib/src/presets/semver-workflow.js +0 -166
- package/lib/src/presets/semver-workflow.js.map +0 -1
- package/lib/src/presets/ui-workshop.d.ts +0 -2
- package/lib/src/presets/ui-workshop.js +0 -88
- package/lib/src/presets/ui-workshop.js.map +0 -1
- package/lib/src/sanity/manifest.d.ts +0 -48
- package/lib/src/sanity/manifest.js +0 -263
- package/lib/src/sanity/manifest.js.map +0 -1
- package/lib/src/sharedFlags.d.ts +0 -15
- package/lib/src/sharedFlags.js +0 -17
- package/lib/src/sharedFlags.js.map +0 -1
- package/lib/src/util/command-parser.d.ts +0 -9
- package/lib/src/util/command-parser.js +0 -46
- package/lib/src/util/command-parser.js.map +0 -1
- package/lib/src/util/errorToUndefined.d.ts +0 -1
- package/lib/src/util/errorToUndefined.js +0 -11
- package/lib/src/util/errorToUndefined.js.map +0 -1
- package/lib/src/util/files.d.ts +0 -36
- package/lib/src/util/files.js +0 -264
- package/lib/src/util/files.js.map +0 -1
- package/lib/src/util/log.d.ts +0 -14
- package/lib/src/util/log.js +0 -36
- package/lib/src/util/log.js.map +0 -1
- package/lib/src/util/prompt.d.ts +0 -14
- package/lib/src/util/prompt.js +0 -75
- package/lib/src/util/prompt.js.map +0 -1
- package/lib/src/util/readme.d.ts +0 -8
- package/lib/src/util/readme.js +0 -92
- package/lib/src/util/readme.js.map +0 -1
- package/lib/src/util/request.d.ts +0 -1
- package/lib/src/util/request.js +0 -19
- package/lib/src/util/request.js.map +0 -1
- package/lib/src/util/user.d.ts +0 -13
- package/lib/src/util/user.js +0 -111
- package/lib/src/util/user.js.map +0 -1
- package/lib/test/cli.test.d.ts +0 -1
- package/lib/test/cli.test.js +0 -64
- package/lib/test/cli.test.js.map +0 -1
- package/lib/test/fixture-utils.d.ts +0 -25
- package/lib/test/fixture-utils.js +0 -67
- package/lib/test/fixture-utils.js.map +0 -1
- package/lib/test/init-verify-build.test.d.ts +0 -1
- package/lib/test/init-verify-build.test.js +0 -68
- package/lib/test/init-verify-build.test.js.map +0 -1
- package/lib/test/init.test.d.ts +0 -1
- package/lib/test/init.test.js +0 -169
- package/lib/test/init.test.js.map +0 -1
- package/lib/test/inject.test.d.ts +0 -1
- package/lib/test/inject.test.js +0 -75
- package/lib/test/inject.test.js.map +0 -1
- package/lib/test/run-test-command.d.ts +0 -1
- package/lib/test/run-test-command.js +0 -6
- package/lib/test/run-test-command.js.map +0 -1
- package/lib/test/semver-workflow.test.d.ts +0 -1
- package/lib/test/semver-workflow.test.js +0 -93
- package/lib/test/semver-workflow.test.js.map +0 -1
- package/lib/test/verify-package.test.d.ts +0 -1
- package/lib/test/verify-package.test.js +0 -87
- package/lib/test/verify-package.test.js.map +0 -1
- package/lib/test/version.test.d.ts +0 -1
- package/lib/test/version.test.js +0 -48
- package/lib/test/version.test.js.map +0 -1
package/src/cmds/inject.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import {loadConfig as loadPackageConfig} from '@sanity/pkg-utils'
|
|
1
2
|
import path from 'path'
|
|
2
3
|
import meow from 'meow'
|
|
3
4
|
import log from '../util/log'
|
|
4
5
|
import {inject} from '../actions/inject'
|
|
5
6
|
import {findStudioV3Config} from '../sanity/manifest'
|
|
6
7
|
import {initFlags} from '../actions/init'
|
|
7
|
-
import {cliName} from '../constants'
|
|
8
|
+
import {cliName, defaultOutDir} from '../constants'
|
|
8
9
|
import {presetHelpList} from '../presets/presets'
|
|
9
10
|
|
|
10
11
|
const description = `Inject configuration into a Sanity plugin`
|
|
@@ -51,6 +52,8 @@ Examples
|
|
|
51
52
|
async function run({argv}: {argv: string[]}) {
|
|
52
53
|
const cli = meow(help, {flags: initFlags, argv, description})
|
|
53
54
|
const basePath = path.resolve(cli.input[0] || process.cwd())
|
|
55
|
+
const packageConfig = await loadPackageConfig({cwd: basePath})
|
|
56
|
+
const outDir = packageConfig?.dist ?? defaultOutDir
|
|
54
57
|
|
|
55
58
|
const {v3ConfigFile} = await findStudioV3Config(basePath)
|
|
56
59
|
if (v3ConfigFile) {
|
|
@@ -60,7 +63,7 @@ async function run({argv}: {argv: string[]}) {
|
|
|
60
63
|
}
|
|
61
64
|
log.info('Inject config into plugin in "%s"', basePath)
|
|
62
65
|
|
|
63
|
-
await inject({basePath, flags: cli.flags, validate: false})
|
|
66
|
+
await inject({basePath, outDir, flags: cli.flags, validate: false})
|
|
64
67
|
log.info('Done!')
|
|
65
68
|
}
|
|
66
69
|
|
package/src/cmds/link-watch.ts
CHANGED
|
@@ -22,7 +22,6 @@ To override the default watch command configuration, provide an override in pack
|
|
|
22
22
|
"sanityPlugin": {
|
|
23
23
|
"watchCommand": "microbundle watch --format modern,esm,cjs --jsx React.createElement --jsxImportSource react --css inline",
|
|
24
24
|
"linkWatch": {
|
|
25
|
-
"folder": "lib",
|
|
26
25
|
"command": "npm run watch",
|
|
27
26
|
"extensions": "js,png,svg,gif,jpeg,css"
|
|
28
27
|
}
|
|
@@ -7,17 +7,15 @@ export function defaultSourceJs(pkg: PackageJson) {
|
|
|
7
7
|
import {definePlugin} from 'sanity'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Usage in sanity.config.js (or .ts)
|
|
11
11
|
*
|
|
12
|
-
* \`\`\`
|
|
12
|
+
* \`\`\`js
|
|
13
13
|
* import {defineConfig} from 'sanity'
|
|
14
14
|
* import {myPlugin} from '${pkg.name}'
|
|
15
15
|
*
|
|
16
|
-
* export
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* myPlugin({})
|
|
20
|
-
* ]
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* // ...
|
|
18
|
+
* plugins: [myPlugin({})],
|
|
21
19
|
* })
|
|
22
20
|
* \`\`\`
|
|
23
21
|
*/
|
|
@@ -42,17 +40,15 @@ export function defaultSourceTs(pkg: PackageJson) {
|
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
|
-
*
|
|
43
|
+
* Usage in \`sanity.config.ts\` (or .js)
|
|
46
44
|
*
|
|
47
|
-
* \`\`\`
|
|
45
|
+
* \`\`\`ts
|
|
48
46
|
* import {defineConfig} from 'sanity'
|
|
49
47
|
* import {myPlugin} from '${pkg.name}'
|
|
50
48
|
*
|
|
51
|
-
* export
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* myPlugin()
|
|
55
|
-
* ]
|
|
49
|
+
* export default defineConfig({
|
|
50
|
+
* // ...
|
|
51
|
+
* plugins: [myPlugin()],
|
|
56
52
|
* })
|
|
57
53
|
* \`\`\`
|
|
58
54
|
*/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {InjectTemplate} from '../actions/inject'
|
|
2
|
+
import {InitFlags} from '../actions/init'
|
|
3
|
+
|
|
4
|
+
export function eslintrcTemplate(options: {flags: InitFlags}): InjectTemplate {
|
|
5
|
+
const {flags} = options
|
|
6
|
+
|
|
7
|
+
const eslintConfig = {
|
|
8
|
+
root: true,
|
|
9
|
+
env: {
|
|
10
|
+
node: true,
|
|
11
|
+
browser: true,
|
|
12
|
+
},
|
|
13
|
+
extends: [
|
|
14
|
+
'sanity',
|
|
15
|
+
flags.typescript && 'sanity/typescript',
|
|
16
|
+
'sanity/react',
|
|
17
|
+
'plugin:react-hooks/recommended',
|
|
18
|
+
flags.prettier && 'plugin:prettier/recommended',
|
|
19
|
+
'plugin:react/jsx-runtime',
|
|
20
|
+
].filter(Boolean),
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
type: 'template',
|
|
25
|
+
force: flags.force,
|
|
26
|
+
to: '.eslintrc',
|
|
27
|
+
value: JSON.stringify(eslintConfig, null, 2),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function eslintignoreTemplate(options: {flags: InitFlags; outDir: string}): InjectTemplate {
|
|
32
|
+
const {flags, outDir} = options
|
|
33
|
+
|
|
34
|
+
const patterns = [
|
|
35
|
+
'.eslintrc.js',
|
|
36
|
+
'commitlint.config.js',
|
|
37
|
+
outDir,
|
|
38
|
+
'lint-staged.config.js',
|
|
39
|
+
flags.typescript ? 'package.config.ts' : 'package.config.js',
|
|
40
|
+
flags.typescript ? '*.js' : '',
|
|
41
|
+
].filter(Boolean)
|
|
42
|
+
|
|
43
|
+
patterns.sort()
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
type: 'template',
|
|
47
|
+
force: flags.force,
|
|
48
|
+
to: '.eslintignore',
|
|
49
|
+
value: patterns.join('\n'),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const forcedPackageVersions = {}
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const forcedDevPackageVersions = forcedPackageVersions
|
|
4
|
+
|
|
5
|
+
export const forcedPeerPackageVersions = {
|
|
4
6
|
react: '^18',
|
|
5
|
-
'@types/react': '^18',
|
|
6
7
|
'react-dom': '^18',
|
|
8
|
+
'react-is': '^18',
|
|
9
|
+
'@types/react': '^18',
|
|
7
10
|
'@types/react-dom': '^18',
|
|
8
|
-
sanity:
|
|
9
|
-
'
|
|
11
|
+
sanity: '^3',
|
|
12
|
+
'styled-components': '^5.2',
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
export const forcedDevPackageVersions = forcedPackageVersions
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {outdent} from 'outdent'
|
|
2
|
+
import {InjectTemplate} from '../actions/inject'
|
|
3
|
+
|
|
4
|
+
export function gitignoreTemplate(): InjectTemplate {
|
|
5
|
+
return {
|
|
6
|
+
type: 'template',
|
|
7
|
+
to: '.gitignore',
|
|
8
|
+
value: outdent`
|
|
9
|
+
# Logs
|
|
10
|
+
logs
|
|
11
|
+
*.log
|
|
12
|
+
npm-debug.log*
|
|
13
|
+
|
|
14
|
+
# Runtime data
|
|
15
|
+
pids
|
|
16
|
+
*.pid
|
|
17
|
+
*.seed
|
|
18
|
+
|
|
19
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
20
|
+
lib-cov
|
|
21
|
+
|
|
22
|
+
# Coverage directory used by tools like istanbul
|
|
23
|
+
coverage
|
|
24
|
+
|
|
25
|
+
# nyc test coverage
|
|
26
|
+
.nyc_output
|
|
27
|
+
|
|
28
|
+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
29
|
+
.grunt
|
|
30
|
+
|
|
31
|
+
# node-waf configuration
|
|
32
|
+
.lock-wscript
|
|
33
|
+
|
|
34
|
+
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
35
|
+
build/Release
|
|
36
|
+
|
|
37
|
+
# Dependency directories
|
|
38
|
+
node_modules
|
|
39
|
+
jspm_packages
|
|
40
|
+
|
|
41
|
+
# Optional npm cache directory
|
|
42
|
+
.npm
|
|
43
|
+
|
|
44
|
+
# Optional REPL history
|
|
45
|
+
.node_repl_history
|
|
46
|
+
|
|
47
|
+
# macOS finder cache file
|
|
48
|
+
.DS_Store
|
|
49
|
+
|
|
50
|
+
# VS Code settings
|
|
51
|
+
.vscode
|
|
52
|
+
|
|
53
|
+
# IntelliJ
|
|
54
|
+
.idea
|
|
55
|
+
*.iml
|
|
56
|
+
|
|
57
|
+
# Cache
|
|
58
|
+
.cache
|
|
59
|
+
|
|
60
|
+
# Yalc
|
|
61
|
+
.yalc
|
|
62
|
+
yalc.lock
|
|
63
|
+
|
|
64
|
+
# npm package zips
|
|
65
|
+
*.tgz
|
|
66
|
+
`,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {outdent} from 'outdent'
|
|
2
|
+
import {InjectTemplate} from '../actions/inject'
|
|
3
|
+
import {InitFlags} from '../actions/init'
|
|
4
|
+
|
|
5
|
+
export function pkgConfigTemplate(options: {outDir: string; flags: InitFlags}): InjectTemplate {
|
|
6
|
+
const {flags, outDir} = options
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
type: 'template',
|
|
10
|
+
force: flags.force,
|
|
11
|
+
to: flags.typescript ? 'package.config.ts' : 'package.config.js',
|
|
12
|
+
value: outdent`
|
|
13
|
+
import {defineConfig} from '@sanity/pkg-utils'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
legacyExports: true,
|
|
17
|
+
tsconfig: 'tsconfig.${outDir}.json',
|
|
18
|
+
|
|
19
|
+
// Remove this block to enable strict export validation
|
|
20
|
+
extract: {
|
|
21
|
+
rules: {
|
|
22
|
+
'ae-forgotten-export': 'off',
|
|
23
|
+
'ae-incompatible-release-tags': 'off',
|
|
24
|
+
'ae-internal-missing-underscore': 'off',
|
|
25
|
+
'ae-missing-release-tag': 'off',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
`,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {InjectTemplate} from '../actions/inject'
|
|
2
|
+
|
|
3
|
+
export function prettierignoreTemplate(options: {outDir: string}): InjectTemplate {
|
|
4
|
+
const {outDir} = options
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
type: 'template',
|
|
8
|
+
to: '.prettierignore',
|
|
9
|
+
value: [outDir, 'pnpm-lock.yaml', 'yarn.lock', 'package-lock.json'].join('\n'),
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {outdent} from 'outdent'
|
|
2
|
+
import {InjectTemplate} from '../actions/inject'
|
|
3
|
+
import {InitFlags} from '../actions/init'
|
|
4
|
+
|
|
5
|
+
export function tsconfigTemplate(options: {flags: InitFlags}): InjectTemplate {
|
|
6
|
+
const {flags} = options
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
type: 'template',
|
|
10
|
+
force: flags.force,
|
|
11
|
+
to: 'tsconfig.json',
|
|
12
|
+
value: outdent`
|
|
13
|
+
{
|
|
14
|
+
"extends": "./tsconfig.settings",
|
|
15
|
+
"include": ["./src", "./package.config.ts"],
|
|
16
|
+
"compilerOptions": {
|
|
17
|
+
"rootDir": ".",
|
|
18
|
+
"jsx": "react-jsx",
|
|
19
|
+
"noEmit": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function tsconfigTemplateDist(options: {outDir: string; flags: InitFlags}): InjectTemplate {
|
|
27
|
+
const {flags, outDir} = options
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
type: 'template',
|
|
31
|
+
force: flags.force,
|
|
32
|
+
to: `tsconfig.${outDir}.json`,
|
|
33
|
+
value: outdent`
|
|
34
|
+
{
|
|
35
|
+
"extends": "./tsconfig.settings",
|
|
36
|
+
"include": ["./src"],
|
|
37
|
+
"exclude": [
|
|
38
|
+
"./src/**/__fixtures__",
|
|
39
|
+
"./src/**/__mocks__",
|
|
40
|
+
"./src/**/*.test.ts",
|
|
41
|
+
"./src/**/*.test.tsx"
|
|
42
|
+
],
|
|
43
|
+
"compilerOptions": {
|
|
44
|
+
"rootDir": ".",
|
|
45
|
+
"outDir": "./${outDir}",
|
|
46
|
+
"jsx": "react-jsx",
|
|
47
|
+
"emitDeclarationOnly": true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function tsconfigTemplateSettings(options: {flags: InitFlags}): InjectTemplate {
|
|
55
|
+
const {flags} = options
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
type: 'template',
|
|
59
|
+
force: flags.force,
|
|
60
|
+
to: `tsconfig.settings.json`,
|
|
61
|
+
value: outdent`
|
|
62
|
+
{
|
|
63
|
+
"compilerOptions": {
|
|
64
|
+
"moduleResolution": "node",
|
|
65
|
+
"target": "esnext",
|
|
66
|
+
"module": "esnext",
|
|
67
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
68
|
+
"esModuleInterop": true,
|
|
69
|
+
"strict": true,
|
|
70
|
+
"downlevelIteration": true,
|
|
71
|
+
"declaration": true,
|
|
72
|
+
"allowSyntheticDefaultImports": true,
|
|
73
|
+
"skipLibCheck": true,
|
|
74
|
+
"isolatedModules": true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/constants.ts
CHANGED
package/src/index.ts
CHANGED
package/src/npm/package.ts
CHANGED
|
@@ -13,10 +13,27 @@ import {cliName, incompatiblePluginPackage} from '../constants'
|
|
|
13
13
|
import {InjectOptions, PackageData} from '../actions/inject'
|
|
14
14
|
import {expectedScripts} from '../actions/verify/validations'
|
|
15
15
|
import {PackageJson} from '../actions/verify/types'
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
forcedDevPackageVersions,
|
|
18
|
+
forcedPackageVersions,
|
|
19
|
+
forcedPeerPackageVersions,
|
|
20
|
+
} from '../configs/forced-package-versions'
|
|
17
21
|
const defaultDependencies = [incompatiblePluginPackage]
|
|
18
22
|
|
|
19
|
-
const defaultDevDependencies = [
|
|
23
|
+
const defaultDevDependencies = [
|
|
24
|
+
'npm-run-all',
|
|
25
|
+
'rimraf',
|
|
26
|
+
'sanity',
|
|
27
|
+
|
|
28
|
+
// peer dependencies of `sanity`
|
|
29
|
+
'react',
|
|
30
|
+
'react-dom',
|
|
31
|
+
'styled-components',
|
|
32
|
+
|
|
33
|
+
// peer dependencies of `styled-components`
|
|
34
|
+
'react-is',
|
|
35
|
+
]
|
|
36
|
+
|
|
20
37
|
const defaultPeerDependencies = ['react', 'sanity']
|
|
21
38
|
|
|
22
39
|
const readFile = util.promisify(fs.readFile)
|
|
@@ -137,7 +154,7 @@ async function validatePaths(manifest: PackageJson, options: ManifestOptions) {
|
|
|
137
154
|
}
|
|
138
155
|
|
|
139
156
|
// We don't want to reference `./src/MyComponent.js` containing a bunch of JSX and whatnot,
|
|
140
|
-
// instead we want to target `./
|
|
157
|
+
// instead we want to target `./dist/MyComponent.js` which is the location it'll be compiled to
|
|
141
158
|
if (!options?.flags?.allowSourceTarget && paths && withinSourceDir(manifestValue)) {
|
|
142
159
|
throw new Error(
|
|
143
160
|
`Invalid package.json: "${key}" points to file within source (uncompiled) directory. Use --allow-source-target if you really want to do this.`
|
|
@@ -188,7 +205,12 @@ function validateLockFiles(options: {basePath: string}) {
|
|
|
188
205
|
|
|
189
206
|
export async function writePackageJson(data: PackageData, options: InjectOptions) {
|
|
190
207
|
const {user, pluginName, license, description, pkg: prevPkg, gitOrigin} = data
|
|
191
|
-
const {
|
|
208
|
+
const {
|
|
209
|
+
outDir,
|
|
210
|
+
peerDependencies: addPeers,
|
|
211
|
+
dependencies: addDeps,
|
|
212
|
+
devDependencies: addDevDeps,
|
|
213
|
+
} = options
|
|
192
214
|
const {flags} = options
|
|
193
215
|
const prev = prevPkg || {}
|
|
194
216
|
|
|
@@ -200,7 +222,7 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
|
|
|
200
222
|
|
|
201
223
|
if (useTypescript) {
|
|
202
224
|
log.debug('Using TypeScript. Adding to dev dependencies.')
|
|
203
|
-
newDevDependencies.push('typescript')
|
|
225
|
+
newDevDependencies.push('@types/react', 'typescript')
|
|
204
226
|
}
|
|
205
227
|
|
|
206
228
|
if (usePrettier) {
|
|
@@ -228,11 +250,14 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
|
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
log.debug('Resolving latest versions for %s', newDevDependencies.join(', '))
|
|
231
|
-
const dependencies = forceDependencyVersions(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
253
|
+
const dependencies = forceDependencyVersions(
|
|
254
|
+
{
|
|
255
|
+
...(prev.dependencies || {}),
|
|
256
|
+
...(addDeps || {}),
|
|
257
|
+
...(await resolveLatestVersions(defaultDependencies)),
|
|
258
|
+
},
|
|
259
|
+
forcedPackageVersions
|
|
260
|
+
)
|
|
236
261
|
const devDependencies = forceDependencyVersions(
|
|
237
262
|
{
|
|
238
263
|
...(addDevDeps || {}),
|
|
@@ -241,14 +266,22 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
|
|
|
241
266
|
},
|
|
242
267
|
forcedDevPackageVersions
|
|
243
268
|
)
|
|
244
|
-
const peerDependencies = forceDependencyVersions(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
269
|
+
const peerDependencies = forceDependencyVersions(
|
|
270
|
+
{
|
|
271
|
+
...(prev.peerDependencies || {}),
|
|
272
|
+
...(addPeers || {}),
|
|
273
|
+
...(await resolveLatestVersions(defaultPeerDependencies)),
|
|
274
|
+
},
|
|
275
|
+
forcedPeerPackageVersions
|
|
276
|
+
)
|
|
249
277
|
|
|
250
278
|
const source = flags.typescript ? './src/index.ts' : './src/index.js'
|
|
251
279
|
|
|
280
|
+
const files = [outDir, 'sanity.json', 'src', 'v2-incompatible.js']
|
|
281
|
+
|
|
282
|
+
// sort alphabetically for scanability
|
|
283
|
+
files.sort()
|
|
284
|
+
|
|
252
285
|
// order should be compatible with prettier-plugin-packagejson
|
|
253
286
|
const forcedOrder = {
|
|
254
287
|
name: pluginName,
|
|
@@ -261,19 +294,19 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
|
|
|
261
294
|
author: user?.email ? `${user.name} <${user.email}>` : user?.name,
|
|
262
295
|
exports: {
|
|
263
296
|
'.': {
|
|
264
|
-
...(flags.typescript ? {types:
|
|
297
|
+
...(flags.typescript ? {types: `./${outDir}/index.d.ts`} : {}),
|
|
265
298
|
source,
|
|
266
|
-
import:
|
|
267
|
-
require:
|
|
268
|
-
default:
|
|
299
|
+
import: `./${outDir}/index.esm.js`,
|
|
300
|
+
require: `./${outDir}/index.js`,
|
|
301
|
+
default: `./${outDir}/index.esm.js`,
|
|
269
302
|
},
|
|
270
303
|
'./package.json': './package.json',
|
|
271
304
|
},
|
|
272
|
-
main:
|
|
273
|
-
module:
|
|
305
|
+
main: `./${outDir}/index.js`,
|
|
306
|
+
module: `./${outDir}/index.esm.js`,
|
|
274
307
|
source,
|
|
275
|
-
...(flags.typescript ? {types:
|
|
276
|
-
files
|
|
308
|
+
...(flags.typescript ? {types: `./${outDir}/index.d.ts`} : {}),
|
|
309
|
+
files,
|
|
277
310
|
scripts: {...prev.scripts},
|
|
278
311
|
dependencies: sortKeys(dependencies),
|
|
279
312
|
devDependencies: sortKeys(devDependencies),
|
|
@@ -361,13 +394,15 @@ export async function writePackageJsonDirect(manifest: PackageJson, {basePath}:
|
|
|
361
394
|
}
|
|
362
395
|
|
|
363
396
|
export async function addBuildScripts(manifest: PackageJson, options: InjectOptions) {
|
|
397
|
+
const {outDir} = options
|
|
398
|
+
|
|
364
399
|
if (!options.flags.scripts) {
|
|
365
400
|
return false
|
|
366
401
|
}
|
|
367
402
|
return addPackageJsonScripts(manifest, options, (scripts) => {
|
|
368
|
-
scripts.prebuild = addScript('npm run clean && ' + expectedScripts.prebuild, scripts.prebuild)
|
|
369
403
|
scripts.build = addScript(expectedScripts.build, scripts.build)
|
|
370
|
-
scripts.clean = addScript(`rimraf
|
|
404
|
+
scripts.clean = addScript(`rimraf ${outDir}`, scripts.clean)
|
|
405
|
+
scripts.format = addScript(`prettier --write --cache --ignore-unknown .`, scripts.format)
|
|
371
406
|
scripts['link-watch'] = addScript(expectedScripts['link-watch'], scripts['link-watch'])
|
|
372
407
|
scripts.lint = addScript(`eslint .`, scripts.lint)
|
|
373
408
|
scripts.prepublishOnly = addScript(expectedScripts.prepublishOnly, scripts.prepublishOnly)
|
|
@@ -386,7 +421,8 @@ export function sortKeys<T extends Record<string, unknown>>(unordered: T): T {
|
|
|
386
421
|
}, {} as T)
|
|
387
422
|
}
|
|
388
423
|
|
|
389
|
-
|
|
424
|
+
/** @internal */
|
|
425
|
+
export function forceDependencyVersions(
|
|
390
426
|
deps: Record<string, string>,
|
|
391
427
|
versions = forcedPackageVersions
|
|
392
428
|
): Record<string, string> {
|
package/src/presets/presets.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {InjectOptions} from '../actions/inject'
|
|
2
2
|
import {semverWorkflowPreset} from './semver-workflow'
|
|
3
3
|
import {renovatePreset} from './renovatebot'
|
|
4
|
+
import {ui} from './ui'
|
|
4
5
|
import {uiWorkshop} from './ui-workshop'
|
|
5
6
|
|
|
6
7
|
export interface Preset {
|
|
@@ -9,7 +10,7 @@ export interface Preset {
|
|
|
9
10
|
apply: (options: InjectOptions) => Promise<void>
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const presets: Preset[] = [semverWorkflowPreset, renovatePreset, uiWorkshop]
|
|
13
|
+
const presets: Preset[] = [semverWorkflowPreset, renovatePreset, ui, uiWorkshop]
|
|
13
14
|
const presetNames = presets.map((p) => p?.name)
|
|
14
15
|
|
|
15
16
|
export function presetHelpList(padStart: number) {
|
|
@@ -8,5 +8,14 @@ export const renovatePreset: Preset = {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
async function applyPreset(options: InjectOptions) {
|
|
11
|
-
await writeAssets(
|
|
11
|
+
await writeAssets(
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
type: 'copy',
|
|
15
|
+
from: ['renovatebot', 'renovate.json'],
|
|
16
|
+
to: 'renovate.json',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
options
|
|
20
|
+
)
|
|
12
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Injectable, InjectOptions, writeAssets} from '../actions/inject'
|
|
2
2
|
import {resolveLatestVersions} from '../npm/resolveLatestVersions'
|
|
3
3
|
import {Preset} from './presets'
|
|
4
4
|
import {
|
|
@@ -148,19 +148,31 @@ function closeEnough(a: string, b: string) {
|
|
|
148
148
|
return isCloseEnough
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
function semverWorkflowFiles():
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
{from: ['
|
|
159
|
-
{from: ['
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
from: ['
|
|
163
|
-
|
|
151
|
+
function semverWorkflowFiles(): Injectable[] {
|
|
152
|
+
const base: Injectable[] = [
|
|
153
|
+
{
|
|
154
|
+
type: 'copy',
|
|
155
|
+
from: ['.github', 'workflows', 'main.yml'],
|
|
156
|
+
to: ['.github', 'workflows', 'main.yml'],
|
|
157
|
+
},
|
|
158
|
+
{type: 'copy', from: ['.husky', 'commit-msg'], to: ['.husky', 'commit-msg']},
|
|
159
|
+
{type: 'copy', from: ['.husky', 'pre-commit'], to: ['.husky', 'pre-commit']},
|
|
160
|
+
{type: 'copy', from: ['.releaserc.json'], to: '.releaserc.json'},
|
|
161
|
+
{type: 'copy', from: ['npmrc'], to: '.npmrc'},
|
|
162
|
+
{type: 'copy', from: ['commitlint.template.js'], to: 'commitlint.config.js'},
|
|
163
|
+
{type: 'copy', from: ['lint-staged.template.js'], to: 'lint-staged.config.js'},
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
return base.map((fromTo) => {
|
|
167
|
+
if (fromTo.type === 'copy') {
|
|
168
|
+
return {
|
|
169
|
+
...fromTo,
|
|
170
|
+
from: ['semver-workflow', ...fromTo.from],
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return fromTo
|
|
175
|
+
})
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
async function semverWorkflowDependencies(): Promise<Record<string, string>> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Preset} from './presets'
|
|
2
|
-
import {
|
|
2
|
+
import {Injectable, InjectOptions, writeAssets} from '../actions/inject'
|
|
3
3
|
import {getPackage, sortKeys, writePackageJsonDirect} from '../npm/package'
|
|
4
4
|
import log from '../util/log'
|
|
5
5
|
import chalk from 'chalk'
|
|
@@ -32,16 +32,32 @@ async function applyPreset(options: InjectOptions) {
|
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function files():
|
|
36
|
-
|
|
37
|
-
{from: ['workshop.config.ts'], to: ['workshop.config.ts']},
|
|
38
|
-
{from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx']},
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
function files(): Injectable[] {
|
|
36
|
+
const base: Injectable[] = [
|
|
37
|
+
{type: 'copy', from: ['workshop.config.ts'], to: ['workshop.config.ts']},
|
|
38
|
+
{type: 'copy', from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx']},
|
|
39
|
+
{
|
|
40
|
+
type: 'copy',
|
|
41
|
+
from: ['src', '__workshop__', 'index.tsx'],
|
|
42
|
+
to: ['src', '__workshop__', 'index.tsx'],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'copy',
|
|
46
|
+
from: ['src', '__workshop__', 'props.tsx'],
|
|
47
|
+
to: ['src', '__workshop__', 'props.tsx'],
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
return base.map((fromTo) => {
|
|
52
|
+
if (fromTo.type === 'copy') {
|
|
53
|
+
return {
|
|
54
|
+
...fromTo,
|
|
55
|
+
from: ['ui-workshop', ...fromTo.from],
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return fromTo
|
|
60
|
+
})
|
|
45
61
|
}
|
|
46
62
|
|
|
47
63
|
async function updateGitIgnore(options: InjectOptions) {
|
|
@@ -76,6 +92,6 @@ async function devDependencies(): Promise<Record<string, string>> {
|
|
|
76
92
|
'@sanity/ui',
|
|
77
93
|
'react',
|
|
78
94
|
'react-dom',
|
|
79
|
-
'styled-
|
|
95
|
+
'styled-components',
|
|
80
96
|
])
|
|
81
97
|
}
|