@serwist/cli 9.0.3 → 9.0.5

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/dist/bin.js CHANGED
@@ -11,7 +11,7 @@ import chalk from 'chalk';
11
11
  import { statSync, writeFileSync } from 'node:fs';
12
12
  import stringifyObject from 'stringify-object';
13
13
  import { glob } from 'glob';
14
- import inquirer from 'inquirer';
14
+ import { input, checkbox, select, Separator } from '@inquirer/prompts';
15
15
 
16
16
  const constants = {
17
17
  defaultConfigFile: "serwist.config.js",
@@ -67,35 +67,40 @@ const getSubdirectories = async ()=>{
67
67
  };
68
68
  const askRootOfWebApp = async ()=>{
69
69
  const subdirectories = await getSubdirectories();
70
- const { manualDirectoryInput, globDirectory } = await (()=>{
70
+ const { globDirectory, manualDirectoryInput } = await (async ()=>{
71
71
  if (subdirectories.length > 0) {
72
72
  const manualEntryChoice = "Manually enter path";
73
- return inquirer.prompt([
74
- {
75
- name: "globDirectory",
76
- type: "list",
77
- message: oneLine`What is the root of your web app (i.e. which directory do
78
- you deploy)?`,
79
- choices: [
80
- ...subdirectories,
81
- new inquirer.Separator(),
82
- manualEntryChoice
83
- ]
84
- },
85
- {
86
- name: "manualDirectoryInput",
87
- when: (answers)=>answers.globDirectory === manualEntryChoice,
73
+ const globDirectory = await select({
74
+ message: "What is the root of your web app (i.e. which directory do you deploy)?",
75
+ choices: [
76
+ ...subdirectories.map((dir)=>({
77
+ value: dir
78
+ })),
79
+ new Separator(),
80
+ {
81
+ value: manualEntryChoice
82
+ }
83
+ ]
84
+ });
85
+ let manualDirectoryInput = undefined;
86
+ if (globDirectory === manualEntryChoice) {
87
+ manualDirectoryInput = await input({
88
88
  message: "Please enter the path to the root of your web app:"
89
- }
90
- ]);
91
- }
92
- return inquirer.prompt([
93
- {
94
- name: "globDirectory",
95
- message: "Please enter the path to the root of your web app:",
96
- default: "."
89
+ });
97
90
  }
98
- ]);
91
+ return {
92
+ globDirectory,
93
+ manualDirectoryInput
94
+ };
95
+ }
96
+ const globDirectory = await input({
97
+ message: "Please enter the path to the root of your web app:",
98
+ default: "."
99
+ });
100
+ return {
101
+ globDirectory,
102
+ manualDirectoryInput: undefined
103
+ };
99
104
  })();
100
105
  const stat = statSync(manualDirectoryInput || globDirectory);
101
106
  assert(stat.isDirectory(), errors["glob-directory-invalid"]);
@@ -125,66 +130,56 @@ const askQuestions = async ()=>{
125
130
  const globDirectory = await askRootOfWebApp();
126
131
  const fileExtensions = await getAllFileExtensions(globDirectory);
127
132
  assert(fileExtensions.length > 0, errors["no-file-extensions-found"]);
128
- const { swSrc, swDest, selectedExtensions, configLocation } = await inquirer.prompt([
129
- {
130
- name: "swSrc",
131
- message: oneLine`Where's your existing service worker file? To be used with
132
- injectManifest, it should include a call to
133
- 'self.__SW_MANIFEST'`,
134
- type: "input",
135
- validate (input) {
136
- if (typeof input !== "string") {
137
- return "You must provide a valid 'swSrc'!";
138
- }
139
- if (!statSync(input, {
140
- throwIfNoEntry: false
141
- })?.isFile()) {
142
- return "'swSrc' must point to a valid file!";
143
- }
144
- return true;
133
+ const swSrc = await input({
134
+ message: "Where's your existing service worker file? To be used with 'injectManifest', it should include a call to 'self.__SW_MANIFEST'",
135
+ validate (input) {
136
+ if (typeof input !== "string") {
137
+ return "You must provide a valid 'swSrc'!";
145
138
  }
146
- },
147
- {
148
- name: "swDest",
149
- message: "Where would you like your service worker file to be saved?",
150
- type: "input",
151
- default: upath.join(globDirectory, "sw.js"),
152
- validate (input) {
153
- if (typeof input !== "string") {
154
- return "You must provide a valid 'swDest'!";
155
- }
156
- return true;
139
+ if (!statSync(input, {
140
+ throwIfNoEntry: false
141
+ })?.isFile()) {
142
+ return "'swSrc' must point to a valid file!";
157
143
  }
158
- },
159
- {
160
- name: "selectedExtensions",
161
- message: "Which file types would you like to precache?",
162
- type: "checkbox",
163
- choices: fileExtensions,
164
- default: fileExtensions,
165
- validate (input) {
166
- if (!Array.isArray(input)) {
167
- return "'selectedExtensions' is not an array. This is most likely a bug.";
168
- }
169
- if (input.length === 0) {
170
- return errors["no-file-extensions-selected"];
171
- }
172
- return true;
144
+ return true;
145
+ }
146
+ });
147
+ const swDest = await input({
148
+ message: "Where would you like your service worker file to be saved?",
149
+ default: upath.join(globDirectory, "sw.js"),
150
+ validate (input) {
151
+ if (typeof input !== "string") {
152
+ return "You must provide a valid 'swDest'!";
173
153
  }
174
- },
175
- {
176
- name: "configLocation",
177
- message: "Where would you like to save these configuration options?",
178
- type: "input",
179
- default: constants.defaultConfigFile,
180
- validate (input) {
181
- if (typeof input !== "string") {
182
- return "You must provide a valid location!";
183
- }
184
- return true;
154
+ return true;
155
+ }
156
+ });
157
+ const selectedExtensions = await checkbox({
158
+ message: "Which file types would you like to precache?",
159
+ choices: fileExtensions.map((ext)=>({
160
+ value: ext,
161
+ checked: true
162
+ })),
163
+ validate (input) {
164
+ if (!Array.isArray(input)) {
165
+ return "'selectedExtensions' is not an array. This is most likely a bug.";
185
166
  }
167
+ if (input.length === 0) {
168
+ return errors["no-file-extensions-selected"];
169
+ }
170
+ return true;
186
171
  }
187
- ]);
172
+ });
173
+ const configLocation = await input({
174
+ message: "Where would you like to save these configuration options?",
175
+ default: constants.defaultConfigFile,
176
+ validate (input) {
177
+ if (typeof input !== "string") {
178
+ return "You must provide a valid location!";
179
+ }
180
+ return true;
181
+ }
182
+ });
188
183
  const globPatterns = [
189
184
  `**/*.${selectedExtensions.length === 1 ? selectedExtensions[0] : `{${selectedExtensions.join(",")}}`}`
190
185
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"ask-questions.d.ts","sourceRoot":"","sources":["../../src/lib/ask-questions.ts"],"names":[],"mappings":"AAuFA,UAAU,wBAAwB;IAChC,MAAM,EAAE;QACN,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,YAAY,QAAa,OAAO,CAAC,wBAAwB,CAsFrE,CAAC"}
1
+ {"version":3,"file":"ask-questions.d.ts","sourceRoot":"","sources":["../../src/lib/ask-questions.ts"],"names":[],"mappings":"AAmFA,UAAU,wBAAwB;IAChC,MAAM,EAAE;QACN,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,YAAY,QAAa,OAAO,CAAC,wBAAwB,CAuErE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/cli",
3
- "version": "9.0.3",
3
+ "version": "9.0.5",
4
4
  "type": "module",
5
5
  "description": "The command line interface of Serwist.",
6
6
  "files": [
@@ -28,18 +28,18 @@
28
28
  "serwist": "cli.js"
29
29
  },
30
30
  "dependencies": {
31
+ "@inquirer/prompts": "5.1.2",
31
32
  "chalk": "5.3.0",
32
33
  "chokidar": "3.6.0",
33
34
  "common-tags": "1.8.2",
34
35
  "fs-extra": "11.2.0",
35
- "glob": "10.4.1",
36
- "inquirer": "9.2.23",
36
+ "glob": "10.4.5",
37
37
  "meow": "13.2.0",
38
38
  "pretty-bytes": "6.1.1",
39
39
  "stringify-object": "5.0.0",
40
40
  "upath": "2.0.1",
41
- "update-notifier": "7.0.0",
42
- "@serwist/build": "9.0.3"
41
+ "update-notifier": "7.1.0",
42
+ "@serwist/build": "9.0.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/common-tags": "1.8.4",
@@ -47,9 +47,9 @@
47
47
  "@types/inquirer": "9.0.7",
48
48
  "@types/stringify-object": "4.0.5",
49
49
  "@types/update-notifier": "6.0.8",
50
- "rollup": "4.18.0",
51
- "typescript": "5.4.5",
52
- "@serwist/configs": "9.0.3"
50
+ "rollup": "4.18.1",
51
+ "typescript": "5.5.3",
52
+ "@serwist/configs": "9.0.5"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",