@serwist/cli 9.5.7 → 9.5.9

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.
Files changed (59) hide show
  1. package/dist/bin.d.mts +10 -0
  2. package/dist/bin.d.mts.map +1 -0
  3. package/dist/bin.mjs +280 -0
  4. package/dist/bin.mjs.map +1 -0
  5. package/dist/chunks/constants-DptMolAX.js +67 -0
  6. package/dist/chunks/constants-DptMolAX.js.map +1 -0
  7. package/dist/chunks/errors-MXE2_2kj.js +139 -0
  8. package/dist/chunks/errors-MXE2_2kj.js.map +1 -0
  9. package/dist/chunks/schema-Bboy6FnP.js +29 -0
  10. package/dist/chunks/schema-Bboy6FnP.js.map +1 -0
  11. package/dist/chunks/types-Zr8JQZBi.d.ts +34 -0
  12. package/dist/chunks/types-Zr8JQZBi.d.ts.map +1 -0
  13. package/dist/chunks/validation-BIte-nSt.js +15 -0
  14. package/dist/chunks/validation-BIte-nSt.js.map +1 -0
  15. package/dist/index.d.mts +46 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.mjs +3 -0
  18. package/dist/index.schema.d.mts +87 -0
  19. package/dist/index.schema.d.mts.map +1 -0
  20. package/dist/index.schema.mjs +3 -0
  21. package/package.json +16 -17
  22. package/dist/app.d.ts +0 -4
  23. package/dist/app.d.ts.map +0 -1
  24. package/dist/bin.d.ts +0 -6
  25. package/dist/bin.d.ts.map +0 -1
  26. package/dist/bin.js +0 -339
  27. package/dist/chunks/constants.js +0 -84
  28. package/dist/chunks/errors.js +0 -153
  29. package/dist/chunks/schema.js +0 -13
  30. package/dist/index.d.ts +0 -5
  31. package/dist/index.d.ts.map +0 -1
  32. package/dist/index.js +0 -11
  33. package/dist/index.schema.d.ts +0 -3
  34. package/dist/index.schema.d.ts.map +0 -1
  35. package/dist/index.schema.js +0 -4
  36. package/dist/lib/ask-questions.d.ts +0 -9
  37. package/dist/lib/ask-questions.d.ts.map +0 -1
  38. package/dist/lib/build.d.ts +0 -18
  39. package/dist/lib/build.d.ts.map +0 -1
  40. package/dist/lib/cleanup-stack-trace.d.ts +0 -2
  41. package/dist/lib/cleanup-stack-trace.d.ts.map +0 -1
  42. package/dist/lib/constants.d.ts +0 -7
  43. package/dist/lib/constants.d.ts.map +0 -1
  44. package/dist/lib/errors.d.ts +0 -17
  45. package/dist/lib/errors.d.ts.map +0 -1
  46. package/dist/lib/help-text.d.ts +0 -2
  47. package/dist/lib/help-text.d.ts.map +0 -1
  48. package/dist/lib/logger.d.ts +0 -7
  49. package/dist/lib/logger.d.ts.map +0 -1
  50. package/dist/lib/read-config.d.ts +0 -3
  51. package/dist/lib/read-config.d.ts.map +0 -1
  52. package/dist/lib/run-wizard.d.ts +0 -2
  53. package/dist/lib/run-wizard.d.ts.map +0 -1
  54. package/dist/lib/schema.d.ts +0 -79
  55. package/dist/lib/schema.d.ts.map +0 -1
  56. package/dist/lib/validation.d.ts +0 -3
  57. package/dist/lib/validation.d.ts.map +0 -1
  58. package/dist/types.d.ts +0 -23
  59. package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,15 @@
1
+ import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
2
+ import z from "zod";
3
+ //#region src/lib/validation.ts
4
+ const validateBuildOptions = async (input) => {
5
+ const result = await (await import("./schema-Bboy6FnP.js").then((n) => n.r)).buildOptions.spa(input, { error: validationErrorMap });
6
+ if (!result.success) throw new SerwistConfigError({
7
+ moduleName: "@serwist/cli",
8
+ message: z.prettifyError(result.error)
9
+ });
10
+ return result.data;
11
+ };
12
+ //#endregion
13
+ export { validateBuildOptions as t };
14
+
15
+ //# sourceMappingURL=validation-BIte-nSt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-BIte-nSt.js","names":[],"sources":["../../src/lib/validation.ts"],"sourcesContent":["import { SerwistConfigError, validationErrorMap } from \"@serwist/build/schema\";\nimport z from \"zod\";\nimport type { BuildOptionsComplete } from \"../types.js\";\n\nexport const validateBuildOptions = async (input: unknown): Promise<BuildOptionsComplete> => {\n const result = await (await import(\"./schema.js\")).buildOptions.spa(input, { error: validationErrorMap });\n if (!result.success) {\n throw new SerwistConfigError({\n moduleName: \"@serwist/cli\",\n message: z.prettifyError(result.error),\n });\n }\n return result.data;\n};\n"],"mappings":";;;AAIA,MAAa,uBAAuB,OAAO,UAAkD;CAC3F,MAAM,SAAS,OAAO,MAAM,OAAO,wBAAA,MAAA,MAAA,EAAA,EAAA,EAAgB,aAAa,IAAI,OAAO,EAAE,OAAO,oBAAoB,CAAC;AACzG,KAAI,CAAC,OAAO,QACV,OAAM,IAAI,mBAAmB;EAC3B,YAAY;EACZ,SAAS,EAAE,cAAc,OAAO,MAAM;EACvC,CAAC;AAEJ,QAAO,OAAO"}
@@ -0,0 +1,46 @@
1
+ import { a as BuildOptionsComplete, c as EsbuildOptions, d as StringFlag, f as SUPPORTED_ESBUILD_OPTIONS, i as BuildOptions, l as EsbuildSupportedOptions, n as AnyFlags, o as BuildPartial, p as constants, r as BooleanFlag, s as BuildResolved, t as AnyFlag, u as NumberFlag } from "./chunks/types-Zr8JQZBi.js";
2
+ import { InjectManifestOptions } from "@serwist/build";
3
+
4
+ //#region src/lib/build.d.ts
5
+ interface InjectManifestCommand {
6
+ watch: boolean;
7
+ config: InjectManifestOptions;
8
+ }
9
+ /**
10
+ * Runs the specified build command with the provided configuration.
11
+ *
12
+ * @param options
13
+ */
14
+ declare const runInjectManifestCommand: ({
15
+ config,
16
+ watch
17
+ }: InjectManifestCommand) => Promise<void>;
18
+ interface BuildCommand {
19
+ config: BuildOptions;
20
+ watch: boolean;
21
+ }
22
+ declare const runBuildCommand: ({
23
+ config,
24
+ watch
25
+ }: BuildCommand) => Promise<void>;
26
+ //#endregion
27
+ //#region src/lib/errors.d.ts
28
+ declare const errors: {
29
+ "missing-input": string;
30
+ "missing-dest-dir-param": string;
31
+ "invalid-common-js-module": string;
32
+ "config-validation-failed": string;
33
+ "serwist-build-runtime-error": string;
34
+ "unknown-command": string;
35
+ "no-file-extensions-found": string;
36
+ "no-file-extensions-selected": string;
37
+ "invalid-sw-dest": string;
38
+ "glob-directory-invalid": string;
39
+ "invalid-config-location": string;
40
+ "sw-src-missing-injection-point": string;
41
+ "no-search-parameters-supplied": string;
42
+ "invalid-search-parameters-supplied": string;
43
+ };
44
+ //#endregion
45
+ export { AnyFlag, AnyFlags, BooleanFlag, type BuildCommand, BuildOptions, BuildOptionsComplete, BuildPartial, BuildResolved, EsbuildOptions, EsbuildSupportedOptions, type InjectManifestCommand, NumberFlag, SUPPORTED_ESBUILD_OPTIONS, StringFlag, constants, errors, runBuildCommand, runInjectManifestCommand };
46
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/build.ts","../src/lib/errors.ts"],"mappings":";;;;UAUiB,qBAAA;EACf,KAAA;EACA,MAAA,EAAQ,qBAAA;AAAA;;;;;;cAQG,wBAAA;EAAkC,MAAA;EAAA;AAAA,GAAmB,qBAAA,KAAqB,OAAA;AAAA,UA0BtE,YAAA;EACf,MAAA,EAAQ,YAAA;EACR,KAAA;AAAA;AAAA,cAGW,eAAA;EAAyB,MAAA;EAAA;AAAA,GAAmB,YAAA,KAAY,OAAA;;;cC1CxD,MAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { n as runBuildCommand, r as runInjectManifestCommand, t as errors } from "./chunks/errors-MXE2_2kj.js";
2
+ import { n as constants, t as SUPPORTED_ESBUILD_OPTIONS } from "./chunks/constants-DptMolAX.js";
3
+ export { SUPPORTED_ESBUILD_OPTIONS, constants, errors, runBuildCommand, runInjectManifestCommand };
@@ -0,0 +1,87 @@
1
+ import { a as BuildOptionsComplete } from "./chunks/types-Zr8JQZBi.js";
2
+ import z from "zod";
3
+
4
+ //#region src/lib/schema.d.ts
5
+ declare const buildPartial: z.ZodObject<{
6
+ esbuildOptions: z.ZodPrefault<z.ZodRecord<z.ZodLiteral<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw"> & z.z.core.$partial, z.ZodAny>>;
7
+ }, z.z.core.$strict>;
8
+ declare const buildOptions: z.ZodObject<{
9
+ esbuildOptions: z.ZodPrefault<z.ZodRecord<z.ZodLiteral<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw"> & z.z.core.$partial, z.ZodAny>>;
10
+ globDirectory: z.ZodString;
11
+ swDest: z.ZodString;
12
+ injectionPoint: z.ZodDefault<z.ZodString>;
13
+ swSrc: z.ZodString;
14
+ globFollow: z.ZodDefault<z.ZodBoolean>;
15
+ globIgnores: z.ZodDefault<z.ZodArray<z.ZodString>>;
16
+ globPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
17
+ globStrict: z.ZodDefault<z.ZodBoolean>;
18
+ templatedURLs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
19
+ additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
20
+ integrity: z.ZodOptional<z.ZodString>;
21
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ url: z.ZodString;
23
+ }, z.z.core.$strict>]>>>;
24
+ disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
25
+ dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
26
+ manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
27
+ size: z.ZodNumber;
28
+ integrity: z.ZodOptional<z.ZodString>;
29
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ url: z.ZodString;
31
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
32
+ manifest: z.ZodArray<z.ZodObject<{
33
+ size: z.ZodNumber;
34
+ integrity: z.ZodOptional<z.ZodString>;
35
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
+ url: z.ZodString;
37
+ }, z.z.core.$strip>>;
38
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
39
+ }, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
40
+ size: z.ZodNumber;
41
+ integrity: z.ZodOptional<z.ZodString>;
42
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
43
+ url: z.ZodString;
44
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
45
+ manifest: z.ZodArray<z.ZodObject<{
46
+ size: z.ZodNumber;
47
+ integrity: z.ZodOptional<z.ZodString>;
48
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
+ url: z.ZodString;
50
+ }, z.z.core.$strip>>;
51
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
52
+ }, z.z.core.$strict>>>, z.ZodTransform<z.z.core.$InferOuterFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
53
+ size: z.ZodNumber;
54
+ integrity: z.ZodOptional<z.ZodString>;
55
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ url: z.ZodString;
57
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
58
+ manifest: z.ZodArray<z.ZodObject<{
59
+ size: z.ZodNumber;
60
+ integrity: z.ZodOptional<z.ZodString>;
61
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
+ url: z.ZodString;
63
+ }, z.z.core.$strip>>;
64
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
65
+ }, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
66
+ size: z.ZodNumber;
67
+ integrity: z.ZodOptional<z.ZodString>;
68
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ url: z.ZodString;
70
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
71
+ manifest: z.ZodArray<z.ZodObject<{
72
+ size: z.ZodNumber;
73
+ integrity: z.ZodOptional<z.ZodString>;
74
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
75
+ url: z.ZodString;
76
+ }, z.z.core.$strip>>;
77
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
78
+ }, z.z.core.$strict>>>>>>;
79
+ maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
80
+ modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
81
+ }, z.z.core.$strict>;
82
+ //#endregion
83
+ //#region src/lib/validation.d.ts
84
+ declare const validateBuildOptions: (input: unknown) => Promise<BuildOptionsComplete>;
85
+ //#endregion
86
+ export { buildOptions, buildPartial, validateBuildOptions };
87
+ //# sourceMappingURL=index.schema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.schema.d.mts","names":[],"sources":["../src/lib/schema.ts","../src/lib/validation.ts"],"mappings":";;;;cAIa,YAAA,EAAY,CAAA,CAAA,SAAA;;;cAIZ,YAAA,EAAY,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCJZ,oBAAA,GAA8B,KAAA,cAAiB,OAAA,CAAQ,oBAAA"}
@@ -0,0 +1,3 @@
1
+ import { n as buildPartial, t as buildOptions } from "./chunks/schema-Bboy6FnP.js";
2
+ import { t as validateBuildOptions } from "./chunks/validation-BIte-nSt.js";
3
+ export { buildOptions, buildPartial, validateBuildOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/cli",
3
- "version": "9.5.7",
3
+ "version": "9.5.9",
4
4
  "type": "module",
5
5
  "description": "The command line interface of Serwist.",
6
6
  "files": [
@@ -27,23 +27,23 @@
27
27
  "repository": "https://github.com/serwist/serwist",
28
28
  "bugs": "https://github.com/serwist/serwist/issues",
29
29
  "homepage": "https://serwist.pages.dev",
30
- "main": "./dist/index.js",
31
- "types": "./dist/index.d.ts",
30
+ "main": "./dist/index.mjs",
31
+ "types": "./dist/index.d.mts",
32
32
  "typesVersions": {
33
33
  "*": {
34
34
  "schema": [
35
- "./dist/index.schema.d.ts"
35
+ "./dist/index.schema.d.mts"
36
36
  ]
37
37
  }
38
38
  },
39
39
  "exports": {
40
40
  ".": {
41
- "types": "./dist/index.d.ts",
42
- "default": "./dist/index.js"
41
+ "types": "./dist/index.d.mts",
42
+ "default": "./dist/index.mjs"
43
43
  },
44
44
  "./schema": {
45
- "types": "./dist/index.schema.d.ts",
46
- "default": "./dist/index.schema.js"
45
+ "types": "./dist/index.schema.d.mts",
46
+ "default": "./dist/index.schema.mjs"
47
47
  },
48
48
  "./package.json": "./package.json"
49
49
  },
@@ -51,7 +51,7 @@
51
51
  "serwist": "cli.js"
52
52
  },
53
53
  "dependencies": {
54
- "@inquirer/prompts": "8.3.0",
54
+ "@inquirer/prompts": "8.4.2",
55
55
  "chalk": "5.6.2",
56
56
  "chokidar": "5.0.0",
57
57
  "common-tags": "1.8.2",
@@ -61,18 +61,17 @@
61
61
  "stringify-object": "6.0.0",
62
62
  "update-notifier": "7.3.1",
63
63
  "zod": "4.3.6",
64
- "@serwist/build": "9.5.7",
65
- "@serwist/utils": "9.5.7"
64
+ "@serwist/build": "9.5.9",
65
+ "@serwist/utils": "9.5.9"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/common-tags": "1.8.4",
69
69
  "@types/inquirer": "9.0.9",
70
70
  "@types/stringify-object": "4.0.5",
71
71
  "@types/update-notifier": "6.0.8",
72
- "esbuild": "0.27.4",
73
- "rollup": "4.59.0",
74
- "typescript": "5.9.3",
75
- "@serwist/configs": "9.5.7"
72
+ "esbuild": "0.28.0",
73
+ "tsdown": "0.21.10",
74
+ "typescript": "6.0.3"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "esbuild": ">=0.25.0 <1.0.0"
@@ -83,8 +82,8 @@
83
82
  }
84
83
  },
85
84
  "scripts": {
86
- "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
87
- "dev": "rollup --config rollup.config.js --watch",
85
+ "build": "rimraf dist && NODE_ENV=production tsdown",
86
+ "dev": "tsdown --watch",
88
87
  "lint": "biome lint ./src",
89
88
  "typecheck": "tsc"
90
89
  }
package/dist/app.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { Result as MeowResult } from "meow";
2
- import type { SupportedFlags } from "./bin.js";
3
- export declare const app: (params: MeowResult<SupportedFlags>) => Promise<void>;
4
- //# sourceMappingURL=app.d.ts.map
package/dist/app.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAS/C,eAAO,MAAM,GAAG,GAAU,QAAQ,UAAU,CAAC,cAAc,CAAC,KAAG,OAAO,CAAC,IAAI,CAkH1E,CAAC"}
package/dist/bin.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { AnyFlags, BooleanFlag } from "./types.js";
2
- export interface SupportedFlags extends AnyFlags {
3
- debug: BooleanFlag;
4
- watch: BooleanFlag;
5
- }
6
- //# sourceMappingURL=bin.d.ts.map
package/dist/bin.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,WAAW,CAAC;CACpB"}
package/dist/bin.js DELETED
@@ -1,339 +0,0 @@
1
- import meow from 'meow';
2
- import updateNotifier from 'update-notifier';
3
- import assert from 'node:assert';
4
- import path from 'node:path';
5
- import { pathToFileURL } from 'node:url';
6
- import chokidar from 'chokidar';
7
- import { glob } from 'glob';
8
- import { e as errors, l as logger, a as runInjectManifestCommand, r as runBuildCommand } from './chunks/errors.js';
9
- import { c as constants } from './chunks/constants.js';
10
- import { statSync, writeFileSync } from 'node:fs';
11
- import stringifyObject from 'stringify-object';
12
- import { input, checkbox, select, Separator } from '@inquirer/prompts';
13
- import { toUnix } from '@serwist/utils';
14
- import '@serwist/build';
15
- import 'pretty-bytes';
16
- import 'chalk';
17
- import 'common-tags';
18
- import '@serwist/build/schema';
19
- import 'zod';
20
-
21
- const readConfig = async (configFile)=>{
22
- return (await import(configFile)).default;
23
- };
24
-
25
- const getSubdirectories = async ()=>{
26
- return await glob("*/", {
27
- ignore: constants.ignoredDirectories.map((directory)=>`${directory}/`)
28
- });
29
- };
30
- const askRootOfWebApp = async ()=>{
31
- const subdirectories = await getSubdirectories();
32
- const { globDirectory, manualDirectoryInput } = await (async ()=>{
33
- if (subdirectories.length > 0) {
34
- const manualEntryChoice = "Manually enter path";
35
- const globDirectory = await select({
36
- message: "What is the root of your web app (i.e. which directory do you deploy)?",
37
- choices: [
38
- ...subdirectories.map((dir)=>({
39
- value: dir
40
- })),
41
- new Separator(),
42
- {
43
- value: manualEntryChoice
44
- }
45
- ]
46
- });
47
- let manualDirectoryInput;
48
- if (globDirectory === manualEntryChoice) {
49
- manualDirectoryInput = await input({
50
- message: "Please enter the path to the root of your web app:"
51
- });
52
- }
53
- return {
54
- globDirectory,
55
- manualDirectoryInput
56
- };
57
- }
58
- const globDirectory = await input({
59
- message: "Please enter the path to the root of your web app:",
60
- default: "."
61
- });
62
- return {
63
- globDirectory,
64
- manualDirectoryInput: undefined
65
- };
66
- })();
67
- const stat = statSync(manualDirectoryInput || globDirectory);
68
- assert(stat.isDirectory(), errors["glob-directory-invalid"]);
69
- return manualDirectoryInput || globDirectory;
70
- };
71
- const getAllFileExtensions = async (globDirectory)=>{
72
- const files = await glob("**/*.*", {
73
- cwd: globDirectory,
74
- nodir: true,
75
- ignore: [
76
- ...constants.ignoredDirectories.map((directory)=>`**/${directory}/**`),
77
- ...constants.ignoredFileExtensions.map((extension)=>`**/*.${extension}`)
78
- ]
79
- });
80
- const extensions = new Set();
81
- for (const file of files){
82
- const extension = path.extname(file);
83
- if (extension) {
84
- extensions.add(extension.replace(/^\./, ""));
85
- }
86
- }
87
- return [
88
- ...extensions
89
- ];
90
- };
91
- const askQuestions = async ()=>{
92
- const globDirectory = await askRootOfWebApp();
93
- const fileExtensions = await getAllFileExtensions(globDirectory);
94
- assert(fileExtensions.length > 0, errors["no-file-extensions-found"]);
95
- const swSrc = await input({
96
- message: "Where's your existing service worker file? To be used with 'injectManifest', it should include a call to 'self.__SW_MANIFEST'",
97
- validate (input) {
98
- if (typeof input !== "string") {
99
- return "You must provide a valid 'swSrc'!";
100
- }
101
- if (!statSync(input, {
102
- throwIfNoEntry: false
103
- })?.isFile()) {
104
- return "'swSrc' must point to a valid file!";
105
- }
106
- return true;
107
- }
108
- });
109
- const swDest = await input({
110
- message: "Where would you like your service worker file to be saved?",
111
- default: toUnix(path.join(globDirectory, "sw.js")),
112
- validate (input) {
113
- if (typeof input !== "string") {
114
- return "You must provide a valid 'swDest'!";
115
- }
116
- return true;
117
- }
118
- });
119
- const selectedExtensions = await checkbox({
120
- message: "Which file types would you like to precache?",
121
- choices: fileExtensions.map((ext)=>({
122
- value: ext,
123
- checked: true
124
- })),
125
- validate (input) {
126
- if (!Array.isArray(input)) {
127
- return "'selectedExtensions' is not an array. This is most likely a bug.";
128
- }
129
- if (input.length === 0) {
130
- return errors["no-file-extensions-selected"];
131
- }
132
- return true;
133
- }
134
- });
135
- const configLocation = await input({
136
- message: "Where would you like to save these configuration options?",
137
- default: constants.defaultConfigFile,
138
- validate (input) {
139
- if (typeof input !== "string") {
140
- return "You must provide a valid location!";
141
- }
142
- return true;
143
- }
144
- });
145
- const globPatterns = [
146
- `**/*.${selectedExtensions.length === 1 ? selectedExtensions[0] : `{${selectedExtensions.join(",")}}`}`
147
- ];
148
- const config = {
149
- globDirectory,
150
- globPatterns,
151
- swSrc,
152
- swDest
153
- };
154
- return {
155
- config,
156
- configLocation
157
- };
158
- };
159
-
160
- async function runWizard() {
161
- const { configLocation, config } = await askQuestions();
162
- const contents = `/** @type {import("@serwist/build").InjectManifestOptions} */\nexport default ${stringifyObject(config)};`;
163
- writeFileSync(configLocation, contents);
164
- logger.log(`To build your service worker, run
165
-
166
- serwist inject-manifest ${configLocation}
167
-
168
- as part of a build process.`);
169
- logger.log(`You can further customize your service worker by making changes to ${configLocation}. See https://serwist.pages.dev/docs/build/configuring for details.`);
170
- }
171
-
172
- const app = async (params)=>{
173
- assert(params && Array.isArray(params.input), errors["missing-input"]);
174
- const [command = "help", option] = params.input;
175
- process.env.SERWIST_ENV = params.flags.watch ? "watch" : "build";
176
- if (!process.env.NODE_ENV) {
177
- process.env.NODE_ENV = params.flags.watch ? "development" : "production";
178
- }
179
- switch(command){
180
- case "wizard":
181
- {
182
- await runWizard();
183
- break;
184
- }
185
- case "build":
186
- {
187
- const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);
188
- const configUrl = pathToFileURL(configPath).href;
189
- let config;
190
- try {
191
- config = await readConfig(configUrl);
192
- } catch (error) {
193
- config = null;
194
- if (error instanceof Error) {
195
- logger.error(errors["invalid-common-js-module"]);
196
- throw error;
197
- }
198
- }
199
- if (config === null) {
200
- throw logger.error(errors["invalid-config-location"]);
201
- }
202
- logger.log(`Using configuration from ${configPath}.`);
203
- await runBuildCommand({
204
- config,
205
- watch: !!params.flags.watch
206
- });
207
- break;
208
- }
209
- case "inject-manifest":
210
- {
211
- const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);
212
- const configUrl = pathToFileURL(configPath).href;
213
- let config;
214
- try {
215
- config = await readConfig(configUrl);
216
- } catch (error) {
217
- config = null;
218
- if (error instanceof Error) {
219
- logger.error(errors["invalid-common-js-module"]);
220
- throw error;
221
- }
222
- }
223
- if (config === null) {
224
- throw logger.error(errors["invalid-config-location"]);
225
- }
226
- logger.log(`Using configuration from ${configPath}.`);
227
- if (params.flags.watch) {
228
- if (config.globPatterns) {
229
- chokidar.watch(await glob(config.globPatterns, {
230
- cwd: config.globDirectory,
231
- follow: config.globFollow,
232
- ignore: config.globIgnores
233
- }), {
234
- ignoreInitial: true,
235
- cwd: config.globDirectory
236
- }).on("all", async ()=>{
237
- if (config === null) return;
238
- await runInjectManifestCommand({
239
- config,
240
- watch: true
241
- });
242
- }).on("ready", async ()=>{
243
- if (config === null) return;
244
- await runInjectManifestCommand({
245
- config,
246
- watch: true
247
- });
248
- }).on("error", (err)=>{
249
- logger.error(err instanceof Error ? err.toString() : "Unknown error");
250
- });
251
- }
252
- } else {
253
- await runInjectManifestCommand({
254
- config,
255
- watch: false
256
- });
257
- }
258
- break;
259
- }
260
- case "help":
261
- {
262
- params.showHelp();
263
- }
264
- default:
265
- {
266
- throw new Error(`${errors["unknown-command"]} ${command}`);
267
- }
268
- }
269
- };
270
-
271
- const cleanupStackTrace = (error, moduleName)=>{
272
- if (!error.stack) {
273
- return "";
274
- }
275
- const frames = error.stack.split("\n");
276
- let startFrame;
277
- let lastFrame = 0;
278
- frames.forEach((frame, index)=>{
279
- if (startFrame === undefined && frame.includes(" at ")) {
280
- startFrame = index;
281
- }
282
- if (frame.includes(`${moduleName}:`)) {
283
- lastFrame = index;
284
- }
285
- });
286
- return frames.slice(startFrame, lastFrame + 1).join("\n");
287
- };
288
-
289
- const helpText = `Usage:
290
- $ serwist <command> [options]
291
-
292
- Commands:
293
- wizard
294
- Runs the configuration wizard, which will generate a
295
- config file based on answers to questions.
296
-
297
- inject-manifest [<path/to/config.js>] [--watch]
298
- Takes an existing service worker file and creates a
299
- copy of it with a precache manifest injected. The precache
300
- manifest is generated based on the options in the config file
301
- (defaults to 'serwist.config.js'). If '--watch' is provided, the
302
- CLI will stay running and rebuild the service worker each
303
- time a file in the precache manifest changes. See
304
- https://serwist.pages.dev/docs/cli for more information.
305
-
306
- Configuration file:
307
- The 'inject-manifest' command expects the configuration
308
- file to be a JavaScript file. By default, it is assumed
309
- to be named 'serwist.config.js' and located in the current
310
- directory, but this can be overridden.
311
-
312
- Examples:
313
- $ serwist wizard
314
- $ serwist inject-manifest configs/serwist-config.js
315
- `;
316
-
317
- void (async ()=>{
318
- const params = meow(helpText, {
319
- importMeta: import.meta
320
- });
321
- updateNotifier({
322
- pkg: params.pkg
323
- }).notify();
324
- try {
325
- await app(params);
326
- } catch (error) {
327
- if (error instanceof Error) {
328
- if (params.flags.debug) {
329
- if (error.stack) {
330
- logger.error(`\n${error.stack}`);
331
- }
332
- } else {
333
- logger.error(`\n${error.message}`);
334
- logger.debug(`${cleanupStackTrace(error, "app.js")}\n`);
335
- }
336
- }
337
- process.exit(1);
338
- }
339
- })();