@sanity/plugin-kit 4.0.20 → 5.0.1
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/assets/inject/semver-workflow/.github/workflows/main.yml +3 -3
- package/assets/inject/semver-workflow/.husky/commit-msg +0 -0
- package/assets/inject/semver-workflow/.husky/pre-commit +0 -0
- package/assets/inject/ui-workshop/src/__workshop__/props.tsx +2 -1
- package/bin/plugin-kit.js +3 -1
- package/dist/{_chunks-cjs/cli.js → _chunks-es/index.js} +53 -63
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/{_chunks-cjs/init2.js → _chunks-es/init.js} +25 -23
- package/dist/_chunks-es/init.js.map +1 -0
- package/dist/_chunks-es/init2.js +140 -0
- package/dist/_chunks-es/init2.js.map +1 -0
- package/{src/cmds/inject.ts → dist/_chunks-es/inject.js} +18 -32
- package/dist/{_chunks-cjs → _chunks-es}/inject.js.map +1 -1
- package/dist/_chunks-es/link-watch.js +91 -0
- package/dist/_chunks-es/link-watch.js.map +1 -0
- package/dist/_chunks-es/load-package-config.js +22 -0
- package/dist/_chunks-es/load-package-config.js.map +1 -0
- package/dist/_chunks-es/package.js +1759 -0
- package/dist/_chunks-es/package.js.map +1 -0
- package/dist/_chunks-es/package2.js +9 -0
- package/dist/{_chunks-cjs → _chunks-es}/package2.js.map +1 -1
- package/dist/_chunks-es/ts.js +171 -0
- package/dist/_chunks-es/ts.js.map +1 -0
- package/dist/_chunks-es/verify-package.js +92 -0
- package/dist/_chunks-es/verify-package.js.map +1 -0
- package/dist/_chunks-es/verify-studio.js +61 -0
- package/dist/_chunks-es/verify-studio.js.map +1 -0
- package/dist/_chunks-es/version.js +50 -0
- package/dist/_chunks-es/version.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +58 -116
- package/LICENSE +0 -21
- package/dist/_chunks-cjs/cli.js.map +0 -1
- package/dist/_chunks-cjs/init.js +0 -892
- package/dist/_chunks-cjs/init.js.map +0 -1
- package/dist/_chunks-cjs/init2.js.map +0 -1
- package/dist/_chunks-cjs/inject.js +0 -54
- package/dist/_chunks-cjs/link-watch.js +0 -84
- package/dist/_chunks-cjs/link-watch.js.map +0 -1
- package/dist/_chunks-cjs/package.js +0 -1809
- package/dist/_chunks-cjs/package.js.map +0 -1
- package/dist/_chunks-cjs/package2.js +0 -8
- package/dist/_chunks-cjs/ts.js +0 -160732
- package/dist/_chunks-cjs/ts.js.map +0 -1
- package/dist/_chunks-cjs/verify-package.js +0 -75
- package/dist/_chunks-cjs/verify-package.js.map +0 -1
- package/dist/_chunks-cjs/verify-studio.js +0 -57
- package/dist/_chunks-cjs/verify-studio.js.map +0 -1
- package/dist/_chunks-cjs/version.js +0 -51
- package/dist/_chunks-cjs/version.js.map +0 -1
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +0 -6
- package/dist/cli.js.map +0 -1
- package/src/actions/init.ts +0 -95
- package/src/actions/inject.ts +0 -399
- package/src/actions/link-watch.ts +0 -98
- package/src/actions/verify/types.ts +0 -56
- package/src/actions/verify/validations.ts +0 -505
- package/src/actions/verify/verify-common.ts +0 -93
- package/src/actions/verify-package.ts +0 -103
- package/src/actions/verify-studio.ts +0 -58
- package/src/cli.ts +0 -77
- package/src/cmds/index.ts +0 -20
- package/src/cmds/init.ts +0 -90
- package/src/cmds/link-watch.ts +0 -50
- package/src/cmds/verify-package.ts +0 -36
- package/src/cmds/verify-studio.ts +0 -36
- package/src/cmds/version.ts +0 -67
- package/src/configs/banned-packages.ts +0 -27
- package/src/configs/buildExtensions.ts +0 -1
- package/src/configs/default-source.ts +0 -64
- package/src/configs/eslint.ts +0 -51
- package/src/configs/forced-package-versions.ts +0 -12
- package/src/configs/git.ts +0 -68
- package/src/configs/pkg-config.ts +0 -30
- package/src/configs/prettier.ts +0 -11
- package/src/configs/tsconfig.ts +0 -78
- package/src/configs/uselessFiles.ts +0 -29
- package/src/constants.ts +0 -15
- package/src/dependencies/find.ts +0 -193
- package/src/dependencies/import-linter.ts +0 -95
- package/src/index.ts +0 -1
- package/src/npm/manager.ts +0 -44
- package/src/npm/package.ts +0 -427
- package/src/npm/publish.ts +0 -9
- package/src/npm/resolveLatestVersions.ts +0 -31
- package/src/presets/presets.ts +0 -54
- package/src/presets/renovatebot.ts +0 -21
- package/src/presets/semver-workflow.ts +0 -186
- package/src/presets/ui-workshop.ts +0 -97
- package/src/presets/ui.ts +0 -67
- package/src/sanity/manifest.ts +0 -340
- package/src/sharedFlags.ts +0 -14
- package/src/util/command-parser.ts +0 -36
- package/src/util/errorToUndefined.ts +0 -7
- package/src/util/files.ts +0 -260
- package/src/util/log.ts +0 -44
- package/src/util/prompt.ts +0 -70
- package/src/util/readme.ts +0 -88
- package/src/util/request.ts +0 -11
- package/src/util/ts.ts +0 -19
- package/src/util/user.ts +0 -129
|
@@ -45,7 +45,7 @@ jobs:
|
|
|
45
45
|
runs-on: ubuntu-latest
|
|
46
46
|
name: Lint & Build
|
|
47
47
|
steps:
|
|
48
|
-
- uses: actions/checkout@
|
|
48
|
+
- uses: actions/checkout@v5
|
|
49
49
|
- uses: actions/setup-node@v4
|
|
50
50
|
with:
|
|
51
51
|
cache: npm
|
|
@@ -85,7 +85,7 @@ jobs:
|
|
|
85
85
|
run: |
|
|
86
86
|
git config --global core.autocrlf false
|
|
87
87
|
git config --global core.eol lf
|
|
88
|
-
- uses: actions/checkout@
|
|
88
|
+
- uses: actions/checkout@v5
|
|
89
89
|
- uses: actions/setup-node@v4
|
|
90
90
|
with:
|
|
91
91
|
cache: npm
|
|
@@ -105,7 +105,7 @@ jobs:
|
|
|
105
105
|
runs-on: ubuntu-latest
|
|
106
106
|
name: Semantic release
|
|
107
107
|
steps:
|
|
108
|
-
- uses: actions/checkout@
|
|
108
|
+
- uses: actions/checkout@v5
|
|
109
109
|
with:
|
|
110
110
|
# Need to fetch entire commit history to
|
|
111
111
|
# analyze every commit since last release
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {Box, Card, Container, Text} from '@sanity/ui'
|
|
2
2
|
import {useString} from '@sanity/ui-workshop'
|
|
3
|
-
import {CustomField} from '../CustomField'
|
|
4
3
|
import React from 'react'
|
|
5
4
|
|
|
5
|
+
import {CustomField} from '../CustomField'
|
|
6
|
+
|
|
6
7
|
export default function PropsStory() {
|
|
7
8
|
const title = useString('Title', 'My custom field')
|
|
8
9
|
|
package/bin/plugin-kit.js
CHANGED
|
@@ -1,59 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
|
-
}
|
|
6
|
-
var meow__default = /* @__PURE__ */ _interopDefaultCompat(meow), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk);
|
|
7
|
-
let beQuiet = !1, beVerbose = !1;
|
|
8
|
-
function setVerbosity({ verbose, silent }) {
|
|
9
|
-
silent ? (beVerbose = !1, beQuiet = !0) : verbose && (beVerbose = !0, beQuiet = !1);
|
|
10
|
-
}
|
|
11
|
-
var log = {
|
|
12
|
-
setVerbosity,
|
|
13
|
-
// Bypasses any checks, prints regardless (only use for things like `cli --version`)
|
|
14
|
-
msg: (msg, ...args) => !beQuiet && console.log(msg, ...args),
|
|
15
|
-
// Debug only printed on --verbose
|
|
16
|
-
debug: (msg, ...args) => !beQuiet && beVerbose && console.debug(`${chalk__default.default.bgBlack.white("[debug]")} ${msg}`, ...args),
|
|
17
|
-
// Success messages only printed if not --silent
|
|
18
|
-
success: (msg, ...args) => !beQuiet && console.info(`${chalk__default.default.bgBlack.greenBright("[success]")} ${msg}`, ...args),
|
|
19
|
-
// Info only printed if not --silent ("standard" level)
|
|
20
|
-
info: (msg, ...args) => !beQuiet && console.info(`${chalk__default.default.bgBlack.cyanBright("[info]")} ${msg}`, ...args),
|
|
21
|
-
// Warning only printed if not --silent
|
|
22
|
-
warn: (msg, ...args) => !beQuiet && console.warn(`${chalk__default.default.bgBlack.yellowBright("[warn]")} ${msg}`, ...args),
|
|
23
|
-
// Errors are always printed
|
|
24
|
-
error: (msg, ...args) => console.error(`${chalk__default.default.bgBlack.redBright("[error]")} ${msg}`, ...args)
|
|
25
|
-
}, commands = {
|
|
1
|
+
import meow from "meow";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var commands = {
|
|
26
4
|
init: async (options) => {
|
|
27
|
-
await (await
|
|
28
|
-
return require("./init2.js");
|
|
29
|
-
})).default(options);
|
|
5
|
+
await (await import("./init.js")).default(options);
|
|
30
6
|
},
|
|
31
7
|
inject: async (options) => {
|
|
32
|
-
await (await
|
|
33
|
-
return require("./inject.js");
|
|
34
|
-
})).default(options);
|
|
8
|
+
await (await import("./inject.js")).default(options);
|
|
35
9
|
},
|
|
36
10
|
"link-watch": async (options) => {
|
|
37
|
-
await (await
|
|
38
|
-
return require("./link-watch.js");
|
|
39
|
-
})).default(options);
|
|
11
|
+
await (await import("./link-watch.js")).default(options);
|
|
40
12
|
},
|
|
41
13
|
"verify-package": async (options) => {
|
|
42
|
-
await (await
|
|
43
|
-
return require("./verify-package.js");
|
|
44
|
-
})).default(options);
|
|
14
|
+
await (await import("./verify-package.js")).default(options);
|
|
45
15
|
},
|
|
46
16
|
"verify-studio": async (options) => {
|
|
47
|
-
await (await
|
|
48
|
-
return require("./verify-studio.js");
|
|
49
|
-
})).default(options);
|
|
17
|
+
await (await import("./verify-studio.js")).default(options);
|
|
50
18
|
},
|
|
51
19
|
version: async (options) => {
|
|
52
|
-
await (
|
|
53
|
-
return require("./version.js");
|
|
54
|
-
})).default(options);
|
|
20
|
+
(await import("./version.js")).default(options);
|
|
55
21
|
}
|
|
56
|
-
}
|
|
22
|
+
};
|
|
23
|
+
const cliName = "@sanity/plugin-kit", urls = {
|
|
24
|
+
refDocs: "https://beta.sanity.io/docs/reference",
|
|
25
|
+
migrationGuideStudio: "https://beta.sanity.io/docs/platform/v2-to-v3",
|
|
26
|
+
migrationGuidePlugin: "https://beta.sanity.io/docs/platform/v2-to-v3/plugins",
|
|
27
|
+
pluginReadme: "https://github.com/sanity-io/plugin-kit",
|
|
28
|
+
incompatiblePlugin: "https://github.com/sanity-io/incompatible-plugin",
|
|
29
|
+
sanityExchange: "https://www.sanity.io/exchange",
|
|
30
|
+
linterPackage: "https://github.com/sanity-io/eslint-config-no-v2-imports"
|
|
31
|
+
}, incompatiblePluginPackage = "@sanity/incompatible-plugin", defaultOutDir = "dist", minPkgUtilsMajor = 10, requiredNodeEngine = ">=20.19 <22 || >=22.12";
|
|
32
|
+
var sharedFlags = {
|
|
57
33
|
debug: {
|
|
58
34
|
default: !1,
|
|
59
35
|
type: "boolean"
|
|
@@ -67,17 +43,27 @@ var log = {
|
|
|
67
43
|
default: !1
|
|
68
44
|
}
|
|
69
45
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
46
|
+
let beQuiet = !1, beVerbose = !1;
|
|
47
|
+
function setVerbosity({ verbose, silent }) {
|
|
48
|
+
silent ? (beVerbose = !1, beQuiet = !0) : verbose && (beVerbose = !0, beQuiet = !1);
|
|
49
|
+
}
|
|
50
|
+
var log = {
|
|
51
|
+
setVerbosity,
|
|
52
|
+
// Bypasses any checks, prints regardless (only use for things like `cli --version`)
|
|
53
|
+
msg: (msg, ...args) => !beQuiet && console.log(msg, ...args),
|
|
54
|
+
// Debug only printed on --verbose
|
|
55
|
+
debug: (msg, ...args) => !beQuiet && beVerbose && console.debug(`${chalk.bgBlack.white("[debug]")} ${msg}`, ...args),
|
|
56
|
+
// Success messages only printed if not --silent
|
|
57
|
+
success: (msg, ...args) => !beQuiet && console.info(`${chalk.bgBlack.greenBright("[success]")} ${msg}`, ...args),
|
|
58
|
+
// Info only printed if not --silent ("standard" level)
|
|
59
|
+
info: (msg, ...args) => !beQuiet && console.info(`${chalk.bgBlack.cyanBright("[info]")} ${msg}`, ...args),
|
|
60
|
+
// Warning only printed if not --silent
|
|
61
|
+
warn: (msg, ...args) => !beQuiet && console.warn(`${chalk.bgBlack.yellowBright("[warn]")} ${msg}`, ...args),
|
|
62
|
+
// Errors are always printed
|
|
63
|
+
error: (msg, ...args) => console.error(`${chalk.bgBlack.redBright("[error]")} ${msg}`, ...args)
|
|
64
|
+
};
|
|
65
|
+
async function cliEntry(argv = process.argv) {
|
|
66
|
+
const cli = meow(
|
|
81
67
|
`
|
|
82
68
|
Usage
|
|
83
69
|
$ ${cliName} [--help] [--debug] <command> [<args>]
|
|
@@ -125,11 +111,15 @@ async function cliEntry(argv = process.argv, autoExit = !0) {
|
|
|
125
111
|
log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message), process.exit(1);
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
export {
|
|
115
|
+
cliEntry,
|
|
116
|
+
cliName,
|
|
117
|
+
defaultOutDir,
|
|
118
|
+
incompatiblePluginPackage,
|
|
119
|
+
log,
|
|
120
|
+
minPkgUtilsMajor,
|
|
121
|
+
requiredNodeEngine,
|
|
122
|
+
sharedFlags,
|
|
123
|
+
urls
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/cmds/index.ts","../../src/constants.ts","../../src/sharedFlags.ts","../../src/util/log.ts","../../src/cli.ts"],"sourcesContent":["export default {\n 'init': async (options: {argv: string[]}) => {\n await (await import('./init')).default(options)\n },\n 'inject': async (options: {argv: string[]}) => {\n await (await import('./inject')).default(options)\n },\n 'link-watch': async (options: {argv: string[]}) => {\n await (await import('./link-watch')).default(options)\n },\n 'verify-package': async (options: {argv: string[]}) => {\n await (await import('./verify-package')).default(options)\n },\n 'verify-studio': async (options: {argv: string[]}) => {\n await (await import('./verify-studio')).default(options)\n },\n 'version': async (options: {argv: string[]}) => {\n ;(await import('./version')).default(options)\n },\n}\n","export const cliName = '@sanity/plugin-kit'\n\nexport const urls = {\n refDocs: 'https://beta.sanity.io/docs/reference',\n migrationGuideStudio: 'https://beta.sanity.io/docs/platform/v2-to-v3',\n migrationGuidePlugin: 'https://beta.sanity.io/docs/platform/v2-to-v3/plugins',\n pluginReadme: 'https://github.com/sanity-io/plugin-kit',\n incompatiblePlugin: 'https://github.com/sanity-io/incompatible-plugin',\n sanityExchange: 'https://www.sanity.io/exchange',\n linterPackage: 'https://github.com/sanity-io/eslint-config-no-v2-imports',\n}\n\nexport const incompatiblePluginPackage = '@sanity/incompatible-plugin'\n\nexport const defaultOutDir = 'dist'\n\n/**\n * Minimum major version of `@sanity/pkg-utils` required in userland.\n *\n * plugin-kit loads `package.config.ts` via the plugin's own `@sanity/pkg-utils` (a peer\n * dependency) using the `loadConfig({cwd, pkgPath})` signature introduced in v10. Older majors\n * expose an incompatible `loadConfig({cwd})` and cannot reliably load ESM TypeScript configs.\n */\nexport const minPkgUtilsMajor = 10\n\n/**\n * Required `engines.node` range for plugins, matching `@sanity/pkg-utils` so plugins declare the\n * same Node.js support as the build tool they use.\n */\nexport const requiredNodeEngine = '>=20.19 <22 || >=22.12'\n","export default {\n debug: {\n default: false,\n type: 'boolean',\n },\n silent: {\n type: 'boolean',\n default: false,\n },\n verbose: {\n type: 'boolean',\n default: false,\n },\n} as const\n","// Note: This is _specifically_ meant for CLI usage,\n// I realize that \"singletons\" are bad.\n\nimport chalk from 'chalk'\n\nlet beQuiet = false\nlet beVerbose = false\n\nfunction setVerbosity({verbose, silent}: {verbose: boolean; silent: boolean}) {\n if (silent) {\n beVerbose = false\n beQuiet = true\n } else if (verbose) {\n beVerbose = true\n beQuiet = false\n }\n}\n\nexport default {\n setVerbosity: setVerbosity,\n\n // Bypasses any checks, prints regardless (only use for things like `cli --version`)\n msg: (msg: any, ...args: any[]) => !beQuiet && console.log(msg, ...args),\n\n // Debug only printed on --verbose\n debug: (msg: any, ...args: any[]) =>\n !beQuiet && beVerbose && console.debug(`${chalk.bgBlack.white('[debug]')} ${msg}`, ...args),\n\n // Success messages only printed if not --silent\n success: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.greenBright('[success]')} ${msg}`, ...args),\n\n // Info only printed if not --silent (\"standard\" level)\n info: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.cyanBright('[info]')} ${msg}`, ...args),\n\n // Warning only printed if not --silent\n warn: (msg: any, ...args: any[]) =>\n !beQuiet && console.warn(`${chalk.bgBlack.yellowBright('[warn]')} ${msg}`, ...args),\n\n // Errors are always printed\n error: (msg: any, ...args: any[]) =>\n console.error(`${chalk.bgBlack.redBright('[error]')} ${msg}`, ...args),\n}\n","import meow from 'meow'\n\nimport commands from './cmds'\nimport {cliName} from './constants'\nimport sharedFlags from './sharedFlags'\nimport log from './util/log'\n\n/** @public */\nexport async function cliEntry(argv = process.argv) {\n const cli = meow(\n `\n\tUsage\n\t $ ${cliName} [--help] [--debug] <command> [<args>]\n\n These are common commands used in various situations:\n\n init Create a new Sanity plugin\n inject Inject config into an existing Sanity v3 plugin\n verify-package Check that a Sanity plugin package follows V3 conventions. Prints upgrade steps.\n verify-studio Check that a Sanity Studio follows V3 conventions. Prints upgrade steps.\n link-watch Recompiles plugin automatically on changes and runs yalc push --publish\n version Show the version of ${cliName} currently installed\n\n Options\n --silent Do not print info and warning messages\n --verbose Log everything. This option conflicts with --silent\n --debug Print stack trace on errors\n --version Output the version number\n --help Output usage information\n\n Examples\n # Init a new plugin in current directory\n $ ${cliName} init\n\n # Init a new plugin in my-sanity-plugin directory\n $ ${cliName} init my-sanity-plugin\n\n # Check that a Sanity plugin package in current directory follows V3 conventions\n $ ${cliName} verify-package\n\n # Check that a Sanity Studio in current directory follows V3 conventions\n $ ${cliName} verify-studio\n`,\n {\n autoHelp: false,\n flags: sharedFlags,\n argv: argv.slice(2),\n },\n )\n\n const commandName = cli.input[0]\n if (!commandName) {\n cli.showHelp() // Exits\n }\n\n if (!(commandName in commands)) {\n console.error(`Unknown command \"${commandName}\"`)\n cli.showHelp() // Exits\n }\n\n if (cli.flags.silent && cli.flags.verbose) {\n log.error(`--silent and --verbose are mutually exclusive`)\n cli.showHelp() // Exits\n }\n\n // Lazy-load command\n const cmd = commands[commandName as keyof typeof commands]\n\n try {\n log.setVerbosity(cli.flags)\n await cmd({argv: argv.slice(3)})\n } catch (err: any) {\n log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message)\n\n process.exit(1)\n }\n}\n"],"names":[],"mappings":";;AAAA,IAAA,WAAe;AAAA,EACb,MAAQ,OAAO,YAA8B;AAC3C,WAAO,MAAM,OAAO,WAAQ,GAAG,QAAQ,OAAO;AAAA,EAChD;AAAA,EACA,QAAU,OAAO,YAA8B;AAC7C,WAAO,MAAM,OAAO,aAAU,GAAG,QAAQ,OAAO;AAAA,EAClD;AAAA,EACA,cAAc,OAAO,YAA8B;AACjD,WAAO,MAAM,OAAO,iBAAc,GAAG,QAAQ,OAAO;AAAA,EACtD;AAAA,EACA,kBAAkB,OAAO,YAA8B;AACrD,WAAO,MAAM,OAAO,qBAAkB,GAAG,QAAQ,OAAO;AAAA,EAC1D;AAAA,EACA,iBAAiB,OAAO,YAA8B;AACpD,WAAO,MAAM,OAAO,oBAAiB,GAAG,QAAQ,OAAO;AAAA,EACzD;AAAA,EACA,SAAW,OAAO,YAA8B;AAC7C,KAAC,MAAM,OAAO,cAAW,GAAG,QAAQ,OAAO;AAAA,EAC9C;AACF;ACnBO,MAAM,UAAU,sBAEV,OAAO;AAAA,EAClB,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,eAAe;AACjB,GAEa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,MAAM;AAClD,QAAM,MAAM;AAAA,IACV;AAAA;AAAA,OAEG,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0CAS4B,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAWzC,OAAO;AAAA;AAAA;AAAA,QAGP,OAAO;AAAA;AAAA;AAAA,QAGP,OAAO;AAAA;AAAA;AAAA,QAGP,OAAO;AAAA;AAAA,IAEX;AAAA,MACE,UAAU;AAAA,MACV,OAAO;AAAA,MACP,MAAM,KAAK,MAAM,CAAC;AAAA,IAAA;AAAA,EACpB,GAGI,cAAc,IAAI,MAAM,CAAC;AAC1B,iBACH,IAAI,YAGA,eAAe,aACnB,QAAQ,MAAM,oBAAoB,WAAW,GAAG,GAChD,IAAI,aAGF,IAAI,MAAM,UAAU,IAAI,MAAM,YAChC,IAAI,MAAM,+CAA+C,GACzD,IAAI,SAAA;AAIN,QAAM,MAAM,SAAS,WAAoC;AAEzD,MAAI;AACF,QAAI,aAAa,IAAI,KAAK,GAC1B,MAAM,IAAI,EAAC,MAAM,KAAK,MAAM,CAAC,EAAA,CAAE;AAAA,EACjC,SAAS,KAAU;AACjB,QAAI,MAAM,eAAe,aAAa,IAAI,MAAM,QAAQ,IAAI,QAAQ,IAAI,OAAO,GAE/E,QAAQ,KAAK,CAAC;AAAA,EAChB;AACF;"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import meow from "meow";
|
|
3
|
+
import { initFlags, init } from "./init2.js";
|
|
4
|
+
import { cliName, log } from "./index.js";
|
|
5
|
+
import execa from "execa";
|
|
6
|
+
import { prompt, hasSanityJson, findStudioV3Config, isEmptyish, ensureDir, presetHelpList } from "./package.js";
|
|
7
7
|
function npmIsAvailable() {
|
|
8
|
-
return
|
|
8
|
+
return execa("npm", ["-v"]).then(() => !0).catch(() => !1);
|
|
9
9
|
}
|
|
10
10
|
function yarnIsAvailable() {
|
|
11
|
-
return
|
|
11
|
+
return execa("yarn", ["-v"]).then(() => !0).catch(() => !1);
|
|
12
12
|
}
|
|
13
13
|
function pnpmAvailable() {
|
|
14
|
-
return
|
|
14
|
+
return execa("pnpm", ["-v"]).then(() => !0).catch(() => !1);
|
|
15
15
|
}
|
|
16
16
|
async function promptForPackageManager() {
|
|
17
17
|
const [npm, yarn, pnpm] = await Promise.all([
|
|
@@ -19,18 +19,18 @@ async function promptForPackageManager() {
|
|
|
19
19
|
yarnIsAvailable(),
|
|
20
20
|
pnpmAvailable()
|
|
21
21
|
]), choices = [npm && "npm", yarn && "yarn", pnpm && "pnpm"].filter(Boolean);
|
|
22
|
-
return choices.length < 2 ? choices[0] || "npm" :
|
|
22
|
+
return choices.length < 2 ? choices[0] || "npm" : prompt("Which package manager do you prefer?", {
|
|
23
23
|
choices: choices.map((value) => ({ value, name: value })),
|
|
24
24
|
default: choices[0]
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
async function installDependencies(pm, { cwd }) {
|
|
28
|
-
const proc =
|
|
28
|
+
const proc = execa(pm, ["install"], { cwd, stdio: "inherit" }), { exitCode } = await proc;
|
|
29
29
|
return exitCode <= 0;
|
|
30
30
|
}
|
|
31
31
|
const description = "Initialize a new Sanity plugin", help = `
|
|
32
32
|
Usage
|
|
33
|
-
$ ${
|
|
33
|
+
$ ${cliName} init [dir] [<args>]
|
|
34
34
|
|
|
35
35
|
Options
|
|
36
36
|
--no-eslint Disables ESLint config and dependencies from being added
|
|
@@ -50,34 +50,36 @@ Options
|
|
|
50
50
|
|
|
51
51
|
--preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.
|
|
52
52
|
The following presets are available:
|
|
53
|
-
${
|
|
53
|
+
${presetHelpList(30)}
|
|
54
54
|
|
|
55
55
|
Examples
|
|
56
56
|
# Initialize a new plugin in the current directory
|
|
57
|
-
$ ${
|
|
57
|
+
$ ${cliName} init
|
|
58
58
|
|
|
59
59
|
# Initialize a plugin in the directory ~/my-plugin
|
|
60
|
-
$ ${
|
|
60
|
+
$ ${cliName} init ~/my-plugin
|
|
61
61
|
|
|
62
62
|
# Don't add eslint or prettier
|
|
63
|
-
$ ${
|
|
63
|
+
$ ${cliName} init --no-eslint --no-prettier
|
|
64
64
|
`;
|
|
65
65
|
async function run({ argv }) {
|
|
66
|
-
const cli
|
|
66
|
+
const cli = meow(help, { flags: initFlags, argv, description }), basePath = path.resolve(cli.input[0] || process.cwd()), { exists, isRoot } = await hasSanityJson(basePath);
|
|
67
67
|
if (exists && isRoot)
|
|
68
68
|
throw new Error(
|
|
69
69
|
'sanity.json has a "root" property set to true - are you trying to init into a studio instead of a plugin?'
|
|
70
70
|
);
|
|
71
|
-
const { v3ConfigFile } = await
|
|
71
|
+
const { v3ConfigFile } = await findStudioV3Config(basePath);
|
|
72
72
|
if (v3ConfigFile)
|
|
73
73
|
throw new Error(
|
|
74
74
|
`${v3ConfigFile} exsists - are you trying to init into a studio instead of a plugin?`
|
|
75
75
|
);
|
|
76
|
-
if (
|
|
77
|
-
|
|
76
|
+
if (log.info('Initializing new plugin in "%s"', basePath), !cli.flags.force && !await isEmptyish(basePath) && !await prompt("Directory is not empty, proceed?", { type: "confirm", default: !1 })) {
|
|
77
|
+
log.error("Directory is not empty. Cancelled.");
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
await
|
|
80
|
+
await ensureDir(basePath), await init({ basePath, flags: cli.flags }), cli.flags.install ? await installDependencies(await promptForPackageManager(), { cwd: basePath }) ? log.info("Done!") : log.error("Failed to install dependencies, try manually running `npm install`") : log.info("Dependency installation skipped.");
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
export {
|
|
83
|
+
run as default
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sources":["../../src/npm/manager.ts","../../src/cmds/init.ts"],"sourcesContent":["import execa from 'execa'\n\nimport {prompt} from '../util/prompt'\n\nfunction npmIsAvailable() {\n return execa('npm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nfunction yarnIsAvailable() {\n return execa('yarn', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nfunction pnpmAvailable() {\n return execa('pnpm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport async function promptForPackageManager() {\n const [npm, yarn, pnpm] = await Promise.all([\n npmIsAvailable(),\n yarnIsAvailable(),\n pnpmAvailable(),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm'].filter(Boolean)\n if (choices.length < 2) {\n return choices[0] || 'npm'\n }\n\n return prompt('Which package manager do you prefer?', {\n choices: choices.map((value) => ({value, name: value})),\n default: choices[0],\n })\n}\n\nexport async function installDependencies(pm: string, {cwd}: {cwd?: string}) {\n const proc = execa(pm, ['install'], {cwd, stdio: 'inherit'})\n const {exitCode} = await proc\n return exitCode <= 0\n}\n","import path from 'path'\n\nimport meow from 'meow'\n\nimport {init, initFlags} from '../actions/init'\nimport {cliName} from '../constants'\nimport {installDependencies, promptForPackageManager} from '../npm/manager'\nimport {presetHelpList} from '../presets/presets'\nimport {findStudioV3Config, hasSanityJson} from '../sanity/manifest'\nimport {isEmptyish, ensureDir} from '../util/files'\nimport log from '../util/log'\nimport {prompt} from '../util/prompt'\n\nconst description = `Initialize a new Sanity plugin`\n\nconst help = `\nUsage\n $ ${cliName} init [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n --no-install Disables automatically running package manager install\n\n --name [package-name] Use the provided package-name\n --author [name] Use the provided author\n --repo [url] Use the provided repo url\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n${presetHelpList(30)}\n\nExamples\n # Initialize a new plugin in the current directory\n $ ${cliName} init\n\n # Initialize a plugin in the directory ~/my-plugin\n $ ${cliName} init ~/my-plugin\n\n # Don't add eslint or prettier\n $ ${cliName} init --no-eslint --no-prettier\n`\n\nasync function run({argv}: {argv: string[]}) {\n const cli = meow(help, {flags: initFlags, argv, description})\n const basePath = path.resolve(cli.input[0] || process.cwd())\n\n const {exists, isRoot} = await hasSanityJson(basePath)\n if (exists && isRoot) {\n throw new Error(\n `sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?`,\n )\n }\n\n const {v3ConfigFile} = await findStudioV3Config(basePath)\n if (v3ConfigFile) {\n throw new Error(\n `${v3ConfigFile} exsists - are you trying to init into a studio instead of a plugin?`,\n )\n }\n\n log.info('Initializing new plugin in \"%s\"', basePath)\n if (\n !cli.flags.force &&\n !(await isEmptyish(basePath)) &&\n !(await prompt('Directory is not empty, proceed?', {type: 'confirm', default: false}))\n ) {\n log.error('Directory is not empty. Cancelled.')\n return\n }\n\n await ensureDir(basePath)\n await init({basePath, flags: cli.flags})\n if (cli.flags.install) {\n if (await installDependencies(await promptForPackageManager(), {cwd: basePath})) {\n log.info('Done!')\n } else {\n log.error('Failed to install dependencies, try manually running `npm install`')\n }\n } else {\n log.info('Dependency installation skipped.')\n }\n}\n\nexport default run\n"],"names":[],"mappings":";;;;;;AAIA,SAAS,iBAAiB;AACxB,SAAO,MAAM,OAAO,CAAC,IAAI,CAAC,EACvB,KAAK,MAAM,EAAI,EACf,MAAM,MAAM,EAAK;AACtB;AAEA,SAAS,kBAAkB;AACzB,SAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,EACxB,KAAK,MAAM,EAAI,EACf,MAAM,MAAM,EAAK;AACtB;AAEA,SAAS,gBAA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,UAAU;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAIJ,QAAM,EAAC,aAAA,IAAgB,MAAM,mBAAmB,QAAQ;AACxD,MAAI;AACF,UAAM,IAAI;AAAA,MACR,GAAG,YAAY;AAAA,IAAA;AAKnB,MADA,IAAI,KAAK,mCAAmC,QAAQ,GAElD,CAAC,IAAI,MAAM,SACX,CAAE,MAAM,WAAW,QAAQ,KAC3B,CAAE,MAAM,OAAO,oCAAoC,EAAC,MAAM,WAAW,SAAS,GAAA,CAAM,GACpF;AACA,QAAI,MAAM,oCAAoC;AAC9C;AAAA,EACF;AAEA,QAAM,UAAU,QAAQ,GACxB,MAAM,KAAK,EAAC,UAAU,OAAO,IAAI,OAAM,GACnC,IAAI,MAAM,UACR,MAAM,oBAAoB,MAAM,wBAAA,GAA2B,EAAC,KAAK,SAAA,CAAS,IAC5E,IAAI,KAAK,OAAO,IAEhB,IAAI,MAAM,oEAAoE,IAGhF,IAAI,KAAK,kCAAkC;AAE/C;"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import outdent from "outdent";
|
|
3
|
+
import { sharedFlags, defaultOutDir } from "./index.js";
|
|
4
|
+
import { inject, getPackage, ensureDir, writeFile } from "./package.js";
|
|
5
|
+
function defaultSourceJs(pkg) {
|
|
6
|
+
return outdent`
|
|
7
|
+
import {definePlugin} from 'sanity'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Usage in sanity.config.js (or .ts)
|
|
11
|
+
*
|
|
12
|
+
* \`\`\`js
|
|
13
|
+
* import {defineConfig} from 'sanity'
|
|
14
|
+
* import {myPlugin} from '${pkg.name}'
|
|
15
|
+
*
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* // ...
|
|
18
|
+
* plugins: [myPlugin({})],
|
|
19
|
+
* })
|
|
20
|
+
* \`\`\`
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const myPlugin = definePlugin((config = {}) => {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log(\`hello from ${pkg.name}\`)
|
|
27
|
+
return {
|
|
28
|
+
name: '${pkg.name}',
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
`.trimStart() + `
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
function defaultSourceTs(pkg) {
|
|
35
|
+
return outdent`
|
|
36
|
+
import {definePlugin} from 'sanity'
|
|
37
|
+
|
|
38
|
+
interface MyPluginConfig {
|
|
39
|
+
/* nothing here yet */
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Usage in \`sanity.config.ts\` (or .js)
|
|
44
|
+
*
|
|
45
|
+
* \`\`\`ts
|
|
46
|
+
* import {defineConfig} from 'sanity'
|
|
47
|
+
* import {myPlugin} from '${pkg.name}'
|
|
48
|
+
*
|
|
49
|
+
* export default defineConfig({
|
|
50
|
+
* // ...
|
|
51
|
+
* plugins: [myPlugin()],
|
|
52
|
+
* })
|
|
53
|
+
* \`\`\`
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export const myPlugin = definePlugin<MyPluginConfig | void>((config = {}) => {
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.log('hello from ${pkg.name}')
|
|
60
|
+
return {
|
|
61
|
+
name: '${pkg.name}',
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
`.trimStart() + `
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
const initFlags = {
|
|
68
|
+
...sharedFlags,
|
|
69
|
+
scripts: {
|
|
70
|
+
type: "boolean",
|
|
71
|
+
default: !0
|
|
72
|
+
},
|
|
73
|
+
eslint: {
|
|
74
|
+
type: "boolean",
|
|
75
|
+
default: !0
|
|
76
|
+
},
|
|
77
|
+
typescript: {
|
|
78
|
+
type: "boolean",
|
|
79
|
+
default: !0
|
|
80
|
+
},
|
|
81
|
+
prettier: {
|
|
82
|
+
type: "boolean",
|
|
83
|
+
default: !0
|
|
84
|
+
},
|
|
85
|
+
license: {
|
|
86
|
+
type: "string"
|
|
87
|
+
},
|
|
88
|
+
editorconfig: {
|
|
89
|
+
type: "boolean",
|
|
90
|
+
default: !0
|
|
91
|
+
},
|
|
92
|
+
gitignore: {
|
|
93
|
+
type: "boolean",
|
|
94
|
+
default: !0
|
|
95
|
+
},
|
|
96
|
+
force: {
|
|
97
|
+
type: "boolean",
|
|
98
|
+
default: !1
|
|
99
|
+
},
|
|
100
|
+
install: {
|
|
101
|
+
type: "boolean",
|
|
102
|
+
default: !0
|
|
103
|
+
},
|
|
104
|
+
name: {
|
|
105
|
+
type: "string"
|
|
106
|
+
},
|
|
107
|
+
author: {
|
|
108
|
+
type: "string"
|
|
109
|
+
},
|
|
110
|
+
repo: {
|
|
111
|
+
type: "string"
|
|
112
|
+
},
|
|
113
|
+
presetOnly: {
|
|
114
|
+
type: "boolean",
|
|
115
|
+
default: !1
|
|
116
|
+
},
|
|
117
|
+
preset: {
|
|
118
|
+
type: "string",
|
|
119
|
+
isMultiple: !0
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
async function init(options) {
|
|
123
|
+
let dependencies = {}, devDependencies = {}, peerDependencies = {};
|
|
124
|
+
await inject({
|
|
125
|
+
...options,
|
|
126
|
+
outDir: defaultOutDir,
|
|
127
|
+
requireUserConfirmation: !options.flags.force,
|
|
128
|
+
dependencies,
|
|
129
|
+
devDependencies,
|
|
130
|
+
peerDependencies,
|
|
131
|
+
validate: !1
|
|
132
|
+
});
|
|
133
|
+
const packageJson = await getPackage({ basePath: options.basePath, validate: !1 }), typescript = options.flags.typescript, source = typescript ? defaultSourceTs(packageJson) : defaultSourceJs(packageJson), filename = typescript ? "index.ts" : "index.js", srcDir = path.resolve(options.basePath, "src");
|
|
134
|
+
await ensureDir(srcDir), await writeFile(path.join(srcDir, filename), source, { encoding: "utf8" });
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
init,
|
|
138
|
+
initFlags
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=init2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init2.js","sources":["../../src/configs/default-source.ts","../../src/actions/init.ts"],"sourcesContent":["import outdent from 'outdent'\n\nimport {PackageJson} from '../actions/verify/types'\n\nexport function defaultSourceJs(pkg: PackageJson) {\n return (\n outdent`\n import {definePlugin} from 'sanity'\n\n /**\n * Usage in sanity.config.js (or .ts)\n *\n * \\`\\`\\`js\n * import {defineConfig} from 'sanity'\n * import {myPlugin} from '${pkg.name}'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin({})],\n * })\n * \\`\\`\\`\n *\n * @public\n */\n export const myPlugin = definePlugin((config = {}) => {\n // eslint-disable-next-line no-console\n console.log(\\`hello from ${pkg.name}\\`)\n return {\n name: '${pkg.name}',\n }\n })\n`.trimStart() + '\\n'\n )\n}\n\nexport function defaultSourceTs(pkg: PackageJson) {\n return (\n outdent`\n import {definePlugin} from 'sanity'\n\n interface MyPluginConfig {\n /* nothing here yet */\n }\n\n /**\n * Usage in \\`sanity.config.ts\\` (or .js)\n *\n * \\`\\`\\`ts\n * import {defineConfig} from 'sanity'\n * import {myPlugin} from '${pkg.name}'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin()],\n * })\n * \\`\\`\\`\n *\n * @public\n */\n export const myPlugin = definePlugin<MyPluginConfig | void>((config = {}) => {\n // eslint-disable-next-line no-console\n console.log('hello from ${pkg.name}')\n return {\n name: '${pkg.name}',\n }\n })\n`.trimStart() + '\\n'\n )\n}\n","import path from 'path'\n\nimport {TypedFlags} from 'meow'\n\nimport {defaultSourceJs, defaultSourceTs} from '../configs/default-source'\nimport {defaultOutDir} from '../constants'\nimport {getPackage} from '../npm/package'\nimport sharedFlags from '../sharedFlags'\nimport {ensureDir, writeFile} from '../util/files'\nimport {inject} from './inject'\n\nexport const initFlags = {\n ...sharedFlags,\n scripts: {\n type: 'boolean',\n default: true,\n },\n eslint: {\n type: 'boolean',\n default: true,\n },\n typescript: {\n type: 'boolean',\n default: true,\n },\n prettier: {\n type: 'boolean',\n default: true,\n },\n license: {\n type: 'string',\n },\n editorconfig: {\n type: 'boolean',\n default: true,\n },\n gitignore: {\n type: 'boolean',\n default: true,\n },\n force: {\n type: 'boolean',\n default: false,\n },\n install: {\n type: 'boolean',\n default: true,\n },\n name: {\n type: 'string',\n },\n author: {\n type: 'string',\n },\n repo: {\n type: 'string',\n },\n presetOnly: {\n type: 'boolean',\n default: false,\n },\n preset: {\n type: 'string',\n isMultiple: true,\n },\n} as const\n\nexport type InitFlags = TypedFlags<typeof initFlags>\n\nexport interface InitOptions {\n basePath: string\n flags: InitFlags\n}\n\nexport async function init(options: InitOptions) {\n let dependencies = {}\n let devDependencies = {}\n let peerDependencies = {}\n\n await inject({\n ...options,\n outDir: defaultOutDir,\n requireUserConfirmation: !options.flags.force,\n dependencies,\n devDependencies,\n peerDependencies,\n validate: false,\n })\n\n const packageJson = await getPackage({basePath: options.basePath, validate: false})\n const typescript = options.flags.typescript\n const source = typescript ? defaultSourceTs(packageJson) : defaultSourceJs(packageJson)\n const filename = typescript ? 'index.ts' : 'index.js'\n const srcDir = path.resolve(options.basePath, 'src')\n await ensureDir(srcDir)\n await writeFile(path.join(srcDir, filename), source, {encoding: 'utf8'})\n}\n"],"names":[],"mappings":";;;;AAIO,SAAS,gBAAgB,KAAkB;AAChD,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAQ2B,IAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAYR,IAAI,IAAI;AAAA;AAAA,eAExB,IAAI,IAAI;AAAA;AAAA;AAAA,EAGrB,cAAc;AAAA;AAEhB;AAEO,SAAS,gBAAgB,KAAkB;AAChD,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AA,IACR,yBAAyB,CAAC,QAAQ,MAAM;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EAAA,CACX;AAED,QAAM,cAAc,MAAM,WAAW,EAAC,UAAU,QAAQ,UAAU,UAAU,GAAA,CAAM,GAC5E,aAAa,QAAQ,MAAM,YAC3B,SAAS,aAAa,gBAAgB,WAAW,IAAI,gBAAgB,WAAW,GAChF,WAAW,aAAa,aAAa,YACrC,SAAS,KAAK,QAAQ,QAAQ,UAAU,KAAK;AACnD,QAAM,UAAU,MAAM,GACtB,MAAM,UAAU,KAAK,KAAK,QAAQ,QAAQ,GAAG,QAAQ,EAAC,UAAU,QAAO;AACzE;"}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {cliName, defaultOutDir} from '../constants'
|
|
9
|
-
import {presetHelpList} from '../presets/presets'
|
|
10
|
-
|
|
11
|
-
const description = `Inject configuration into a Sanity plugin`
|
|
12
|
-
|
|
13
|
-
const help = `
|
|
1
|
+
import path from "path";
|
|
2
|
+
import meow from "meow";
|
|
3
|
+
import { initFlags } from "./init2.js";
|
|
4
|
+
import { findStudioV3Config, inject, presetHelpList } from "./package.js";
|
|
5
|
+
import { cliName, defaultOutDir, log } from "./index.js";
|
|
6
|
+
import { loadPackageConfig } from "./load-package-config.js";
|
|
7
|
+
const description = "Inject configuration into a Sanity plugin", help = `
|
|
14
8
|
Usage
|
|
15
9
|
$ ${cliName} inject [dir] [<args>]
|
|
16
10
|
|
|
@@ -47,24 +41,16 @@ Examples
|
|
|
47
41
|
# Only inject semver-workflow and renovatebot config from presets
|
|
48
42
|
$ ${cliName} inject --preset-only --preset semver-workflow --preset renovatebot
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const basePath = path.resolve(cli.input[0] || process.cwd())
|
|
55
|
-
const packageConfig = await loadPackageConfig({cwd: basePath})
|
|
56
|
-
const outDir = packageConfig?.dist ?? defaultOutDir
|
|
57
|
-
|
|
58
|
-
const {v3ConfigFile} = await findStudioV3Config(basePath)
|
|
59
|
-
if (v3ConfigFile) {
|
|
44
|
+
`;
|
|
45
|
+
async function run({ argv }) {
|
|
46
|
+
const cli = meow(help, { flags: initFlags, argv, description }), basePath = path.resolve(cli.input[0] || process.cwd()), outDir = (await loadPackageConfig({ basePath }))?.dist ?? defaultOutDir, { v3ConfigFile } = await findStudioV3Config(basePath);
|
|
47
|
+
if (v3ConfigFile)
|
|
60
48
|
throw new Error(
|
|
61
|
-
`${v3ConfigFile} exists - are you trying to INJECT into a studio instead of a plugin
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
log.info('Inject config into plugin in "%s"', basePath)
|
|
65
|
-
|
|
66
|
-
await inject({basePath, outDir, flags: cli.flags, validate: false})
|
|
67
|
-
log.info('Done!')
|
|
49
|
+
`${v3ConfigFile} exists - are you trying to INJECT into a studio instead of a plugin?`
|
|
50
|
+
);
|
|
51
|
+
log.info('Inject config into plugin in "%s"', basePath), await inject({ basePath, outDir, flags: cli.flags, validate: !1 }), log.info("Done!");
|
|
68
52
|
}
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
export {
|
|
54
|
+
run as default
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sources":["../../src/cmds/inject.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"inject.js","sources":["../../src/cmds/inject.ts"],"sourcesContent":["import path from 'path'\n\nimport meow from 'meow'\n\nimport {initFlags} from '../actions/init'\nimport {inject} from '../actions/inject'\nimport {cliName, defaultOutDir} from '../constants'\nimport {presetHelpList} from '../presets/presets'\nimport {findStudioV3Config} from '../sanity/manifest'\nimport {loadPackageConfig} from '../util/load-package-config'\nimport log from '../util/log'\n\nconst description = `Inject configuration into a Sanity plugin`\n\nconst help = `\nUsage\n $ ${cliName} inject [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n${presetHelpList(30)}\n --preset-only Skips the default inject steps. Use this to apply a preset to an otherwise complete plugin.\n\nExamples\n # Inject configuration into the plugin in the current directory\n $ ${cliName} inject\n\n # Inject configuration into the plugin in ~/my-plugin\n $ ${cliName} inject ~/my-plugin\n\n # Don't inject eslint or prettier\n $ ${cliName} inject --no-eslint --no-prettier\n\n # Inject plugin configuration and semver-workflow into the plugin in the current directory\n $ @sanity/plugin-kit inject --preset semver-workflow\n\n # Only inject semver-workflow and renovatebot config from presets\n $ ${cliName} inject --preset-only --preset semver-workflow --preset renovatebot\n\n`\n\nasync function run({argv}: {argv: string[]}) {\n const cli = meow(help, {flags: initFlags, argv, description})\n const basePath = path.resolve(cli.input[0] || process.cwd())\n const packageConfig = await loadPackageConfig({basePath})\n const outDir = packageConfig?.dist ?? defaultOutDir\n\n const {v3ConfigFile} = await findStudioV3Config(basePath)\n if (v3ConfigFile) {\n throw new Error(\n `${v3ConfigFile} exists - are you trying to INJECT into a studio instead of a plugin?`,\n )\n }\n log.info('Inject config into plugin in \"%s\"', basePath)\n\n await inject({basePath, outDir, flags: cli.flags, validate: false})\n log.info('Done!')\n}\n\nexport default run\n"],"names":[],"mappings":";;;;;;AAYA,MAAM,cAAc,6CAEd,OAAO;AAAA;AAAA,MAEP,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBX,eAAe,EAAE,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,MAKd,OAAO;AAAA;AAAA;AAAA,MAGP,OAAO;AAAA;AAAA;AAAA,MAGP,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMP,OAAO;AAAA;AAAA;AAIb,eAAe,IAAI,EAAC,QAAyB;AAC3C,QAAM,MAAM,KAAK,MAAM,EAAC,OAAO,WAAW,MAAM,YAAA,CAAY,GACtD,WAAW,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,QAAQ,IAAA,CAAK,GAErD,UADgB,MAAM,kBAAkB,EAAC,SAAA,CAAS,IAC1B,QAAQ,eAEhC,EAAC,aAAA,IAAgB,MAAM,mBAAmB,QAAQ;AACxD,MAAI;AACF,UAAM,IAAI;AAAA,MACR,GAAG,YAAY;AAAA,IAAA;AAGnB,MAAI,KAAK,qCAAqC,QAAQ,GAEtD,MAAM,OAAO,EAAC,UAAU,QAAQ,OAAO,IAAI,OAAO,UAAU,GAAA,CAAM,GAClE,IAAI,KAAK,OAAO;AAClB;"}
|