@sanity/plugin-kit 2.1.19 → 2.2.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/README.md +1 -0
- package/assets/inject/ui-workshop/src/CustomField.tsx +15 -0
- package/assets/inject/ui-workshop/src/__workshop__/index.tsx +14 -0
- package/assets/inject/ui-workshop/src/__workshop__/props.tsx +20 -0
- package/assets/inject/ui-workshop/workshop.config.ts +5 -0
- package/lib/package.json +4 -3
- package/lib/src/cmds/init.js +1 -1
- package/lib/src/cmds/inject.js +1 -1
- package/lib/src/presets/presets.js +2 -1
- package/lib/src/presets/presets.js.map +1 -1
- package/lib/src/presets/ui-workshop.d.ts +2 -0
- package/lib/src/presets/ui-workshop.js +88 -0
- package/lib/src/presets/ui-workshop.js.map +1 -0
- package/package.json +4 -3
- package/src/cmds/init.ts +1 -1
- package/src/cmds/inject.ts +1 -1
- package/src/presets/presets.ts +2 -1
- package/src/presets/ui-workshop.ts +81 -0
package/README.md
CHANGED
|
@@ -198,6 +198,7 @@ The inject command can do more work by adding presets. Consult the individual pr
|
|
|
198
198
|
|
|
199
199
|
* [semver-workflow](./docs/semver-workflow.md) - Add an opinionated Github workflow to automate NPM releases
|
|
200
200
|
* [renovatebot](./docs/renovatebot.md) - Add opinionated Renovatebot config to make dependency management a breeze
|
|
201
|
+
* [ui-workshop](./docs/ui-workshop.md) - Add [@sanity/ui-workshop](https://github.com/sanity-io/ui-workshop) to make component testing a breeze
|
|
201
202
|
|
|
202
203
|
## Testing a plugin in Sanity Studio
|
|
203
204
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Box, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import React, {ReactNode} from 'react'
|
|
3
|
+
|
|
4
|
+
export function CustomField(props: {children?: ReactNode; title?: ReactNode}) {
|
|
5
|
+
const {children, title} = props
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<Stack space={3}>
|
|
9
|
+
<Text size={1} weight="semibold">
|
|
10
|
+
{title}
|
|
11
|
+
</Text>
|
|
12
|
+
<Box>{children}</Box>
|
|
13
|
+
</Stack>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {defineScope} from '@sanity/ui-workshop'
|
|
2
|
+
import {lazy} from 'react'
|
|
3
|
+
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'custom',
|
|
6
|
+
title: 'Custom (example)',
|
|
7
|
+
stories: [
|
|
8
|
+
{
|
|
9
|
+
name: 'props',
|
|
10
|
+
title: 'Props',
|
|
11
|
+
component: lazy(() => import('./props')),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {Box, Card, Container, Text} from '@sanity/ui'
|
|
2
|
+
import {useString} from '@sanity/ui-workshop'
|
|
3
|
+
import {CustomField} from '../CustomField'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
export default function PropsStory() {
|
|
7
|
+
const title = useString('Title', 'My custom field')
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Container width={1}>
|
|
11
|
+
<Box paddingX={4} paddingY={[5, 6, 7]}>
|
|
12
|
+
<CustomField title={title}>
|
|
13
|
+
<Card border padding={3}>
|
|
14
|
+
<Text>This is just an example</Text>
|
|
15
|
+
</Card>
|
|
16
|
+
</CustomField>
|
|
17
|
+
</Box>
|
|
18
|
+
</Container>
|
|
19
|
+
)
|
|
20
|
+
}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/plugin-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Enhanced Sanity.io plugin development experience",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -89,8 +89,9 @@
|
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@commitlint/cli": "^17.2.0",
|
|
91
91
|
"@commitlint/config-conventional": "^17.2.0",
|
|
92
|
-
"@sanity/pkg-utils": "^1.
|
|
92
|
+
"@sanity/pkg-utils": "^1.20.1",
|
|
93
93
|
"@sanity/semantic-release-preset": "^2.0.2",
|
|
94
|
+
"@sanity/ui-workshop": "^1.0.1",
|
|
94
95
|
"@types/eslint": "^8.4.10",
|
|
95
96
|
"@types/fs-extra": "^9.0.13",
|
|
96
97
|
"@types/inquirer": "^9.0.3",
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"prettier-plugin-packagejson": "^2.3.0",
|
|
113
114
|
"readdirp": "^3.6.0",
|
|
114
115
|
"rimraf": "^3.0.2",
|
|
115
|
-
"sanity": "3.0.0
|
|
116
|
+
"sanity": "^3.0.0",
|
|
116
117
|
"sinon": "^14.0.2",
|
|
117
118
|
"tap": "^16.3.1",
|
|
118
119
|
"ts-node": "^10.9.1",
|
package/lib/src/cmds/init.js
CHANGED
|
@@ -43,7 +43,7 @@ Options
|
|
|
43
43
|
--license [spdx] Use the license with the given SPDX identifier
|
|
44
44
|
--force No promt when overwriting files
|
|
45
45
|
|
|
46
|
-
--preset [preset-name]
|
|
46
|
+
--preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.
|
|
47
47
|
The following presets are available:
|
|
48
48
|
${(0, presets_1.presetHelpList)(30)}
|
|
49
49
|
|
package/lib/src/cmds/inject.js
CHANGED
|
@@ -37,7 +37,7 @@ Options
|
|
|
37
37
|
--license [spdx] Use the license with the given SPDX identifier
|
|
38
38
|
--force No promt when overwriting files
|
|
39
39
|
|
|
40
|
-
--preset [preset-name]
|
|
40
|
+
--preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.
|
|
41
41
|
The following presets are available:
|
|
42
42
|
${(0, presets_1.presetHelpList)(30)}
|
|
43
43
|
--preset-only Skips the default inject steps. Use this to apply a preset to an otherwise complete plugin.
|
|
@@ -12,7 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.injectPresets = exports.presetHelpList = void 0;
|
|
13
13
|
const semver_workflow_1 = require("./semver-workflow");
|
|
14
14
|
const renovatebot_1 = require("./renovatebot");
|
|
15
|
-
const
|
|
15
|
+
const ui_workshop_1 = require("./ui-workshop");
|
|
16
|
+
const presets = [semver_workflow_1.semverWorkflowPreset, renovatebot_1.renovatePreset, ui_workshop_1.uiWorkshop];
|
|
16
17
|
const presetNames = presets.map((p) => p === null || p === void 0 ? void 0 : p.name);
|
|
17
18
|
function presetHelpList(padStart) {
|
|
18
19
|
return presets
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../../src/presets/presets.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAAsD;AACtD,+CAA4C;
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../../src/presets/presets.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAAsD;AACtD,+CAA4C;AAC5C,+CAAwC;AAQxC,MAAM,OAAO,GAAa,CAAC,sCAAoB,EAAE,4BAAc,EAAE,wBAAU,CAAC,CAAA;AAC5E,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,CAAA;AAE/C,SAAgB,cAAc,CAAC,QAAgB;IAC7C,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;SAC1E,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAJD,wCAIC;AAED,SAAsB,aAAa,CAAC,OAAsB;;;QACxD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CA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_arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.uiWorkshop = void 0;
|
|
16
|
+
const inject_1 = require("../actions/inject");
|
|
17
|
+
const package_1 = require("../npm/package");
|
|
18
|
+
const log_1 = __importDefault(require("../util/log"));
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
const outdent_1 = __importDefault(require("outdent"));
|
|
21
|
+
const resolveLatestVersions_1 = require("../npm/resolveLatestVersions");
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const files_1 = require("../util/files");
|
|
24
|
+
const errorToUndefined_1 = require("../util/errorToUndefined");
|
|
25
|
+
exports.uiWorkshop = {
|
|
26
|
+
name: 'ui-workshop',
|
|
27
|
+
description: 'Files for testing custom components with @sanity/ui-workshop',
|
|
28
|
+
apply: applyPreset,
|
|
29
|
+
};
|
|
30
|
+
function applyPreset(options) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
yield (0, inject_1.writeAssets)(files(), options);
|
|
33
|
+
yield addDevDependencies(options);
|
|
34
|
+
yield updateGitIgnore(options);
|
|
35
|
+
log_1.default.info(chalk_1.default.green((0, outdent_1.default) `
|
|
36
|
+
ui-workshop preset injected.
|
|
37
|
+
|
|
38
|
+
Please confer
|
|
39
|
+
https://github.com/sanity-io/plugin-kit/blob/main/docs/ui-workshop.md#manual-steps-after-inject
|
|
40
|
+
to finalize configuration for this preset.
|
|
41
|
+
`.trim()));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function files() {
|
|
45
|
+
return [
|
|
46
|
+
{ from: ['workshop.config.ts'], to: ['workshop.config.ts'] },
|
|
47
|
+
{ from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx'] },
|
|
48
|
+
{ from: ['src', '__workshop__', 'index.tsx'], to: ['src', '__workshop__', 'index.tsx'] },
|
|
49
|
+
{ from: ['src', '__workshop__', 'props.tsx'], to: ['src', '__workshop__', 'props.tsx'] },
|
|
50
|
+
].map((fromTo) => (Object.assign(Object.assign({}, fromTo), { from: ['ui-workshop', ...fromTo.from] })));
|
|
51
|
+
}
|
|
52
|
+
function updateGitIgnore(options) {
|
|
53
|
+
var _a;
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const { basePath } = options;
|
|
56
|
+
const gitignorePath = path_1.default.join(basePath, '.gitignore');
|
|
57
|
+
let gitignore = (_a = (yield (0, files_1.readFile)(gitignorePath, 'utf8').catch(errorToUndefined_1.errorToUndefined))) !== null && _a !== void 0 ? _a : '';
|
|
58
|
+
const value = '.workshop';
|
|
59
|
+
if (gitignore.includes(value)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
gitignore += `\n\n${value}`;
|
|
63
|
+
yield (0, files_1.writeFile)(gitignorePath, gitignore, { encoding: 'utf8' });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function addDevDependencies(options) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const pkg = yield (0, package_1.getPackage)(options);
|
|
69
|
+
const devDeps = (0, package_1.sortKeys)(Object.assign(Object.assign({}, pkg.devDependencies), (yield devDependencies())));
|
|
70
|
+
const newPkg = Object.assign({}, pkg);
|
|
71
|
+
newPkg.devDependencies = devDeps;
|
|
72
|
+
yield (0, package_1.writePackageJsonDirect)(newPkg, options);
|
|
73
|
+
log_1.default.info('Updated devDependencies.');
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function devDependencies() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return (0, resolveLatestVersions_1.resolveLatestVersions)([
|
|
79
|
+
'@sanity/ui-workshop',
|
|
80
|
+
'@sanity/icons',
|
|
81
|
+
'@sanity/ui',
|
|
82
|
+
'react',
|
|
83
|
+
'react-dom',
|
|
84
|
+
'styled-component',
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=ui-workshop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-workshop.js","sourceRoot":"","sources":["../../../src/presets/ui-workshop.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,8CAAoE;AACpE,4CAA2E;AAC3E,sDAA6B;AAC7B,kDAAyB;AACzB,sDAA6B;AAC7B,wEAAkE;AAClE,gDAAuB;AACvB,yCAAiD;AACjD,+DAAyD;AAE5C,QAAA,UAAU,GAAW;IAChC,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,8DAA8D;IAC3E,KAAK,EAAE,WAAW;CACnB,CAAA;AAED,SAAe,WAAW,CAAC,OAAsB;;QAC/C,MAAM,IAAA,oBAAW,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAA;QACnC,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAA;QACjC,MAAM,eAAe,CAAC,OAAO,CAAC,CAAA;QAC9B,aAAG,CAAC,IAAI,CACN,eAAK,CAAC,KAAK,CACT,IAAA,iBAAO,EAAA;;;;;;GAMV,CAAC,IAAI,EAAE,CACL,CACF,CAAA;IACH,CAAC;CAAA;AAED,SAAS,KAAK;IACZ,OAAO;QACL,EAAC,IAAI,EAAE,CAAC,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,oBAAU,EAAC,OAAO,CAAC,CAAA;QACrC,MAAM,OAAO,GAAG,IAAA,kBAAQ,kCACnB,GAAG,CAAC,eAAe,GACnB,CAAC,MAAM,eAAe,EAAE,CAAC,EAC5B,CAAA;QACF,MAAM,MAAM,qBAAO,GAAG,CAAC,CAAA;QACvB,MAAM,CAAC,eAAe,GAAG,OAAO,CAAA;QAChC,MAAM,IAAA,gCAAsB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7C,aAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IACtC,CAAC;CAAA;AAED,SAAe,eAAe;;QAC5B,OAAO,IAAA,6CAAqB,EAAC;YAC3B,qBAAqB;YACrB,eAAe;YACf,YAAY;YACZ,OAAO;YACP,WAAW;YACX,kBAAkB;SACnB,CAAC,CAAA;IACJ,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/plugin-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Enhanced Sanity.io plugin development experience",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -89,8 +89,9 @@
|
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@commitlint/cli": "^17.2.0",
|
|
91
91
|
"@commitlint/config-conventional": "^17.2.0",
|
|
92
|
-
"@sanity/pkg-utils": "^1.
|
|
92
|
+
"@sanity/pkg-utils": "^1.20.1",
|
|
93
93
|
"@sanity/semantic-release-preset": "^2.0.2",
|
|
94
|
+
"@sanity/ui-workshop": "^1.0.1",
|
|
94
95
|
"@types/eslint": "^8.4.10",
|
|
95
96
|
"@types/fs-extra": "^9.0.13",
|
|
96
97
|
"@types/inquirer": "^9.0.3",
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"prettier-plugin-packagejson": "^2.3.0",
|
|
113
114
|
"readdirp": "^3.6.0",
|
|
114
115
|
"rimraf": "^3.0.2",
|
|
115
|
-
"sanity": "3.0.0
|
|
116
|
+
"sanity": "^3.0.0",
|
|
116
117
|
"sinon": "^14.0.2",
|
|
117
118
|
"tap": "^16.3.1",
|
|
118
119
|
"ts-node": "^10.9.1",
|
package/src/cmds/init.ts
CHANGED
|
@@ -31,7 +31,7 @@ Options
|
|
|
31
31
|
--license [spdx] Use the license with the given SPDX identifier
|
|
32
32
|
--force No promt when overwriting files
|
|
33
33
|
|
|
34
|
-
--preset [preset-name]
|
|
34
|
+
--preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.
|
|
35
35
|
The following presets are available:
|
|
36
36
|
${presetHelpList(30)}
|
|
37
37
|
|
package/src/cmds/inject.ts
CHANGED
|
@@ -25,7 +25,7 @@ Options
|
|
|
25
25
|
--license [spdx] Use the license with the given SPDX identifier
|
|
26
26
|
--force No promt when overwriting files
|
|
27
27
|
|
|
28
|
-
--preset [preset-name]
|
|
28
|
+
--preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.
|
|
29
29
|
The following presets are available:
|
|
30
30
|
${presetHelpList(30)}
|
|
31
31
|
--preset-only Skips the default inject steps. Use this to apply a preset to an otherwise complete plugin.
|
package/src/presets/presets.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {InjectOptions} from '../actions/inject'
|
|
2
2
|
import {semverWorkflowPreset} from './semver-workflow'
|
|
3
3
|
import {renovatePreset} from './renovatebot'
|
|
4
|
+
import {uiWorkshop} from './ui-workshop'
|
|
4
5
|
|
|
5
6
|
export interface Preset {
|
|
6
7
|
name: string
|
|
@@ -8,7 +9,7 @@ export interface Preset {
|
|
|
8
9
|
apply: (options: InjectOptions) => Promise<void>
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
const presets: Preset[] = [semverWorkflowPreset, renovatePreset]
|
|
12
|
+
const presets: Preset[] = [semverWorkflowPreset, renovatePreset, uiWorkshop]
|
|
12
13
|
const presetNames = presets.map((p) => p?.name)
|
|
13
14
|
|
|
14
15
|
export function presetHelpList(padStart: number) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {Preset} from './presets'
|
|
2
|
+
import {FromTo, InjectOptions, writeAssets} from '../actions/inject'
|
|
3
|
+
import {getPackage, sortKeys, writePackageJsonDirect} from '../npm/package'
|
|
4
|
+
import log from '../util/log'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import outdent from 'outdent'
|
|
7
|
+
import {resolveLatestVersions} from '../npm/resolveLatestVersions'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import {readFile, writeFile} from '../util/files'
|
|
10
|
+
import {errorToUndefined} from '../util/errorToUndefined'
|
|
11
|
+
|
|
12
|
+
export const uiWorkshop: Preset = {
|
|
13
|
+
name: 'ui-workshop',
|
|
14
|
+
description: 'Files for testing custom components with @sanity/ui-workshop',
|
|
15
|
+
apply: applyPreset,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function applyPreset(options: InjectOptions) {
|
|
19
|
+
await writeAssets(files(), options)
|
|
20
|
+
await addDevDependencies(options)
|
|
21
|
+
await updateGitIgnore(options)
|
|
22
|
+
log.info(
|
|
23
|
+
chalk.green(
|
|
24
|
+
outdent`
|
|
25
|
+
ui-workshop preset injected.
|
|
26
|
+
|
|
27
|
+
Please confer
|
|
28
|
+
https://github.com/sanity-io/plugin-kit/blob/main/docs/ui-workshop.md#manual-steps-after-inject
|
|
29
|
+
to finalize configuration for this preset.
|
|
30
|
+
`.trim()
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function files(): FromTo[] {
|
|
36
|
+
return [
|
|
37
|
+
{from: ['workshop.config.ts'], to: ['workshop.config.ts']},
|
|
38
|
+
{from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx']},
|
|
39
|
+
{from: ['src', '__workshop__', 'index.tsx'], to: ['src', '__workshop__', 'index.tsx']},
|
|
40
|
+
{from: ['src', '__workshop__', 'props.tsx'], to: ['src', '__workshop__', 'props.tsx']},
|
|
41
|
+
].map((fromTo) => ({
|
|
42
|
+
...fromTo,
|
|
43
|
+
from: ['ui-workshop', ...fromTo.from],
|
|
44
|
+
}))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function updateGitIgnore(options: InjectOptions) {
|
|
48
|
+
const {basePath} = options
|
|
49
|
+
const gitignorePath = path.join(basePath, '.gitignore')
|
|
50
|
+
let gitignore = (await readFile(gitignorePath, 'utf8').catch(errorToUndefined)) ?? ''
|
|
51
|
+
const value = '.workshop'
|
|
52
|
+
if (gitignore.includes(value)) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
gitignore += `\n\n${value}`
|
|
57
|
+
await writeFile(gitignorePath, gitignore, {encoding: 'utf8'})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function addDevDependencies(options: InjectOptions) {
|
|
61
|
+
const pkg = await getPackage(options)
|
|
62
|
+
const devDeps = sortKeys({
|
|
63
|
+
...pkg.devDependencies,
|
|
64
|
+
...(await devDependencies()),
|
|
65
|
+
})
|
|
66
|
+
const newPkg = {...pkg}
|
|
67
|
+
newPkg.devDependencies = devDeps
|
|
68
|
+
await writePackageJsonDirect(newPkg, options)
|
|
69
|
+
log.info('Updated devDependencies.')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function devDependencies(): Promise<Record<string, string>> {
|
|
73
|
+
return resolveLatestVersions([
|
|
74
|
+
'@sanity/ui-workshop',
|
|
75
|
+
'@sanity/icons',
|
|
76
|
+
'@sanity/ui',
|
|
77
|
+
'react',
|
|
78
|
+
'react-dom',
|
|
79
|
+
'styled-component',
|
|
80
|
+
])
|
|
81
|
+
}
|