@sanity/plugin-kit 3.1.12 → 3.1.13-canary.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/assets/inject/semver-workflow/.github/workflows/main.yml +6 -6
- package/dist/_chunks-cjs/cli.js +135 -0
- package/dist/_chunks-cjs/cli.js.map +1 -0
- package/dist/_chunks-cjs/init.js +894 -0
- package/dist/_chunks-cjs/init.js.map +1 -0
- package/dist/_chunks-cjs/init2.js +83 -0
- package/dist/_chunks-cjs/init2.js.map +1 -0
- package/dist/_chunks-cjs/inject.js +54 -0
- package/dist/_chunks-cjs/inject.js.map +1 -0
- package/dist/_chunks-cjs/link-watch.js +84 -0
- package/dist/_chunks-cjs/link-watch.js.map +1 -0
- package/dist/_chunks-cjs/package.js +1808 -0
- package/dist/_chunks-cjs/package.js.map +1 -0
- package/dist/_chunks-cjs/package2.js +143 -0
- package/dist/_chunks-cjs/package2.js.map +1 -0
- package/dist/_chunks-cjs/ts.js +162 -0
- package/dist/_chunks-cjs/ts.js.map +1 -0
- package/dist/_chunks-cjs/verify-package.js +75 -0
- package/dist/_chunks-cjs/verify-package.js.map +1 -0
- package/dist/_chunks-cjs/verify-studio.js +57 -0
- package/dist/_chunks-cjs/verify-studio.js.map +1 -0
- package/dist/_chunks-cjs/version.js +51 -0
- package/dist/_chunks-cjs/version.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +4 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +57 -59
- package/src/actions/inject.ts +1 -1
- package/src/actions/verify/types.ts +0 -1
- package/src/actions/verify/validations.ts +13 -69
- package/src/actions/verify/verify-common.ts +0 -1
- package/src/actions/verify-package.ts +0 -2
- package/src/cli.ts +1 -0
- package/src/configs/forced-package-versions.ts +0 -1
- package/src/configs/pkg-config.ts +0 -1
- package/src/configs/tsconfig.ts +20 -21
- package/src/npm/package.ts +6 -17
- package/src/presets/ui.ts +0 -1
- package/dist/_chunks/cli-cFLCCBOO.js +0 -168
- package/dist/_chunks/cli-cFLCCBOO.js.map +0 -1
- package/dist/_chunks/init-RizSz7N7.js +0 -104
- package/dist/_chunks/init-RizSz7N7.js.map +0 -1
- package/dist/_chunks/init-iwJScjA2.js +0 -966
- package/dist/_chunks/init-iwJScjA2.js.map +0 -1
- package/dist/_chunks/inject-p1N6jT0L.js +0 -49
- package/dist/_chunks/inject-p1N6jT0L.js.map +0 -1
- package/dist/_chunks/link-watch-hESx--O4.js +0 -91
- package/dist/_chunks/link-watch-hESx--O4.js.map +0 -1
- package/dist/_chunks/package-LD2bWiQM.js +0 -2358
- package/dist/_chunks/package-LD2bWiQM.js.map +0 -1
- package/dist/_chunks/package-hEMm6olE.js +0 -155
- package/dist/_chunks/package-hEMm6olE.js.map +0 -1
- package/dist/_chunks/ts--PkJtFoh.js +0 -165
- package/dist/_chunks/ts--PkJtFoh.js.map +0 -1
- package/dist/_chunks/verify-package-88yI8VXr.js +0 -97
- package/dist/_chunks/verify-package-88yI8VXr.js.map +0 -1
- package/dist/_chunks/verify-studio-t8s7BSdb.js +0 -74
- package/dist/_chunks/verify-studio-t8s7BSdb.js.map +0 -1
- package/dist/_chunks/version-UQqnNiud.js +0 -54
- package/dist/_chunks/version-UQqnNiud.js.map +0 -1
|
@@ -1,966 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14;
|
|
4
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
5
|
-
var path = require('path');
|
|
6
|
-
var licenses = require('@rexxars/choosealicense-list');
|
|
7
|
-
var gitRemoteOriginUrl = require('git-remote-origin-url');
|
|
8
|
-
var cli = require('./cli-cFLCCBOO.js');
|
|
9
|
-
var xdgBasedir = require('xdg-basedir');
|
|
10
|
-
var gitUserInfo = require('git-user-info');
|
|
11
|
-
var emailValidator = require('email-validator');
|
|
12
|
-
var _package$1 = require('./package-LD2bWiQM.js');
|
|
13
|
-
var getIt = require('get-it');
|
|
14
|
-
var middleware = require('get-it/middleware');
|
|
15
|
-
var _package = require('./package-hEMm6olE.js');
|
|
16
|
-
var outdent = require('outdent');
|
|
17
|
-
var chalk = require('chalk');
|
|
18
|
-
function _interopDefaultCompat(e) {
|
|
19
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
20
|
-
default: e
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
24
|
-
var licenses__default = /*#__PURE__*/_interopDefaultCompat(licenses);
|
|
25
|
-
var gitRemoteOriginUrl__default = /*#__PURE__*/_interopDefaultCompat(gitRemoteOriginUrl);
|
|
26
|
-
var xdgBasedir__default = /*#__PURE__*/_interopDefaultCompat(xdgBasedir);
|
|
27
|
-
var outdent__default = /*#__PURE__*/_interopDefaultCompat(outdent);
|
|
28
|
-
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
29
|
-
const request = getIt.getIt([middleware.promise({
|
|
30
|
-
onlyBody: true
|
|
31
|
-
}), middleware.jsonRequest(), middleware.jsonResponse(), middleware.httpErrors(), middleware.headers({
|
|
32
|
-
"User-Agent": "".concat(_package.pkg.name, "@").concat(_package.pkg.version)
|
|
33
|
-
})]);
|
|
34
|
-
async function getUserInfo(_ref, pkg) {
|
|
35
|
-
var _flags$author;
|
|
36
|
-
let {
|
|
37
|
-
requireUserConfirmation,
|
|
38
|
-
flags
|
|
39
|
-
} = _ref;
|
|
40
|
-
const userInfo = getPackageUserInfo({
|
|
41
|
-
author: (_flags$author = flags.author) !== null && _flags$author !== void 0 ? _flags$author : pkg === null || pkg === void 0 ? void 0 : pkg.author
|
|
42
|
-
}) || (await getSanityUserInfo()) || (await getGitUserInfo());
|
|
43
|
-
if (requireUserConfirmation) {
|
|
44
|
-
return promptForInfo(userInfo);
|
|
45
|
-
}
|
|
46
|
-
return userInfo;
|
|
47
|
-
}
|
|
48
|
-
function getPackageUserInfo(pkg) {
|
|
49
|
-
let author = pkg === null || pkg === void 0 ? void 0 : pkg.author;
|
|
50
|
-
if (!author) {
|
|
51
|
-
return void 0;
|
|
52
|
-
}
|
|
53
|
-
if (author && typeof author !== "string") {
|
|
54
|
-
return author;
|
|
55
|
-
} else if (!author.includes("@")) {
|
|
56
|
-
return {
|
|
57
|
-
name: author
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const [pre, ...post] = author.replace(/[<>[\]]/g, "").split(/@/);
|
|
61
|
-
const nameParts = pre.split(/\s+/);
|
|
62
|
-
const email = [nameParts[nameParts.length - 1], ...post].join("@");
|
|
63
|
-
const name = nameParts.slice(0, -1).join(" ");
|
|
64
|
-
return {
|
|
65
|
-
name,
|
|
66
|
-
email
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
async function promptForInfo(defValue) {
|
|
70
|
-
const name = await _package$1.prompt("Author name", {
|
|
71
|
-
filter: filterString,
|
|
72
|
-
default: defValue && defValue.name,
|
|
73
|
-
validate: requiredString
|
|
74
|
-
});
|
|
75
|
-
const email = await _package$1.prompt("Author email", {
|
|
76
|
-
filter: filterString,
|
|
77
|
-
default: defValue && defValue.email,
|
|
78
|
-
validate: validOrEmptyEmail
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
name,
|
|
82
|
-
email
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
async function getSanityUserInfo() {
|
|
86
|
-
try {
|
|
87
|
-
var _xdgBasedir__default$;
|
|
88
|
-
const data = await _package$1.readJsonFile(path__default.default.join((_xdgBasedir__default$ = xdgBasedir__default.default.config) !== null && _xdgBasedir__default$ !== void 0 ? _xdgBasedir__default$ : "", "sanity", "config.json"));
|
|
89
|
-
const token = data === null || data === void 0 ? void 0 : data.authToken;
|
|
90
|
-
if (!token) {
|
|
91
|
-
return void 0;
|
|
92
|
-
}
|
|
93
|
-
const user = await request({
|
|
94
|
-
url: "https://api.sanity.io/v1/users/me",
|
|
95
|
-
headers: {
|
|
96
|
-
Authorization: "Bearer ".concat(token)
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
if (!user) {
|
|
100
|
-
return void 0;
|
|
101
|
-
}
|
|
102
|
-
const {
|
|
103
|
-
name,
|
|
104
|
-
email
|
|
105
|
-
} = user;
|
|
106
|
-
return {
|
|
107
|
-
name,
|
|
108
|
-
email
|
|
109
|
-
};
|
|
110
|
-
} catch (err) {
|
|
111
|
-
return void 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async function getGitUserInfo() {
|
|
115
|
-
const user = await gitUserInfo.getGitUserInfo();
|
|
116
|
-
return user ? {
|
|
117
|
-
name: user.name,
|
|
118
|
-
email: user.email
|
|
119
|
-
} : void 0;
|
|
120
|
-
}
|
|
121
|
-
function filterString(val) {
|
|
122
|
-
return (val || "").trim();
|
|
123
|
-
}
|
|
124
|
-
function requiredString(value) {
|
|
125
|
-
return value.length > 1 ? true : "Required";
|
|
126
|
-
}
|
|
127
|
-
function validOrEmptyEmail(value) {
|
|
128
|
-
if (!value) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
return emailValidator.validate(value) ? true : "Must either be a valid email or empty";
|
|
132
|
-
}
|
|
133
|
-
function generateReadme(data) {
|
|
134
|
-
const {
|
|
135
|
-
user,
|
|
136
|
-
pluginName,
|
|
137
|
-
license,
|
|
138
|
-
description
|
|
139
|
-
} = data;
|
|
140
|
-
return outdent__default.default(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n # ", "\n\n ", "\n\n ", "\n\n ## Usage\n\n Add it as a plugin in `sanity.config.ts` (or .js):\n\n ```ts\n import {defineConfig} from 'sanity'\n import {myPlugin} from '", "'\n\n export default defineConfig({\n //...\n plugins: [myPlugin({})],\n })\n ```\n\n ", "\n ", "\n "], ["\n # ", "\n\n ", "\n\n ", "\n\n ## Usage\n\n Add it as a plugin in \\`sanity.config.ts\\` (or .js):\n\n \\`\\`\\`ts\n import {defineConfig} from 'sanity'\n import {myPlugin} from '", "'\n\n export default defineConfig({\n //...\n plugins: [myPlugin({})],\n })\n \\`\\`\\`\n\n ", "\n ", "\n "])), pluginName, v3BannerNotice(), installationSnippet(pluginName !== null && pluginName !== void 0 ? pluginName : "unknown"), pluginName, getLicenseText(license === null || license === void 0 ? void 0 : license.id, user !== null && user !== void 0 && user.name ? user : void 0), developTestSnippet()) + "\n";
|
|
141
|
-
}
|
|
142
|
-
function v3BannerNotice() {
|
|
143
|
-
return "> This is a **Sanity Studio v3** plugin.";
|
|
144
|
-
}
|
|
145
|
-
function installationSnippet(packageName) {
|
|
146
|
-
return outdent__default.default(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ## Installation\n\n ```sh\n npm install ", "\n ```\n "], ["\n ## Installation\n\n \\`\\`\\`sh\n npm install ", "\n \\`\\`\\`\n "])), packageName);
|
|
147
|
-
}
|
|
148
|
-
function developTestSnippet() {
|
|
149
|
-
return outdent__default.default(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ## Develop & test\n\n This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)\n with default configuration for build & watch scripts.\n\n See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)\n on how to run this plugin with hotreload in the studio.\n "])));
|
|
150
|
-
}
|
|
151
|
-
function getLicenseText(licenseId, user) {
|
|
152
|
-
var _licenseName;
|
|
153
|
-
if (!licenseId) {
|
|
154
|
-
return "";
|
|
155
|
-
}
|
|
156
|
-
let licenseName = licenses__default.default.find(licenseId).title;
|
|
157
|
-
licenseName = (_licenseName = licenseName) === null || _licenseName === void 0 ? void 0 : _licenseName.replace(/\s+license$/i, "");
|
|
158
|
-
let licenseText = "## License\n";
|
|
159
|
-
if (licenseName && user !== null && user !== void 0 && user.name) {
|
|
160
|
-
licenseText = "".concat(licenseText, "\n[").concat(licenseName, "](LICENSE) \xA9 ").concat(user === null || user === void 0 ? void 0 : user.name, "\n");
|
|
161
|
-
} else if (licenseName) {
|
|
162
|
-
licenseText = "".concat(licenseText, "\n[").concat(licenseName, "](LICENSE)\n");
|
|
163
|
-
} else {
|
|
164
|
-
licenseText = "".concat(licenseText, "\nSee [LICENSE](LICENSE)");
|
|
165
|
-
}
|
|
166
|
-
return licenseText;
|
|
167
|
-
}
|
|
168
|
-
function isDefaultGitHubReadme(readme) {
|
|
169
|
-
if (!readme) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
const lines = readme.split("\n", 20).filter(Boolean);
|
|
173
|
-
return lines.length <= 2 && lines[0].startsWith("#");
|
|
174
|
-
}
|
|
175
|
-
const semverWorkflowPreset = {
|
|
176
|
-
name: "semver-workflow",
|
|
177
|
-
description: "Files and dependencies for conventional-commits, github workflow and semantic-release.",
|
|
178
|
-
apply: applyPreset$3
|
|
179
|
-
};
|
|
180
|
-
const info = function (write, msg) {
|
|
181
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
182
|
-
args[_key - 2] = arguments[_key];
|
|
183
|
-
}
|
|
184
|
-
return write && cli.log.info(msg, ...args);
|
|
185
|
-
};
|
|
186
|
-
async function applyPreset$3(options) {
|
|
187
|
-
await writeAssets(semverWorkflowFiles(), options);
|
|
188
|
-
await addPrepareScript(options);
|
|
189
|
-
await addDevDependencies$2(options);
|
|
190
|
-
await updateReadme(options);
|
|
191
|
-
}
|
|
192
|
-
async function addPrepareScript(options) {
|
|
193
|
-
const pkg = await _package$1.getPackage(options);
|
|
194
|
-
const didWrite = await _package$1.addPackageJsonScripts(pkg, options, scripts => {
|
|
195
|
-
scripts.prepare = _package$1.addScript("husky install", scripts.prepare);
|
|
196
|
-
return scripts;
|
|
197
|
-
});
|
|
198
|
-
info(didWrite, "Added prepare script to package.json");
|
|
199
|
-
}
|
|
200
|
-
async function addDevDependencies$2(options) {
|
|
201
|
-
const pkg = await _package$1.getPackage(options);
|
|
202
|
-
const devDeps = _package$1.sortKeys({
|
|
203
|
-
...pkg.devDependencies,
|
|
204
|
-
...(await semverWorkflowDependencies())
|
|
205
|
-
});
|
|
206
|
-
const newPkg = {
|
|
207
|
-
...pkg
|
|
208
|
-
};
|
|
209
|
-
newPkg.devDependencies = devDeps;
|
|
210
|
-
await _package$1.writePackageJsonDirect(newPkg, options);
|
|
211
|
-
cli.log.info("Updated devDependencies.");
|
|
212
|
-
cli.log.info(chalk__default.default.green(outdent__default.default(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n semantic-release preset injected.\n\n Please confer\n https://github.com/sanity-io/plugin-kit/blob/main/docs/semver-workflow.md#manual-steps-after-inject\n to finalize configuration for this preset.\n "]))).trim()));
|
|
213
|
-
}
|
|
214
|
-
async function updateReadme(options) {
|
|
215
|
-
var _await$_package$1$rea;
|
|
216
|
-
const {
|
|
217
|
-
basePath
|
|
218
|
-
} = options;
|
|
219
|
-
const readmePath = path__default.default.join(basePath, "README.md");
|
|
220
|
-
const readme = (_await$_package$1$rea = await _package$1.readFile(readmePath, "utf8").catch(_package$1.errorToUndefined)) !== null && _await$_package$1$rea !== void 0 ? _await$_package$1$rea : "";
|
|
221
|
-
const {
|
|
222
|
-
v3Banner,
|
|
223
|
-
install,
|
|
224
|
-
usage,
|
|
225
|
-
developTest,
|
|
226
|
-
license,
|
|
227
|
-
releaseSnippet
|
|
228
|
-
} = await readmeSnippets(options);
|
|
229
|
-
const prependSections = missingSections(readme, [v3Banner, install, usage]);
|
|
230
|
-
const appendSections = missingSections(readme, [license, developTest, releaseSnippet]);
|
|
231
|
-
if (prependSections.length || appendSections.length) {
|
|
232
|
-
const updatedReadme = [...prependSections, readme, ...appendSections].filter(Boolean).join("\n\n");
|
|
233
|
-
await _package$1.writeFile(readmePath, updatedReadme, {
|
|
234
|
-
encoding: "utf8"
|
|
235
|
-
});
|
|
236
|
-
cli.log.info("Updated README. Please review the changes.");
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
async function readmeSnippets(options) {
|
|
240
|
-
var _pkg$name;
|
|
241
|
-
const pkg = await _package$1.getPackage(options);
|
|
242
|
-
const user = await getUserInfo(options, pkg);
|
|
243
|
-
const bestEffortUrl = readmeBaseurl(pkg);
|
|
244
|
-
const install = installationSnippet((_pkg$name = pkg.name) !== null && _pkg$name !== void 0 ? _pkg$name : "unknown");
|
|
245
|
-
const usage = outdent__default.default(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n ## Usage\n "])));
|
|
246
|
-
const license = getLicenseText(typeof pkg.license === "string" ? pkg.license : void 0, user);
|
|
247
|
-
const releaseSnippet = outdent__default.default(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n ### Release new version\n\n Run [\"CI & Release\" workflow](", "/actions/workflows/main.yml).\n Make sure to select the main branch and check \"Release new version\".\n\n Semantic release will only release on configured branches, so it is safe to run release on any branch.\n "])), bestEffortUrl);
|
|
248
|
-
return {
|
|
249
|
-
v3Banner: v3BannerNotice(),
|
|
250
|
-
install,
|
|
251
|
-
usage,
|
|
252
|
-
license,
|
|
253
|
-
developTest: developTestSnippet(),
|
|
254
|
-
releaseSnippet
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function missingSections(readme, sections) {
|
|
258
|
-
return sections.filter(section => !closeEnough(section, readme));
|
|
259
|
-
}
|
|
260
|
-
function closeEnough(a, b) {
|
|
261
|
-
const aLines = a.split("\n");
|
|
262
|
-
const bLines = b.split("\n");
|
|
263
|
-
const matchingLines = aLines.filter(line => bLines.find(bLine => bLine === line)).length;
|
|
264
|
-
const isCloseEnough = matchingLines >= aLines.length * 0.5;
|
|
265
|
-
return isCloseEnough;
|
|
266
|
-
}
|
|
267
|
-
function semverWorkflowFiles() {
|
|
268
|
-
const base = [{
|
|
269
|
-
type: "copy",
|
|
270
|
-
from: [".github", "workflows", "main.yml"],
|
|
271
|
-
to: [".github", "workflows", "main.yml"]
|
|
272
|
-
}, {
|
|
273
|
-
type: "copy",
|
|
274
|
-
from: [".husky", "commit-msg"],
|
|
275
|
-
to: [".husky", "commit-msg"]
|
|
276
|
-
}, {
|
|
277
|
-
type: "copy",
|
|
278
|
-
from: [".husky", "pre-commit"],
|
|
279
|
-
to: [".husky", "pre-commit"]
|
|
280
|
-
}, {
|
|
281
|
-
type: "copy",
|
|
282
|
-
from: [".releaserc.json"],
|
|
283
|
-
to: ".releaserc.json"
|
|
284
|
-
}, {
|
|
285
|
-
type: "copy",
|
|
286
|
-
from: ["commitlint.template.js"],
|
|
287
|
-
to: "commitlint.config.js"
|
|
288
|
-
}, {
|
|
289
|
-
type: "copy",
|
|
290
|
-
from: ["lint-staged.template.js"],
|
|
291
|
-
to: "lint-staged.config.js"
|
|
292
|
-
}];
|
|
293
|
-
return base.map(fromTo => {
|
|
294
|
-
if (fromTo.type === "copy") {
|
|
295
|
-
return {
|
|
296
|
-
...fromTo,
|
|
297
|
-
from: ["semver-workflow", ...fromTo.from]
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
return fromTo;
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
async function semverWorkflowDependencies() {
|
|
304
|
-
return _package$1.resolveLatestVersions(["@commitlint/cli", "@commitlint/config-conventional", "@sanity/semantic-release-preset", "husky", "lint-staged"]);
|
|
305
|
-
}
|
|
306
|
-
function readmeBaseurl(pkg) {
|
|
307
|
-
var _ref2, _pkg$repository$url, _pkg$repository;
|
|
308
|
-
return ((_ref2 = (_pkg$repository$url = (_pkg$repository = pkg.repository) === null || _pkg$repository === void 0 ? void 0 : _pkg$repository.url) !== null && _pkg$repository$url !== void 0 ? _pkg$repository$url : pkg.homepage) !== null && _ref2 !== void 0 ? _ref2 : "TODO").replace(/.+:\/\//g, "https://").replace(/\.git/g, "").replace(/git@github.com\//g, "github.com/").replace(/git@github.com:/g, "https://github.com/").replace(/#.+/g, "");
|
|
309
|
-
}
|
|
310
|
-
const renovatePreset = {
|
|
311
|
-
name: "renovatebot",
|
|
312
|
-
description: "Files to enable renovatebot.",
|
|
313
|
-
apply: applyPreset$2
|
|
314
|
-
};
|
|
315
|
-
async function applyPreset$2(options) {
|
|
316
|
-
await writeAssets([{
|
|
317
|
-
type: "copy",
|
|
318
|
-
from: ["renovatebot", "renovate.json"],
|
|
319
|
-
to: "renovate.json"
|
|
320
|
-
}], options);
|
|
321
|
-
}
|
|
322
|
-
const ui = {
|
|
323
|
-
name: "ui",
|
|
324
|
-
description: "`@sanity/ui` and dependencies",
|
|
325
|
-
apply: applyPreset$1
|
|
326
|
-
};
|
|
327
|
-
async function applyPreset$1(options) {
|
|
328
|
-
await addDependencies(options);
|
|
329
|
-
await addDevDependencies$1(options);
|
|
330
|
-
cli.log.info(chalk__default.default.green("ui preset injected"));
|
|
331
|
-
}
|
|
332
|
-
async function addDependencies(options) {
|
|
333
|
-
const pkg = await _package$1.getPackage(options);
|
|
334
|
-
const newDeps = _package$1.sortKeys(_package$1.forceDependencyVersions({
|
|
335
|
-
...pkg.dependencies,
|
|
336
|
-
...(await resolveDependencyList())
|
|
337
|
-
}, _package$1.forcedPackageVersions));
|
|
338
|
-
const newPkg = {
|
|
339
|
-
...pkg
|
|
340
|
-
};
|
|
341
|
-
newPkg.dependencies = newDeps;
|
|
342
|
-
await _package$1.writePackageJsonDirect(newPkg, options);
|
|
343
|
-
cli.log.info("Updated dependencies.");
|
|
344
|
-
}
|
|
345
|
-
async function addDevDependencies$1(options) {
|
|
346
|
-
const pkg = await _package$1.getPackage(options);
|
|
347
|
-
const newDeps = _package$1.sortKeys(_package$1.forceDependencyVersions({
|
|
348
|
-
...pkg.devDependencies,
|
|
349
|
-
...(await resolveDevDependencyList())
|
|
350
|
-
}, _package$1.forcedDevPackageVersions));
|
|
351
|
-
const newPkg = {
|
|
352
|
-
...pkg
|
|
353
|
-
};
|
|
354
|
-
newPkg.devDependencies = newDeps;
|
|
355
|
-
await _package$1.writePackageJsonDirect(newPkg, options);
|
|
356
|
-
cli.log.info("Updated devDependencies.");
|
|
357
|
-
}
|
|
358
|
-
async function resolveDependencyList() {
|
|
359
|
-
return _package$1.resolveLatestVersions(["@sanity/icons", "@sanity/ui"]);
|
|
360
|
-
}
|
|
361
|
-
async function resolveDevDependencyList() {
|
|
362
|
-
return _package$1.resolveLatestVersions([
|
|
363
|
-
// install the peer dependencies of `@sanity/ui` as dev dependencies
|
|
364
|
-
"react", "react-dom", "react-is", "styled-components"]);
|
|
365
|
-
}
|
|
366
|
-
const uiWorkshop = {
|
|
367
|
-
name: "ui-workshop",
|
|
368
|
-
description: "Files for testing custom components with @sanity/ui-workshop",
|
|
369
|
-
apply: applyPreset
|
|
370
|
-
};
|
|
371
|
-
async function applyPreset(options) {
|
|
372
|
-
await writeAssets(files(), options);
|
|
373
|
-
await addDevDependencies(options);
|
|
374
|
-
await updateGitIgnore(options);
|
|
375
|
-
cli.log.info(chalk__default.default.green(outdent__default.default(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n ui-workshop preset injected.\n\n Please confer\n https://github.com/sanity-io/plugin-kit/blob/main/docs/ui-workshop.md#manual-steps-after-inject\n to finalize configuration for this preset.\n "]))).trim()));
|
|
376
|
-
}
|
|
377
|
-
function files() {
|
|
378
|
-
const base = [{
|
|
379
|
-
type: "copy",
|
|
380
|
-
from: ["workshop.config.ts"],
|
|
381
|
-
to: ["workshop.config.ts"]
|
|
382
|
-
}, {
|
|
383
|
-
type: "copy",
|
|
384
|
-
from: ["src", "CustomField.tsx"],
|
|
385
|
-
to: ["src", "CustomField.tsx"]
|
|
386
|
-
}, {
|
|
387
|
-
type: "copy",
|
|
388
|
-
from: ["src", "__workshop__", "index.tsx"],
|
|
389
|
-
to: ["src", "__workshop__", "index.tsx"]
|
|
390
|
-
}, {
|
|
391
|
-
type: "copy",
|
|
392
|
-
from: ["src", "__workshop__", "props.tsx"],
|
|
393
|
-
to: ["src", "__workshop__", "props.tsx"]
|
|
394
|
-
}];
|
|
395
|
-
return base.map(fromTo => {
|
|
396
|
-
if (fromTo.type === "copy") {
|
|
397
|
-
return {
|
|
398
|
-
...fromTo,
|
|
399
|
-
from: ["ui-workshop", ...fromTo.from]
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
return fromTo;
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
async function updateGitIgnore(options) {
|
|
406
|
-
var _await$_package$1$rea2;
|
|
407
|
-
const {
|
|
408
|
-
basePath
|
|
409
|
-
} = options;
|
|
410
|
-
const gitignorePath = path__default.default.join(basePath, ".gitignore");
|
|
411
|
-
let gitignore = (_await$_package$1$rea2 = await _package$1.readFile(gitignorePath, "utf8").catch(_package$1.errorToUndefined)) !== null && _await$_package$1$rea2 !== void 0 ? _await$_package$1$rea2 : "";
|
|
412
|
-
const value = ".workshop";
|
|
413
|
-
if (gitignore.includes(value)) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
gitignore += "\n\n".concat(value);
|
|
417
|
-
await _package$1.writeFile(gitignorePath, gitignore, {
|
|
418
|
-
encoding: "utf8"
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
async function addDevDependencies(options) {
|
|
422
|
-
const pkg = await _package$1.getPackage(options);
|
|
423
|
-
const devDeps = _package$1.sortKeys({
|
|
424
|
-
...pkg.devDependencies,
|
|
425
|
-
...(await devDependencies())
|
|
426
|
-
});
|
|
427
|
-
const newPkg = {
|
|
428
|
-
...pkg
|
|
429
|
-
};
|
|
430
|
-
newPkg.devDependencies = devDeps;
|
|
431
|
-
await _package$1.writePackageJsonDirect(newPkg, options);
|
|
432
|
-
cli.log.info("Updated devDependencies.");
|
|
433
|
-
}
|
|
434
|
-
async function devDependencies() {
|
|
435
|
-
return _package$1.resolveLatestVersions(["@sanity/ui-workshop", "@sanity/icons", "@sanity/ui", "react", "react-dom", "styled-components"]);
|
|
436
|
-
}
|
|
437
|
-
const presets = [semverWorkflowPreset, renovatePreset, ui, uiWorkshop];
|
|
438
|
-
const presetNames = presets.map(p => p === null || p === void 0 ? void 0 : p.name);
|
|
439
|
-
function presetHelpList(padStart) {
|
|
440
|
-
return presets.map(p => "".concat("".padStart(padStart)).concat(p.name.padEnd(20)).concat(p.description)).join("\n");
|
|
441
|
-
}
|
|
442
|
-
async function injectPresets(options) {
|
|
443
|
-
var _options$flags$preset;
|
|
444
|
-
if (options.flags.presetOnly && !((_options$flags$preset = options.flags.preset) !== null && _options$flags$preset !== void 0 && _options$flags$preset.length)) {
|
|
445
|
-
throw new Error("--preset-only, but no --preset [preset-name] was provided.");
|
|
446
|
-
}
|
|
447
|
-
const applyPresets = presetsFromInput(options.flags.preset);
|
|
448
|
-
for (const preset of applyPresets) {
|
|
449
|
-
await preset.apply(options);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
function presetsFromInput(inputPresets) {
|
|
453
|
-
if (!inputPresets) {
|
|
454
|
-
return [];
|
|
455
|
-
}
|
|
456
|
-
const unknownPresets = inputPresets.filter(p => !presetNames.includes(p));
|
|
457
|
-
if (unknownPresets.length) {
|
|
458
|
-
throw new Error("Unknown --preset(s): [".concat(unknownPresets.join(", "), "]. Must be one of: [").concat(presetNames.join(", "), "]"));
|
|
459
|
-
}
|
|
460
|
-
return inputPresets.filter(onlyUnique).map(presetName => presets.find(p => p.name === presetName)).filter(p => !!p);
|
|
461
|
-
}
|
|
462
|
-
function onlyUnique(value, index, arr) {
|
|
463
|
-
return arr.indexOf(value) === index;
|
|
464
|
-
}
|
|
465
|
-
function tsconfigTemplate(options) {
|
|
466
|
-
const {
|
|
467
|
-
flags
|
|
468
|
-
} = options;
|
|
469
|
-
return {
|
|
470
|
-
type: "template",
|
|
471
|
-
force: flags.force,
|
|
472
|
-
to: "tsconfig.json",
|
|
473
|
-
value: outdent.outdent(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./src\", \"./package.config.ts\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"jsx\": \"react-jsx\",\n \"noEmit\": true\n }\n }\n "])))
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function tsconfigTemplateDist(options) {
|
|
477
|
-
const {
|
|
478
|
-
flags,
|
|
479
|
-
outDir
|
|
480
|
-
} = options;
|
|
481
|
-
return {
|
|
482
|
-
type: "template",
|
|
483
|
-
force: flags.force,
|
|
484
|
-
to: "tsconfig.".concat(outDir, ".json"),
|
|
485
|
-
value: outdent.outdent(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./src\"],\n \"exclude\": [\n \"./src/**/__fixtures__\",\n \"./src/**/__mocks__\",\n \"./src/**/*.test.ts\",\n \"./src/**/*.test.tsx\"\n ],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./", "\",\n \"jsx\": \"react-jsx\",\n \"emitDeclarationOnly\": true\n }\n }\n "])), outDir)
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function tsconfigTemplateSettings(options) {
|
|
489
|
-
const {
|
|
490
|
-
flags
|
|
491
|
-
} = options;
|
|
492
|
-
return {
|
|
493
|
-
type: "template",
|
|
494
|
-
force: flags.force,
|
|
495
|
-
to: "tsconfig.settings.json",
|
|
496
|
-
value: outdent.outdent(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n {\n \"compilerOptions\": {\n \"moduleResolution\": \"node\",\n \"target\": \"esnext\",\n \"module\": \"esnext\",\n \"lib\": [\"DOM\", \"DOM.Iterable\", \"ESNext\"],\n \"esModuleInterop\": true,\n \"strict\": true,\n \"downlevelIteration\": true,\n \"declaration\": true,\n \"allowSyntheticDefaultImports\": true,\n \"skipLibCheck\": true,\n \"isolatedModules\": true\n }\n }\n "])))
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function pkgConfigTemplate(options) {
|
|
500
|
-
const {
|
|
501
|
-
flags,
|
|
502
|
-
outDir
|
|
503
|
-
} = options;
|
|
504
|
-
return {
|
|
505
|
-
type: "template",
|
|
506
|
-
force: flags.force,
|
|
507
|
-
to: flags.typescript ? "package.config.ts" : "package.config.js",
|
|
508
|
-
value: outdent.outdent(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n legacyExports: true,\n dist: '", "',\n tsconfig: 'tsconfig.", ".json',\n\n // Remove this block to enable strict export validation\n extract: {\n rules: {\n 'ae-forgotten-export': 'off',\n 'ae-incompatible-release-tags': 'off',\n 'ae-internal-missing-underscore': 'off',\n 'ae-missing-release-tag': 'off',\n },\n },\n })\n "])), outDir, outDir)
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
function gitignoreTemplate() {
|
|
512
|
-
return {
|
|
513
|
-
type: "template",
|
|
514
|
-
to: ".gitignore",
|
|
515
|
-
value: outdent.outdent(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n # Logs\n logs\n *.log\n npm-debug.log*\n\n # Runtime data\n pids\n *.pid\n *.seed\n\n # Directory for instrumented libs generated by jscoverage/JSCover\n lib-cov\n\n # Coverage directory used by tools like istanbul\n coverage\n\n # nyc test coverage\n .nyc_output\n\n # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n .grunt\n\n # node-waf configuration\n .lock-wscript\n\n # Compiled binary addons (http://nodejs.org/api/addons.html)\n build/Release\n\n # Dependency directories\n node_modules\n jspm_packages\n\n # Optional npm cache directory\n .npm\n\n # Optional REPL history\n .node_repl_history\n\n # macOS finder cache file\n .DS_Store\n\n # VS Code settings\n .vscode\n\n # IntelliJ\n .idea\n *.iml\n\n # Cache\n .cache\n\n # Yalc\n .yalc\n yalc.lock\n\n # npm package zips\n *.tgz\n "])))
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function eslintrcTemplate(options) {
|
|
519
|
-
const {
|
|
520
|
-
flags
|
|
521
|
-
} = options;
|
|
522
|
-
const eslintConfig = {
|
|
523
|
-
root: true,
|
|
524
|
-
env: {
|
|
525
|
-
node: true,
|
|
526
|
-
browser: true
|
|
527
|
-
},
|
|
528
|
-
extends: ["sanity", flags.typescript && "sanity/typescript", "sanity/react", "plugin:react-hooks/recommended", flags.prettier && "plugin:prettier/recommended", "plugin:react/jsx-runtime"].filter(Boolean)
|
|
529
|
-
};
|
|
530
|
-
return {
|
|
531
|
-
type: "template",
|
|
532
|
-
force: flags.force,
|
|
533
|
-
to: ".eslintrc",
|
|
534
|
-
value: JSON.stringify(eslintConfig, null, 2)
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
function eslintignoreTemplate(options) {
|
|
538
|
-
const {
|
|
539
|
-
flags,
|
|
540
|
-
outDir
|
|
541
|
-
} = options;
|
|
542
|
-
const patterns = [".eslintrc.js", "commitlint.config.js", outDir, "lint-staged.config.js", flags.typescript ? "package.config.ts" : "package.config.js", flags.typescript ? "*.js" : ""].filter(Boolean);
|
|
543
|
-
patterns.sort();
|
|
544
|
-
return {
|
|
545
|
-
type: "template",
|
|
546
|
-
force: flags.force,
|
|
547
|
-
to: ".eslintignore",
|
|
548
|
-
value: patterns.join("\n")
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
function prettierignoreTemplate(options) {
|
|
552
|
-
const {
|
|
553
|
-
outDir
|
|
554
|
-
} = options;
|
|
555
|
-
return {
|
|
556
|
-
type: "template",
|
|
557
|
-
to: ".prettierignore",
|
|
558
|
-
value: [outDir, "pnpm-lock.yaml", "yarn.lock", "package-lock.json"].join("\n")
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
const bannedFields = ["login", "description", "projecturl", "email"];
|
|
562
|
-
const preferredLicenses = ["MIT", "ISC", "BSD-3-Clause"];
|
|
563
|
-
const otherLicenses = Object.keys(licenses__default.default.list).filter(id => {
|
|
564
|
-
const license = licenses__default.default.list[id];
|
|
565
|
-
return !preferredLicenses.includes(id) && !bannedFields.some(field => license.body.includes("[".concat(field, "]")));
|
|
566
|
-
});
|
|
567
|
-
async function inject(options) {
|
|
568
|
-
if (options.flags.presetOnly) {
|
|
569
|
-
cli.log.info("Only apply presets, skipping default inject.");
|
|
570
|
-
} else {
|
|
571
|
-
await injectBase(options);
|
|
572
|
-
}
|
|
573
|
-
await injectPresets(options);
|
|
574
|
-
}
|
|
575
|
-
async function injectBase(options) {
|
|
576
|
-
var _flags$name, _flags$repo, _pkg$repository2;
|
|
577
|
-
const {
|
|
578
|
-
basePath,
|
|
579
|
-
flags,
|
|
580
|
-
requireUserConfirmation
|
|
581
|
-
} = options;
|
|
582
|
-
const info = function (write, msg) {
|
|
583
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
584
|
-
args[_key2 - 2] = arguments[_key2];
|
|
585
|
-
}
|
|
586
|
-
return write && cli.log.info(msg, ...args);
|
|
587
|
-
};
|
|
588
|
-
const pkg = await _package$1.getPackage(options).catch(_package$1.errorToUndefined);
|
|
589
|
-
cli.log.debug("Plugin has package.json: %s", pkg ? "yes" : "no");
|
|
590
|
-
const user = await getUserInfo(options, pkg);
|
|
591
|
-
cli.log.debug("User information: %o", user);
|
|
592
|
-
const pkgName = (_flags$name = flags.name) !== null && _flags$name !== void 0 ? _flags$name : pkg === null || pkg === void 0 ? void 0 : pkg.name;
|
|
593
|
-
const pluginName = requireUserConfirmation || !pkgName ? await _package$1.promptForPackageName(options, pkgName) : pkgName;
|
|
594
|
-
cli.log.debug("Plugin name: %s", pluginName);
|
|
595
|
-
const license = await getLicense(flags, {
|
|
596
|
-
user,
|
|
597
|
-
pluginName,
|
|
598
|
-
pkg,
|
|
599
|
-
requireUserConfirmation
|
|
600
|
-
});
|
|
601
|
-
const licenseChanged = (pkg && pkg.license) !== (license && license.id);
|
|
602
|
-
cli.log.debug("License: %s", license ? license.id : "<none>");
|
|
603
|
-
const description = await getProjectDescription(basePath, pkg, requireUserConfirmation);
|
|
604
|
-
cli.log.debug("Description: %s", description || "<none>");
|
|
605
|
-
const repoUrl = (_flags$repo = flags.repo) !== null && _flags$repo !== void 0 ? _flags$repo : (await gitRemoteOriginUrl__default.default(basePath).catch(_package$1.errorToUndefined)) || (pkg === null || pkg === void 0 || (_pkg$repository2 = pkg.repository) === null || _pkg$repository2 === void 0 ? void 0 : _pkg$repository2.url);
|
|
606
|
-
const gitOrigin = requireUserConfirmation ? await _package$1.promptForRepoOrigin(options, repoUrl) : repoUrl;
|
|
607
|
-
cli.log.debug("Remote origin: %s", gitOrigin || "<none>");
|
|
608
|
-
const data = {
|
|
609
|
-
user,
|
|
610
|
-
pluginName,
|
|
611
|
-
license,
|
|
612
|
-
description,
|
|
613
|
-
pkg,
|
|
614
|
-
gitOrigin
|
|
615
|
-
};
|
|
616
|
-
let didWrite;
|
|
617
|
-
const newPkg = await _package$1.writePackageJson(data, options);
|
|
618
|
-
info(newPkg !== pkg, "Wrote package.json");
|
|
619
|
-
data.pkg = newPkg;
|
|
620
|
-
didWrite = await writeLicense(data, options, licenseChanged);
|
|
621
|
-
info(didWrite, "Wrote license file (LICENSE)");
|
|
622
|
-
didWrite = await writeReadme(data, options);
|
|
623
|
-
info(didWrite, "Wrote readme file (README.md)");
|
|
624
|
-
didWrite = await writeStaticAssets(options);
|
|
625
|
-
info(didWrite.length > 0, "Wrote static asset files: %s", didWrite.join(", "));
|
|
626
|
-
didWrite = await _package$1.addBuildScripts(newPkg, options);
|
|
627
|
-
info(didWrite, "Added build scripts to package.json");
|
|
628
|
-
didWrite = await addCompileDirToGitIgnore(data, options);
|
|
629
|
-
info(didWrite, "Added compilation output directory to .gitignore");
|
|
630
|
-
}
|
|
631
|
-
async function writeReadme(data, options) {
|
|
632
|
-
const {
|
|
633
|
-
basePath
|
|
634
|
-
} = options;
|
|
635
|
-
const readmePath = path__default.default.join(basePath, "README.md");
|
|
636
|
-
const readme = await _package$1.readFile(readmePath, "utf8").catch(_package$1.errorToUndefined);
|
|
637
|
-
if (readme && !isDefaultGitHubReadme(readme)) {
|
|
638
|
-
return false;
|
|
639
|
-
}
|
|
640
|
-
await _package$1.writeFileWithOverwritePrompt(readmePath, generateReadme(data), {
|
|
641
|
-
encoding: "utf8",
|
|
642
|
-
force: options.flags.force
|
|
643
|
-
});
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
async function writeLicense(_ref3, options, licenseChanged) {
|
|
647
|
-
let {
|
|
648
|
-
license
|
|
649
|
-
} = _ref3;
|
|
650
|
-
const {
|
|
651
|
-
basePath,
|
|
652
|
-
flags
|
|
653
|
-
} = options;
|
|
654
|
-
if (flags.license === false || !license) {
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
const hasLicenseMdFile = await _package$1.fileExists(path__default.default.join(basePath, "LICENSE.md"));
|
|
658
|
-
const licensePath = path__default.default.join(basePath, hasLicenseMdFile ? "LICENSE.md" : "LICENSE");
|
|
659
|
-
await _package$1.writeFileWithOverwritePrompt(licensePath, license.text, {
|
|
660
|
-
encoding: "utf8",
|
|
661
|
-
default: licenseChanged,
|
|
662
|
-
force: flags.force
|
|
663
|
-
});
|
|
664
|
-
return true;
|
|
665
|
-
}
|
|
666
|
-
async function getLicense(flags, _ref4) {
|
|
667
|
-
let {
|
|
668
|
-
user,
|
|
669
|
-
pluginName,
|
|
670
|
-
pkg,
|
|
671
|
-
requireUserConfirmation
|
|
672
|
-
} = _ref4;
|
|
673
|
-
const license = await getLicenseIdentifier(flags, pkg, requireUserConfirmation);
|
|
674
|
-
if (!license) {
|
|
675
|
-
return void 0;
|
|
676
|
-
}
|
|
677
|
-
const text = license.body.replace(/\[fullname\]/g, user === null || user === void 0 ? void 0 : user.name).replace(/\[project\]/g, pluginName).replace(/\[year\]/g, ( /* @__PURE__ */new Date()).getFullYear());
|
|
678
|
-
return {
|
|
679
|
-
id: license.id,
|
|
680
|
-
text
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
async function getLicenseIdentifier(flags, pkg) {
|
|
684
|
-
let requireUserConfirmation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
685
|
-
if (flags.license === false) {
|
|
686
|
-
return null;
|
|
687
|
-
}
|
|
688
|
-
if (typeof flags.license === "string") {
|
|
689
|
-
const license = licenses__default.default.find("".concat(flags.license));
|
|
690
|
-
if (!license) {
|
|
691
|
-
throw new Error("License \"".concat(flags.license, "\" not found"));
|
|
692
|
-
}
|
|
693
|
-
return license;
|
|
694
|
-
}
|
|
695
|
-
if (pkg && pkg.license && !requireUserConfirmation) {
|
|
696
|
-
const license = licenses__default.default.find("".concat(pkg.license));
|
|
697
|
-
if (license) {
|
|
698
|
-
return license;
|
|
699
|
-
}
|
|
700
|
-
cli.log.warn("package.json contains license \"".concat(pkg.license, "\", which is not recognized"));
|
|
701
|
-
}
|
|
702
|
-
const licenseId = await _package$1.prompt("Which license do you want to use?", {
|
|
703
|
-
default: pkg && pkg.license && licenses__default.default.find(pkg.license) ? pkg.license : preferredLicenses[0],
|
|
704
|
-
choices: [_package$1.prompt.separator(), ...preferredLicenses.map(value => ({
|
|
705
|
-
value,
|
|
706
|
-
name: licenses__default.default.list[value].title
|
|
707
|
-
})), _package$1.prompt.separator(), ...otherLicenses.map(value => ({
|
|
708
|
-
value,
|
|
709
|
-
name: licenses__default.default.list[value].title
|
|
710
|
-
}))]
|
|
711
|
-
});
|
|
712
|
-
return licenses__default.default.find(licenseId);
|
|
713
|
-
}
|
|
714
|
-
async function getProjectDescription(basePath, pkg) {
|
|
715
|
-
var _description;
|
|
716
|
-
let requireUserConfirmation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
717
|
-
let description = await resolveProjectDescription(basePath, pkg);
|
|
718
|
-
if (requireUserConfirmation) {
|
|
719
|
-
description = await _package$1.prompt("Plugin description", {
|
|
720
|
-
default: description || ""
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
return (_description = description) !== null && _description !== void 0 ? _description : "";
|
|
724
|
-
}
|
|
725
|
-
async function resolveProjectDescription(basePath, pkg) {
|
|
726
|
-
if (pkg && typeof pkg.description === "string" && pkg.description.length > 5) {
|
|
727
|
-
return pkg.description;
|
|
728
|
-
}
|
|
729
|
-
try {
|
|
730
|
-
const readmePath = path__default.default.join(basePath, "README.md");
|
|
731
|
-
const readme = await _package$1.readFile(readmePath, "utf8");
|
|
732
|
-
const [title, description] = readme.split("\n").filter(Boolean);
|
|
733
|
-
if (!title || !description || !title.match(/^#\s+\w+/)) {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
const unlinked = description.replace(/\[(.*?)\]\(.*?\)/g, "$1");
|
|
737
|
-
if (/^[^#]/.test(unlinked)) {
|
|
738
|
-
return unlinked;
|
|
739
|
-
}
|
|
740
|
-
return null;
|
|
741
|
-
} catch (err) {
|
|
742
|
-
return _package$1.errorToUndefined(err);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
async function writeAssets(injectables, _ref5) {
|
|
746
|
-
let {
|
|
747
|
-
basePath,
|
|
748
|
-
flags
|
|
749
|
-
} = _ref5;
|
|
750
|
-
const assetsDir = await findAssetsDir();
|
|
751
|
-
const from = function () {
|
|
752
|
-
for (var _len3 = arguments.length, segments = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
753
|
-
segments[_key3] = arguments[_key3];
|
|
754
|
-
}
|
|
755
|
-
return path__default.default.join(assetsDir, "inject", ...segments);
|
|
756
|
-
};
|
|
757
|
-
const to = function () {
|
|
758
|
-
for (var _len4 = arguments.length, segments = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
759
|
-
segments[_key4] = arguments[_key4];
|
|
760
|
-
}
|
|
761
|
-
return path__default.default.join(basePath, ...segments);
|
|
762
|
-
};
|
|
763
|
-
const writes = [];
|
|
764
|
-
for (const injectable of injectables) {
|
|
765
|
-
if (injectable.type === "copy") {
|
|
766
|
-
const fromPath = asArray(injectable.from);
|
|
767
|
-
const toPath = asArray(injectable.to);
|
|
768
|
-
if (await _package$1.copyFileWithOverwritePrompt(from(...fromPath), to(...toPath), flags)) {
|
|
769
|
-
writes.push(path__default.default.join(...toPath));
|
|
770
|
-
}
|
|
771
|
-
continue;
|
|
772
|
-
}
|
|
773
|
-
if (injectable.type === "template") {
|
|
774
|
-
const toPath = asArray(injectable.to);
|
|
775
|
-
await _package$1.writeFileWithOverwritePrompt(to(...toPath), "".concat(injectable.value.trim(), "\n"), {
|
|
776
|
-
default: "n",
|
|
777
|
-
force: injectable.force || flags.force
|
|
778
|
-
});
|
|
779
|
-
writes.push(path__default.default.join(...toPath));
|
|
780
|
-
continue;
|
|
781
|
-
}
|
|
782
|
-
throw new Error("Unknown operation type \"".concat(injectable.type, "\""));
|
|
783
|
-
}
|
|
784
|
-
return writes;
|
|
785
|
-
}
|
|
786
|
-
async function writeStaticAssets(options) {
|
|
787
|
-
const {
|
|
788
|
-
outDir,
|
|
789
|
-
flags
|
|
790
|
-
} = options;
|
|
791
|
-
const files = [flags.eslint && eslintrcTemplate({
|
|
792
|
-
flags: options.flags
|
|
793
|
-
}), flags.eslint && eslintignoreTemplate({
|
|
794
|
-
outDir,
|
|
795
|
-
flags: options.flags
|
|
796
|
-
}), {
|
|
797
|
-
type: "copy",
|
|
798
|
-
from: "editorconfig",
|
|
799
|
-
to: ".editorconfig"
|
|
800
|
-
}, {
|
|
801
|
-
type: "copy",
|
|
802
|
-
from: "sanity.json",
|
|
803
|
-
to: "sanity.json"
|
|
804
|
-
}, {
|
|
805
|
-
type: "copy",
|
|
806
|
-
from: "v2-incompatible.js.template",
|
|
807
|
-
to: "v2-incompatible.js"
|
|
808
|
-
}, pkgConfigTemplate({
|
|
809
|
-
outDir,
|
|
810
|
-
flags: options.flags
|
|
811
|
-
}), flags.gitignore && gitignoreTemplate(), flags.typescript && tsconfigTemplate({
|
|
812
|
-
flags: options.flags
|
|
813
|
-
}), flags.typescript && tsconfigTemplateDist({
|
|
814
|
-
outDir,
|
|
815
|
-
flags: options.flags
|
|
816
|
-
}), flags.typescript && tsconfigTemplateSettings({
|
|
817
|
-
flags: options.flags
|
|
818
|
-
}), flags.prettier && prettierignoreTemplate({
|
|
819
|
-
outDir
|
|
820
|
-
}), flags.prettier && {
|
|
821
|
-
type: "copy",
|
|
822
|
-
from: "prettierrc.json",
|
|
823
|
-
to: ".prettierrc"
|
|
824
|
-
}].map(f => f ? f : void 0).filter(f => !!f);
|
|
825
|
-
const result = writeAssets(files, options);
|
|
826
|
-
return result;
|
|
827
|
-
}
|
|
828
|
-
function asArray(input) {
|
|
829
|
-
return typeof input === "string" ? [input] : input;
|
|
830
|
-
}
|
|
831
|
-
async function findAssetsDir() {
|
|
832
|
-
let maxBackpaddle = 3;
|
|
833
|
-
let currDir = __dirname;
|
|
834
|
-
let assetsDir = "";
|
|
835
|
-
while (!assetsDir && maxBackpaddle) {
|
|
836
|
-
currDir = path__default.default.join(currDir, "..");
|
|
837
|
-
const assets = path__default.default.join(currDir, "assets");
|
|
838
|
-
if (await _package$1.fileExists(assets)) {
|
|
839
|
-
assetsDir = assets;
|
|
840
|
-
} else {
|
|
841
|
-
maxBackpaddle--;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
if (!assetsDir) {
|
|
845
|
-
throw new Error("Could not find assets directory!");
|
|
846
|
-
}
|
|
847
|
-
return assetsDir;
|
|
848
|
-
}
|
|
849
|
-
async function addCompileDirToGitIgnore(data, options) {
|
|
850
|
-
var _data$pkg$main, _data$pkg, _data$pkg2;
|
|
851
|
-
const gitIgnorePath = path__default.default.join(options.basePath, ".gitignore");
|
|
852
|
-
const gitignore = await _package$1.readFile(gitIgnorePath, "utf8").catch(_package$1.errorToUndefined);
|
|
853
|
-
if (!gitignore) {
|
|
854
|
-
return false;
|
|
855
|
-
}
|
|
856
|
-
const output = (_data$pkg$main = (_data$pkg = data.pkg) === null || _data$pkg === void 0 ? void 0 : _data$pkg.main) !== null && _data$pkg$main !== void 0 ? _data$pkg$main : (_data$pkg2 = data.pkg) === null || _data$pkg2 === void 0 ? void 0 : _data$pkg2.module;
|
|
857
|
-
if (!output) {
|
|
858
|
-
return false;
|
|
859
|
-
}
|
|
860
|
-
const ignorePath = output.replace(/^[./]+/, "");
|
|
861
|
-
const ignore = ignorePath.split("/")[0];
|
|
862
|
-
if (!ignore) {
|
|
863
|
-
return false;
|
|
864
|
-
}
|
|
865
|
-
const lines = gitignore.trim().split("\n");
|
|
866
|
-
if (lines.includes(ignore)) {
|
|
867
|
-
return false;
|
|
868
|
-
}
|
|
869
|
-
lines.push("", "# Compiled plugin", ignore);
|
|
870
|
-
await _package$1.writeFile(gitIgnorePath, lines.join("\n") + "\n", {
|
|
871
|
-
encoding: "utf8"
|
|
872
|
-
});
|
|
873
|
-
return true;
|
|
874
|
-
}
|
|
875
|
-
function defaultSourceJs(pkg) {
|
|
876
|
-
return outdent__default.default(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\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 '", "'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin({})],\n * })\n * ```\n */\n export const myPlugin = definePlugin((config = {}) => {\n // eslint-disable-next-line no-console\n console.log(`hello from ", "`)\n return {\n name: '", "',\n }\n })\n"], ["\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 '", "'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin({})],\n * })\n * \\`\\`\\`\n */\n export const myPlugin = definePlugin((config = {}) => {\n // eslint-disable-next-line no-console\n console.log(\\`hello from ", "\\`)\n return {\n name: '", "',\n }\n })\n"])), pkg.name, pkg.name, pkg.name).trimStart() + "\n";
|
|
877
|
-
}
|
|
878
|
-
function defaultSourceTs(pkg) {
|
|
879
|
-
return outdent__default.default(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\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 '", "'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin()],\n * })\n * ```\n */\n export const myPlugin = definePlugin<MyPluginConfig | void>((config = {}) => {\n // eslint-disable-next-line no-console\n console.log('hello from ", "')\n return {\n name: '", "',\n }\n })\n"], ["\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 '", "'\n *\n * export default defineConfig({\n * // ...\n * plugins: [myPlugin()],\n * })\n * \\`\\`\\`\n */\n export const myPlugin = definePlugin<MyPluginConfig | void>((config = {}) => {\n // eslint-disable-next-line no-console\n console.log('hello from ", "')\n return {\n name: '", "',\n }\n })\n"])), pkg.name, pkg.name, pkg.name).trimStart() + "\n";
|
|
880
|
-
}
|
|
881
|
-
const initFlags = {
|
|
882
|
-
...cli.sharedFlags,
|
|
883
|
-
scripts: {
|
|
884
|
-
type: "boolean",
|
|
885
|
-
default: true
|
|
886
|
-
},
|
|
887
|
-
eslint: {
|
|
888
|
-
type: "boolean",
|
|
889
|
-
default: true
|
|
890
|
-
},
|
|
891
|
-
typescript: {
|
|
892
|
-
type: "boolean",
|
|
893
|
-
default: true
|
|
894
|
-
},
|
|
895
|
-
prettier: {
|
|
896
|
-
type: "boolean",
|
|
897
|
-
default: true
|
|
898
|
-
},
|
|
899
|
-
license: {
|
|
900
|
-
type: "string"
|
|
901
|
-
},
|
|
902
|
-
editorconfig: {
|
|
903
|
-
type: "boolean",
|
|
904
|
-
default: true
|
|
905
|
-
},
|
|
906
|
-
gitignore: {
|
|
907
|
-
type: "boolean",
|
|
908
|
-
default: true
|
|
909
|
-
},
|
|
910
|
-
force: {
|
|
911
|
-
type: "boolean",
|
|
912
|
-
default: false
|
|
913
|
-
},
|
|
914
|
-
install: {
|
|
915
|
-
type: "boolean",
|
|
916
|
-
default: true
|
|
917
|
-
},
|
|
918
|
-
name: {
|
|
919
|
-
type: "string"
|
|
920
|
-
},
|
|
921
|
-
author: {
|
|
922
|
-
type: "string"
|
|
923
|
-
},
|
|
924
|
-
repo: {
|
|
925
|
-
type: "string"
|
|
926
|
-
},
|
|
927
|
-
presetOnly: {
|
|
928
|
-
type: "boolean",
|
|
929
|
-
default: false
|
|
930
|
-
},
|
|
931
|
-
preset: {
|
|
932
|
-
type: "string",
|
|
933
|
-
isMultiple: true
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
async function init(options) {
|
|
937
|
-
let dependencies = {};
|
|
938
|
-
let devDependencies = {};
|
|
939
|
-
let peerDependencies = {};
|
|
940
|
-
await inject({
|
|
941
|
-
...options,
|
|
942
|
-
outDir: cli.defaultOutDir,
|
|
943
|
-
requireUserConfirmation: !options.flags.force,
|
|
944
|
-
dependencies,
|
|
945
|
-
devDependencies,
|
|
946
|
-
peerDependencies,
|
|
947
|
-
validate: false
|
|
948
|
-
});
|
|
949
|
-
const packageJson = await _package$1.getPackage({
|
|
950
|
-
basePath: options.basePath,
|
|
951
|
-
validate: false
|
|
952
|
-
});
|
|
953
|
-
const typescript = options.flags.typescript;
|
|
954
|
-
const source = typescript ? defaultSourceTs(packageJson) : defaultSourceJs(packageJson);
|
|
955
|
-
const filename = typescript ? "index.ts" : "index.js";
|
|
956
|
-
const srcDir = path__default.default.resolve(options.basePath, "src");
|
|
957
|
-
await _package$1.ensureDir(srcDir);
|
|
958
|
-
await _package$1.writeFile(path__default.default.join(srcDir, filename), source, {
|
|
959
|
-
encoding: "utf8"
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
exports.init = init;
|
|
963
|
-
exports.initFlags = initFlags;
|
|
964
|
-
exports.inject = inject;
|
|
965
|
-
exports.presetHelpList = presetHelpList;
|
|
966
|
-
//# sourceMappingURL=init-iwJScjA2.js.map
|