storybooker 0.19.3 → 0.22.0-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/README.md +40 -18
- package/dist/adapters/_internal/queue.d.mts +127 -0
- package/dist/aws-dynamodb.d.mts +22 -0
- package/dist/aws-dynamodb.mjs +118 -0
- package/dist/aws-dynamodb.mjs.map +1 -0
- package/dist/aws-s3.d.mts +20 -0
- package/dist/aws-s3.mjs +96 -0
- package/dist/aws-s3.mjs.map +1 -0
- package/dist/azure-blob-storage.d.mts +20 -0
- package/dist/azure-blob-storage.mjs +126 -0
- package/dist/azure-blob-storage.mjs.map +1 -0
- package/dist/azure-cosmos-db.d.mts +23 -0
- package/dist/azure-cosmos-db.mjs +87 -0
- package/dist/azure-cosmos-db.mjs.map +1 -0
- package/dist/azure-data-tables.d.mts +23 -0
- package/dist/azure-data-tables.mjs +127 -0
- package/dist/azure-data-tables.mjs.map +1 -0
- package/dist/azure-easy-auth.d.mts +50 -0
- package/dist/azure-easy-auth.mjs +88 -0
- package/dist/azure-easy-auth.mjs.map +1 -0
- package/dist/azure-functions.d.mts +62 -0
- package/dist/azure-functions.mjs +147 -0
- package/dist/azure-functions.mjs.map +1 -0
- package/dist/fs.d.mts +37 -0
- package/dist/fs.mjs +240 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/gcp-big-table.d.mts +23 -0
- package/dist/gcp-big-table.mjs +92 -0
- package/dist/gcp-big-table.mjs.map +1 -0
- package/dist/gcp-firestore.d.mts +22 -0
- package/dist/gcp-firestore.mjs +87 -0
- package/dist/gcp-firestore.mjs.map +1 -0
- package/dist/gcp-storage.d.mts +20 -0
- package/dist/gcp-storage.mjs +96 -0
- package/dist/gcp-storage.mjs.map +1 -0
- package/dist/handlers/handle-process-zip.mjs +90 -0
- package/dist/handlers/handle-process-zip.mjs.map +1 -0
- package/dist/handlers/handle-purge.d.mts +12 -0
- package/dist/handlers/handle-purge.mjs +36 -0
- package/dist/handlers/handle-purge.mjs.map +1 -0
- package/dist/handlers/handle-serve-storybook.mjs +94 -0
- package/dist/handlers/handle-serve-storybook.mjs.map +1 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +62 -0
- package/dist/index.mjs.map +1 -0
- package/dist/models/builds-model.mjs +248 -0
- package/dist/models/builds-model.mjs.map +1 -0
- package/dist/models/builds-schema.d.mts +171 -0
- package/dist/models/builds-schema.mjs +67 -0
- package/dist/models/builds-schema.mjs.map +1 -0
- package/dist/models/projects-model.mjs +122 -0
- package/dist/models/projects-model.mjs.map +1 -0
- package/dist/models/projects-schema.d.mts +70 -0
- package/dist/models/projects-schema.mjs +37 -0
- package/dist/models/projects-schema.mjs.map +1 -0
- package/dist/models/tags-model.mjs +110 -0
- package/dist/models/tags-model.mjs.map +1 -0
- package/dist/models/tags-schema.d.mts +76 -0
- package/dist/models/tags-schema.mjs +34 -0
- package/dist/models/tags-schema.mjs.map +1 -0
- package/dist/models/~model.mjs +43 -0
- package/dist/models/~model.mjs.map +1 -0
- package/dist/models/~shared-schema.d.mts +1 -0
- package/dist/models/~shared-schema.mjs +20 -0
- package/dist/models/~shared-schema.mjs.map +1 -0
- package/dist/mysql.d.mts +39 -0
- package/dist/mysql.mjs +151 -0
- package/dist/mysql.mjs.map +1 -0
- package/dist/redis.d.mts +33 -0
- package/dist/redis.mjs +118 -0
- package/dist/redis.mjs.map +1 -0
- package/dist/routers/account-router.mjs +91 -0
- package/dist/routers/account-router.mjs.map +1 -0
- package/dist/routers/builds-router.mjs +347 -0
- package/dist/routers/builds-router.mjs.map +1 -0
- package/dist/routers/projects-router.mjs +236 -0
- package/dist/routers/projects-router.mjs.map +1 -0
- package/dist/routers/root-router.mjs +108 -0
- package/dist/routers/root-router.mjs.map +1 -0
- package/dist/routers/tags-router.mjs +269 -0
- package/dist/routers/tags-router.mjs.map +1 -0
- package/dist/routers/tasks-router.mjs +71 -0
- package/dist/routers/tasks-router.mjs.map +1 -0
- package/dist/urls.d.mts +47 -0
- package/dist/urls.mjs +208 -0
- package/dist/urls.mjs.map +1 -0
- package/dist/utils/adapter-utils.d.mts +14 -0
- package/dist/utils/adapter-utils.mjs +14 -0
- package/dist/utils/adapter-utils.mjs.map +1 -0
- package/dist/utils/auth.mjs +25 -0
- package/dist/utils/auth.mjs.map +1 -0
- package/dist/utils/error.d.mts +21 -0
- package/dist/utils/error.mjs +109 -0
- package/dist/utils/error.mjs.map +1 -0
- package/dist/utils/file-utils.mjs +16 -0
- package/dist/utils/file-utils.mjs.map +1 -0
- package/dist/utils/openapi-utils.mjs +45 -0
- package/dist/utils/openapi-utils.mjs.map +1 -0
- package/dist/utils/request.mjs +35 -0
- package/dist/utils/request.mjs.map +1 -0
- package/dist/utils/response.mjs +24 -0
- package/dist/utils/response.mjs.map +1 -0
- package/dist/utils/store.mjs +54 -0
- package/dist/utils/store.mjs.map +1 -0
- package/dist/utils/ui-utils.mjs +38 -0
- package/dist/utils/ui-utils.mjs.map +1 -0
- package/dist/utils/url-utils.d.mts +10 -0
- package/dist/utils/url-utils.mjs +54 -0
- package/dist/utils/url-utils.mjs.map +1 -0
- package/dist/~internal/adapter/auth.d.mts +123 -0
- package/dist/~internal/adapter/auth.mjs +20 -0
- package/dist/~internal/adapter/auth.mjs.map +1 -0
- package/dist/~internal/adapter/database.d.mts +240 -0
- package/dist/~internal/adapter/database.mjs +63 -0
- package/dist/~internal/adapter/database.mjs.map +1 -0
- package/dist/~internal/adapter/logger.d.mts +34 -0
- package/dist/~internal/adapter/logger.mjs +13 -0
- package/dist/~internal/adapter/logger.mjs.map +1 -0
- package/dist/~internal/adapter/storage.d.mts +208 -0
- package/dist/~internal/adapter/storage.mjs +63 -0
- package/dist/~internal/adapter/storage.mjs.map +1 -0
- package/dist/~internal/adapter/ui.d.mts +109 -0
- package/dist/~internal/adapter/ui.mjs +1 -0
- package/dist/~internal/adapter.d.mts +8 -0
- package/dist/~internal/adapter.mjs +6 -0
- package/dist/~internal/constants.d.mts +24 -0
- package/dist/~internal/constants.mjs +32 -0
- package/dist/~internal/constants.mjs.map +1 -0
- package/dist/~internal/mimes.d.mts +449 -0
- package/dist/~internal/mimes.mjs +454 -0
- package/dist/~internal/mimes.mjs.map +1 -0
- package/dist/~internal/router.d.mts +1651 -0
- package/dist/~internal/router.mjs +39 -0
- package/dist/~internal/router.mjs.map +1 -0
- package/dist/~internal/types.d.mts +77 -0
- package/dist/~internal/types.mjs +1 -0
- package/dist/~internal/utils.d.mts +4 -0
- package/dist/~internal/utils.mjs +5 -0
- package/openapi.json +3162 -0
- package/package.json +148 -27
- package/src/adapters/_internal/auth.ts +135 -0
- package/src/adapters/_internal/database.ts +241 -0
- package/src/adapters/_internal/index.ts +8 -0
- package/src/adapters/_internal/logger.ts +41 -0
- package/src/adapters/_internal/queue.ts +151 -0
- package/src/adapters/_internal/storage.ts +197 -0
- package/src/adapters/_internal/ui.ts +103 -0
- package/src/adapters/aws-dynamodb.ts +201 -0
- package/src/adapters/aws-s3.ts +160 -0
- package/src/adapters/azure-blob-storage.ts +223 -0
- package/src/adapters/azure-cosmos-db.ts +158 -0
- package/src/adapters/azure-data-tables.ts +223 -0
- package/src/adapters/azure-easy-auth.ts +174 -0
- package/src/adapters/azure-functions.ts +242 -0
- package/src/adapters/fs.ts +398 -0
- package/src/adapters/gcp-big-table.ts +157 -0
- package/src/adapters/gcp-firestore.ts +146 -0
- package/src/adapters/gcp-storage.ts +141 -0
- package/src/adapters/mysql.ts +296 -0
- package/src/adapters/redis.ts +242 -0
- package/src/handlers/handle-process-zip.ts +117 -0
- package/src/handlers/handle-purge.ts +65 -0
- package/src/handlers/handle-serve-storybook.ts +101 -0
- package/src/index.ts +81 -16
- package/src/mocks/mock-auth-service.ts +51 -0
- package/src/mocks/mock-store.ts +26 -0
- package/src/models/builds-model.ts +373 -0
- package/src/models/builds-schema.ts +84 -0
- package/src/models/projects-model.ts +177 -0
- package/src/models/projects-schema.ts +69 -0
- package/src/models/tags-model.ts +138 -0
- package/src/models/tags-schema.ts +45 -0
- package/src/models/~model.ts +79 -0
- package/src/models/~shared-schema.ts +14 -0
- package/src/routers/_app-router.ts +57 -0
- package/src/routers/account-router.ts +136 -0
- package/src/routers/builds-router.ts +464 -0
- package/src/routers/projects-router.ts +309 -0
- package/src/routers/root-router.ts +127 -0
- package/src/routers/tags-router.ts +339 -0
- package/src/routers/tasks-router.ts +75 -0
- package/src/types.ts +107 -0
- package/src/urls.ts +327 -0
- package/src/utils/adapter-utils.ts +26 -0
- package/src/utils/auth.test.ts +71 -0
- package/src/utils/auth.ts +39 -0
- package/src/utils/constants.ts +31 -0
- package/src/utils/date-utils.ts +10 -0
- package/src/utils/error.test.ts +86 -0
- package/src/utils/error.ts +140 -0
- package/src/utils/file-utils.test.ts +65 -0
- package/src/utils/file-utils.ts +43 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/mime-utils.ts +457 -0
- package/src/utils/openapi-utils.ts +49 -0
- package/src/utils/request.ts +97 -0
- package/src/utils/response.ts +20 -0
- package/src/utils/store.ts +85 -0
- package/src/utils/story-utils.ts +42 -0
- package/src/utils/text-utils.ts +10 -0
- package/src/utils/ui-utils.ts +57 -0
- package/src/utils/url-utils.ts +113 -0
- package/dist/index.js +0 -554
- package/src/commands/create.ts +0 -263
- package/src/commands/purge.ts +0 -70
- package/src/commands/test.ts +0 -42
- package/src/service-schema.d.ts +0 -2023
- package/src/utils/auth-utils.ts +0 -31
- package/src/utils/pkg-utils.ts +0 -37
- package/src/utils/sb-build.ts +0 -55
- package/src/utils/sb-test.ts +0 -115
- package/src/utils/schema-utils.ts +0 -123
- package/src/utils/stream-utils.ts +0 -72
- package/src/utils/types.ts +0 -4
- package/src/utils/zip.ts +0 -77
package/src/commands/create.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
// oxlint-disable new-cap
|
|
2
|
-
// oxlint-disable max-lines-per-function
|
|
3
|
-
|
|
4
|
-
import * as fs from "node:fs";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import { styleText } from "node:util";
|
|
7
|
-
import createClient from "openapi-fetch";
|
|
8
|
-
import type { CommandModule } from "yargs";
|
|
9
|
-
import z from "zod";
|
|
10
|
-
import type { paths } from "../service-schema";
|
|
11
|
-
import { createAuthMiddleware } from "../utils/auth-utils";
|
|
12
|
-
import { buildStoryBook } from "../utils/sb-build";
|
|
13
|
-
import { testStoryBook } from "../utils/sb-test";
|
|
14
|
-
import {
|
|
15
|
-
sharedSchemas,
|
|
16
|
-
zodSchemaToCommandBuilder,
|
|
17
|
-
} from "../utils/schema-utils";
|
|
18
|
-
import { toReadableStream } from "../utils/stream-utils";
|
|
19
|
-
import type { ServiceClient } from "../utils/types";
|
|
20
|
-
import { zip } from "../utils/zip";
|
|
21
|
-
|
|
22
|
-
const CreateSchema = z.object({
|
|
23
|
-
project: sharedSchemas.project,
|
|
24
|
-
url: sharedSchemas.url,
|
|
25
|
-
cwd: sharedSchemas.cwd,
|
|
26
|
-
sha: z.string({ error: "URL is required to connect to the service." }).meta({
|
|
27
|
-
alias: ["id"],
|
|
28
|
-
description: "Unique ID of the build.",
|
|
29
|
-
}),
|
|
30
|
-
message: z
|
|
31
|
-
.string()
|
|
32
|
-
.optional()
|
|
33
|
-
.meta({ alias: ["m"], description: "Readable message for the build." }),
|
|
34
|
-
labels: z
|
|
35
|
-
.string()
|
|
36
|
-
.array()
|
|
37
|
-
.meta({
|
|
38
|
-
alias: ["l"],
|
|
39
|
-
description: "Labels associated with the build.",
|
|
40
|
-
}),
|
|
41
|
-
build: z
|
|
42
|
-
.union([z.string(), z.boolean()])
|
|
43
|
-
.optional()
|
|
44
|
-
.meta({
|
|
45
|
-
alias: ["b"],
|
|
46
|
-
description: "Name of the script in package.json to build the StoryBook.",
|
|
47
|
-
}),
|
|
48
|
-
test: z
|
|
49
|
-
.union([z.string(), z.boolean()])
|
|
50
|
-
.optional()
|
|
51
|
-
.meta({
|
|
52
|
-
alias: ["t"],
|
|
53
|
-
description: "Name of the script in package.json to test the StoryBook.",
|
|
54
|
-
}),
|
|
55
|
-
testCoverageDir: sharedSchemas.testCoverageDir,
|
|
56
|
-
testReportDir: sharedSchemas.testReportDir,
|
|
57
|
-
silent: z
|
|
58
|
-
.boolean()
|
|
59
|
-
.default(false)
|
|
60
|
-
.meta({
|
|
61
|
-
alias: ["s"],
|
|
62
|
-
description: "Silent the logs and only show final error/status.",
|
|
63
|
-
}),
|
|
64
|
-
authorName: z.string().optional().meta({
|
|
65
|
-
description: "Name of the author of the build.",
|
|
66
|
-
}),
|
|
67
|
-
authorEmail: z.email().optional().meta({
|
|
68
|
-
description: "Email of the author of the build.",
|
|
69
|
-
}),
|
|
70
|
-
ignoreError: z.boolean().default(false).meta({
|
|
71
|
-
hidden: true,
|
|
72
|
-
}),
|
|
73
|
-
authType: sharedSchemas.authType,
|
|
74
|
-
authValue: sharedSchemas.authValue,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export const createCommandModule: CommandModule = {
|
|
78
|
-
command: "create",
|
|
79
|
-
describe: "Create and upload StoryBook assets to the service.",
|
|
80
|
-
builder: zodSchemaToCommandBuilder(CreateSchema),
|
|
81
|
-
// oxlint-disable-next-line max-lines-per-function
|
|
82
|
-
handler: async (args): Promise<void> => {
|
|
83
|
-
const result = CreateSchema.safeParse(args);
|
|
84
|
-
if (!result.success) {
|
|
85
|
-
throw new Error(z.prettifyError(result.error));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const cwd =
|
|
89
|
-
result.data.cwd !== undefined && result.data.cwd !== ""
|
|
90
|
-
? path.resolve(result.data.cwd)
|
|
91
|
-
: process.cwd();
|
|
92
|
-
if (cwd && !fs.existsSync(cwd)) {
|
|
93
|
-
throw new Error(`Path provided to CWD does not exists: '${cwd}'`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const {
|
|
97
|
-
build,
|
|
98
|
-
silent,
|
|
99
|
-
url,
|
|
100
|
-
project,
|
|
101
|
-
sha,
|
|
102
|
-
ignoreError,
|
|
103
|
-
test,
|
|
104
|
-
testCoverageDir,
|
|
105
|
-
testReportDir,
|
|
106
|
-
authType,
|
|
107
|
-
authValue,
|
|
108
|
-
} = result.data;
|
|
109
|
-
|
|
110
|
-
const client = createClient<paths>({ baseUrl: url });
|
|
111
|
-
client.use(createAuthMiddleware({ authType, authValue }));
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
console.group(styleText("bold", "\nCreate Build Entry"));
|
|
115
|
-
await createSBRBuild(client, result.data, ignoreError);
|
|
116
|
-
console.groupEnd();
|
|
117
|
-
|
|
118
|
-
console.group(styleText("bold", "\nBuild StoryBook"));
|
|
119
|
-
const buildDirpath = buildStoryBook({ build, cwd, silent });
|
|
120
|
-
if (buildDirpath) {
|
|
121
|
-
await uploadSBRBuild(client, {
|
|
122
|
-
project,
|
|
123
|
-
sha,
|
|
124
|
-
dirpath: buildDirpath,
|
|
125
|
-
variant: "storybook",
|
|
126
|
-
cwd,
|
|
127
|
-
});
|
|
128
|
-
console.groupEnd();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
console.group(styleText("bold", "\nTest StoryBook"));
|
|
132
|
-
const { testCoverageDirpath, testReportDirpath } = testStoryBook({
|
|
133
|
-
cwd,
|
|
134
|
-
test,
|
|
135
|
-
silent,
|
|
136
|
-
testCoverageDir,
|
|
137
|
-
testReportDir,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
if (testReportDirpath) {
|
|
141
|
-
await uploadSBRBuild(client, {
|
|
142
|
-
project,
|
|
143
|
-
sha,
|
|
144
|
-
dirpath: testReportDirpath,
|
|
145
|
-
cwd,
|
|
146
|
-
variant: "testReport",
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (testCoverageDirpath) {
|
|
150
|
-
await uploadSBRBuild(client, {
|
|
151
|
-
project,
|
|
152
|
-
sha,
|
|
153
|
-
dirpath: testCoverageDirpath,
|
|
154
|
-
cwd,
|
|
155
|
-
variant: "coverage",
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
console.groupEnd();
|
|
159
|
-
|
|
160
|
-
console.log(styleText("green", "Created build successfully."));
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error(error);
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
async function createSBRBuild(
|
|
169
|
-
client: ServiceClient,
|
|
170
|
-
{ project, sha, message, labels }: z.infer<typeof CreateSchema>,
|
|
171
|
-
ignorePrevious?: boolean,
|
|
172
|
-
): Promise<void> {
|
|
173
|
-
const { error, response } = await client.POST(
|
|
174
|
-
"/projects/{projectId}/builds/create",
|
|
175
|
-
{
|
|
176
|
-
params: { path: { projectId: project } },
|
|
177
|
-
body: {
|
|
178
|
-
authorEmail: "Siddhant@asd.com",
|
|
179
|
-
authorName: "Siddhant",
|
|
180
|
-
labels,
|
|
181
|
-
sha,
|
|
182
|
-
message,
|
|
183
|
-
},
|
|
184
|
-
headers: {
|
|
185
|
-
Accept: "application/json",
|
|
186
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
if (error) {
|
|
192
|
-
if (ignorePrevious) {
|
|
193
|
-
console.warn(
|
|
194
|
-
styleText("yellow", "> StoryBooker Build entry already exits."),
|
|
195
|
-
);
|
|
196
|
-
} else {
|
|
197
|
-
throw new Error(
|
|
198
|
-
error.errorMessage ||
|
|
199
|
-
`Request to service failed with status: ${response.status}.`,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
console.log("New Build entry created '%s / %s'", project, sha);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async function uploadSBRBuild(
|
|
208
|
-
client: ServiceClient,
|
|
209
|
-
{
|
|
210
|
-
project,
|
|
211
|
-
sha,
|
|
212
|
-
dirpath,
|
|
213
|
-
variant,
|
|
214
|
-
cwd,
|
|
215
|
-
}: {
|
|
216
|
-
project: string;
|
|
217
|
-
sha: string;
|
|
218
|
-
dirpath: string;
|
|
219
|
-
variant: "storybook" | "testReport" | "coverage" | "screenshots";
|
|
220
|
-
cwd: string;
|
|
221
|
-
},
|
|
222
|
-
): Promise<void> {
|
|
223
|
-
const zipFilepath = path.join(cwd, `${variant}.zip`);
|
|
224
|
-
|
|
225
|
-
console.log(
|
|
226
|
-
`> Compressing directory '%s' to file '%s'...`,
|
|
227
|
-
path.relative(cwd, dirpath),
|
|
228
|
-
path.relative(cwd, zipFilepath),
|
|
229
|
-
);
|
|
230
|
-
zip(path.join(dirpath, "*"), zipFilepath);
|
|
231
|
-
|
|
232
|
-
const fileSize = fs.statSync(zipFilepath).size;
|
|
233
|
-
|
|
234
|
-
console.log(`> Uploading file '%s'...`, path.relative(cwd, zipFilepath));
|
|
235
|
-
const { error, response } = await client.POST(
|
|
236
|
-
"/projects/{projectId}/builds/{buildSHA}/upload",
|
|
237
|
-
{
|
|
238
|
-
params: {
|
|
239
|
-
path: { projectId: project, buildSHA: sha },
|
|
240
|
-
query: { variant },
|
|
241
|
-
},
|
|
242
|
-
// @ts-expect-error assign stream to object
|
|
243
|
-
body: toReadableStream(fs.createReadStream(zipFilepath), fileSize),
|
|
244
|
-
bodySerializer: (body) => body,
|
|
245
|
-
headers: {
|
|
246
|
-
Accept: "application/json",
|
|
247
|
-
"Content-Type": "application/zip",
|
|
248
|
-
"Content-Length": fileSize.toString(),
|
|
249
|
-
},
|
|
250
|
-
duplex: "half",
|
|
251
|
-
},
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
if (error) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
error.errorMessage ||
|
|
257
|
-
`Request to service failed with status: ${response.status}.`,
|
|
258
|
-
);
|
|
259
|
-
} else {
|
|
260
|
-
console.log("> Uploaded '%s / %s / %s'.", project, sha, variant);
|
|
261
|
-
fs.rmSync(zipFilepath);
|
|
262
|
-
}
|
|
263
|
-
}
|
package/src/commands/purge.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// oxlint-disable new-cap
|
|
2
|
-
|
|
3
|
-
import { styleText } from "node:util";
|
|
4
|
-
import createClient from "openapi-fetch";
|
|
5
|
-
import type { CommandModule } from "yargs";
|
|
6
|
-
import z from "zod";
|
|
7
|
-
import type { paths } from "../service-schema";
|
|
8
|
-
import { createAuthMiddleware } from "../utils/auth-utils";
|
|
9
|
-
import {
|
|
10
|
-
sharedSchemas,
|
|
11
|
-
zodSchemaToCommandBuilder,
|
|
12
|
-
} from "../utils/schema-utils";
|
|
13
|
-
|
|
14
|
-
const PurgeSchema = z.object({
|
|
15
|
-
project: sharedSchemas.project,
|
|
16
|
-
url: sharedSchemas.url,
|
|
17
|
-
label: z.string().meta({
|
|
18
|
-
alias: ["l"],
|
|
19
|
-
description: "The label slug to purge associated builds.",
|
|
20
|
-
}),
|
|
21
|
-
authType: sharedSchemas.authType,
|
|
22
|
-
authValue: sharedSchemas.authValue,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const purgeCommandModule: CommandModule = {
|
|
26
|
-
command: "purge",
|
|
27
|
-
describe: "Purge StoryBook assets from the service.",
|
|
28
|
-
builder: zodSchemaToCommandBuilder(PurgeSchema),
|
|
29
|
-
handler: async (args): Promise<void> => {
|
|
30
|
-
const result = PurgeSchema.safeParse(args);
|
|
31
|
-
if (!result.success) {
|
|
32
|
-
throw new Error(z.prettifyError(result.error));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { label, project, url, authType, authValue } = result.data;
|
|
36
|
-
const client = createClient<paths>({ baseUrl: url });
|
|
37
|
-
client.use(createAuthMiddleware({ authType, authValue }));
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
console.group(
|
|
41
|
-
styleText("bold", "\nPurge Label '%s' (project: %s)"),
|
|
42
|
-
label,
|
|
43
|
-
project,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
console.log(`> Deleting label '%s' and associated builds...`, label);
|
|
47
|
-
const { error, response } = await client.DELETE(
|
|
48
|
-
"/projects/{projectId}/labels/{labelSlug}",
|
|
49
|
-
{
|
|
50
|
-
params: { path: { labelSlug: label, projectId: project } },
|
|
51
|
-
headers: { Accept: "application/json" },
|
|
52
|
-
},
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
if (error) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
error.errorMessage ||
|
|
58
|
-
`Request to service failed with status: ${response.status}.`,
|
|
59
|
-
);
|
|
60
|
-
} else {
|
|
61
|
-
console.log("> Purged '%s / %s'.", project, label);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.groupEnd();
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error(error);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
};
|
package/src/commands/test.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { styleText } from "node:util";
|
|
4
|
-
import type { CommandModule } from "yargs";
|
|
5
|
-
import z from "zod";
|
|
6
|
-
import { testStoryBook } from "../utils/sb-test";
|
|
7
|
-
import {
|
|
8
|
-
sharedSchemas,
|
|
9
|
-
zodSchemaToCommandBuilder,
|
|
10
|
-
} from "../utils/schema-utils";
|
|
11
|
-
|
|
12
|
-
const schema = z.object({
|
|
13
|
-
cwd: sharedSchemas.cwd,
|
|
14
|
-
testCoverageDir: sharedSchemas.testCoverageDir,
|
|
15
|
-
testReportDir: sharedSchemas.testReportDir,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export const testCommandModule: CommandModule = {
|
|
19
|
-
command: "test",
|
|
20
|
-
describe: "Run test on StoryBook with Vitest",
|
|
21
|
-
builder: zodSchemaToCommandBuilder(schema),
|
|
22
|
-
handler(args) {
|
|
23
|
-
const result = schema.safeParse(args);
|
|
24
|
-
if (!result.success) {
|
|
25
|
-
throw new Error(z.prettifyError(result.error));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const cwd = result.data.cwd ? path.resolve(result.data.cwd) : process.cwd();
|
|
29
|
-
if (cwd && !fs.existsSync(cwd)) {
|
|
30
|
-
throw new Error(`Path provided to CWD does not exists: '${cwd}'`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
console.group(styleText("bold", "\nTest StoryBook"));
|
|
34
|
-
testStoryBook({
|
|
35
|
-
cwd,
|
|
36
|
-
test: true,
|
|
37
|
-
testCoverageDir: result.data.testCoverageDir,
|
|
38
|
-
testReportDir: result.data.testReportDir,
|
|
39
|
-
});
|
|
40
|
-
console.groupEnd();
|
|
41
|
-
},
|
|
42
|
-
};
|