@michijs/dev-server 0.4.2 → 0.5.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.
Files changed (40) hide show
  1. package/LICENSE.md +8 -8
  2. package/README.md +229 -208
  3. package/bin/actions/build.js +2 -2
  4. package/bin/actions/dist.js +5 -5
  5. package/bin/actions/generateAssets.d.ts +4 -0
  6. package/bin/actions/generateAssets.js +125 -0
  7. package/bin/actions/start.d.ts +1 -1
  8. package/bin/actions/start.js +46 -30
  9. package/bin/cli.js +33 -33
  10. package/bin/config/config.d.ts +111 -6
  11. package/bin/config/config.js +40 -31
  12. package/bin/config/getIPAddress.js +5 -3
  13. package/bin/config/michi.config.cjs +159 -0
  14. package/bin/config/public/client.js +1 -1
  15. package/bin/config/tsconfig.d.ts +1 -1
  16. package/bin/config/tsconfig.js +3 -3
  17. package/bin/config/userConfig.d.ts +1 -1
  18. package/bin/config/userConfig.js +18 -14
  19. package/bin/constants.d.ts +8 -0
  20. package/bin/constants.js +12 -0
  21. package/bin/index.d.ts +1 -1
  22. package/bin/index.js +1 -1
  23. package/bin/tsconfig.tsbuildinfo +1 -1
  24. package/bin/types.d.ts +71 -7
  25. package/bin/utils/copy.js +4 -4
  26. package/bin/utils/feature-image-template.svg +62 -0
  27. package/bin/utils/getAllFiles.js +2 -2
  28. package/bin/utils/getHostURL.d.ts +1 -0
  29. package/bin/utils/getHostURL.js +4 -0
  30. package/bin/utils/getLocalURL.d.ts +1 -0
  31. package/bin/utils/getLocalURL.js +3 -0
  32. package/bin/utils/getPath.js +1 -1
  33. package/bin/utils/minify.js +3 -3
  34. package/bin/utils/serviceWorkerTransformer.d.ts +1 -1
  35. package/bin/utils/serviceWorkerTransformer.js +8 -8
  36. package/bin/utils/transformers.d.ts +1 -1
  37. package/bin/utils/transformers.js +4 -4
  38. package/package.json +63 -74
  39. package/bin/actions/generateIcons.d.ts +0 -1
  40. package/bin/actions/generateIcons.js +0 -31
package/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2021-present, michijs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-present, michijs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
9
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,208 +1,229 @@
1
- # Michijs Dev Server
2
- Development server built on top of esbuild.
3
-
4
- ![npm][version] [![license][github-license]][github-license-url] ![npm][npm-downloads] ![npm][repo-size]
5
- [![CodeQL](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml)
6
- [![Tests](https://github.com/michijs/dev-server/actions/workflows/tests.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/tests.yml)
7
-
8
- ## Main features
9
- - Configure esbuild options with Typescript
10
- - First-class PWA support
11
- - Custom environments
12
- - Packages distribution
13
-
14
- ## Getting started
15
-
16
- You can use the following [test project](https://github.com/michijs/michijs-template) or setup a project from scratch:
17
-
18
- npm install -D @michijs/dev-server
19
-
20
- ## CLI commands
21
- You have the following CLI commands:
22
- <table>
23
- <thead>
24
- <tr>
25
- <th>CLI command</th>
26
- <th>Default environment</th>
27
- <th>Description</th>
28
- </tr>
29
- </thead>
30
- <tbody>
31
- <tr>
32
- <td>start</td>
33
- <td>DEVELOPMENT</td>
34
- <td>Allows to start a dev server as a webpage.</td>
35
- </tr>
36
- <tr>
37
- <td>build</td>
38
- <td>PRODUCTION</td>
39
- <td>Allows to build the src code as a webpage.</td>
40
- </tr>
41
- <tr>
42
- <td>dist</td>
43
- <td>DISTRIBUTION</td>
44
- <td>Allows to distribute the src code as a package. At the moment ESBuild does not support .d.ts files so we still use the Typescript compiler with the tsconfig provided by esbuildOptions field.</td>
45
- </tr>
46
- <tr>
47
- <td>generate-icons</td>
48
- <td>-</td>
49
- <td>Allows to generate a full set of icons from a src icon.</td>
50
- </tr>
51
- </tbody>
52
- </table>
53
-
54
-
55
- ## Configure the server
56
- To configure the server you just need to create an optional file called michi.config.ts at the root of your project. This file would look like this:
57
-
58
- ```ts
59
- import { ServerConfig, ServerConfigFactory, DefaultEnvironment } from '@michijs/server';
60
-
61
- export const config: ServerConfigFactory = (environment) => {
62
- const defaultConfig: ServerConfig = {
63
- // Your custom configuration
64
- }
65
- return defaultConfig;
66
- };
67
-
68
- export default config;
69
- ```
70
-
71
- <table>
72
- <thead>
73
- <tr>
74
- <th colspan="4">ServerConfig</th>
75
- <th>Default value</th>
76
- </tr>
77
- </thead>
78
- <tbody>
79
- <tr>
80
- <td>env</td>
81
- <td colspan="3">Allows to add environment variables</td>
82
- <td></td>
83
- </tr>
84
- <tr>
85
- <td>esbuildOptions</td>
86
- <td colspan="3">All the options available at <a href="https://esbuild.github.io/plugins/#build-options">esbuild documentation</a></td>
87
- <td>Can be chequed <a href="#esbuild-default-options">here</a></td>
88
- </tr>
89
- <tr>
90
- <td>openBrowser</td>
91
- <td colspan="3">If the browser should open at localhost url when server starts</td>
92
- <td>"true"</td>
93
- </tr>
94
- <tr>
95
- <td>port</td>
96
- <td colspan="3">Port to run dev server on</td>
97
- <td>"3000"</td>
98
- </tr>
99
- <tr>
100
- <td rowspan="10">public</td>
101
- <td rowspan="10">Public folder - will be copied at server start</td>
102
- <tr>
103
- <td colspan="2">indexName</td>
104
- <td>"index.html"</td>
105
- </tr>
106
- <tr>
107
- <td colspan="2">minify</td>
108
- <td>"true" if environment is PRODUCTION</td>
109
- </tr>
110
- <tr>
111
- <td colspan="2">path</td>
112
- <td>"public"</td>
113
- </tr>
114
- <tr>
115
- <td rowspan="3">manifest <br/><small>(A JSON document that contains startup parameters and application defaults for when a web application is launched.)</small></td>
116
- <tr>
117
- <td>name</td>
118
- <td>"manifest.json"</td>
119
- </tr>
120
- <tr>
121
- <td>options</td>
122
- <td></td>
123
- </tr>
124
- </tr>
125
- <tr>
126
- <td rowspan="3">wellKnown <br/><small>(A URI with the path component /.well-known/assetlinks.json is used by the AssetLinks protocol to identify one or more digital assets (such as web sites or mobile apps) that are related to the hosting web site in some fashion.)</small></td>
127
- <tr>
128
- <td>relation</td>
129
- <td></td>
130
- </tr>
131
- <tr>
132
- <td>target</td>
133
- <td></td>
134
- </tr>
135
- </tr>
136
- </tr>
137
- </tbody>
138
- </table>
139
-
140
- ## Esbuild default options
141
-
142
- <table>
143
- <thead>
144
- <tr>
145
- <th>Field</th>
146
- <th>Default value</th>
147
- </tr>
148
- </thead>
149
- <tbody>
150
- <tr>
151
- <td>bundle</td>
152
- <td>"true"</td>
153
- </tr>
154
- <tr>
155
- <td>entryPoints</td>
156
- <td>['src/index.ts']</td>
157
- </tr>
158
- <tr>
159
- <td>format</td>
160
- <td>"esm"</td>
161
- </tr>
162
- <tr>
163
- <td>keepNames</td>
164
- <td>"true" if environment is PRODUCTION</td>
165
- </tr>
166
- <tr>
167
- <td>logLevel</td>
168
- <td>"error"</td>
169
- </tr>
170
- <tr>
171
- <td>minifySyntax</td>
172
- <td>"true" if environment is PRODUCTION</td>
173
- </tr>
174
- <tr>
175
- <td>minifyWhitespace</td>
176
- <td>"true" if environment is PRODUCTION</td>
177
- </tr>
178
- <tr>
179
- <td>outdir</td>
180
- <td>"build"</td>
181
- </tr>
182
- <tr>
183
- <td>sourcemap</td>
184
- <td>"true" if environment is <b>NOT</b> PRODUCTION</td>
185
- </tr>
186
- <tr>
187
- <td>splitting</td>
188
- <td>"true"</td>
189
- </tr>
190
- <tr>
191
- <td>target</td>
192
- <td>"esnext"</td>
193
- </tr>
194
- <tr>
195
- <td>tsconfig</td>
196
- <td>"tsconfig.json"</td>
197
- </tr>
198
- </tbody>
199
- </table>
200
-
201
- ## License
202
- - [MIT](https://github.com/michijs/dev-server/blob/master/LICENSE.md)
203
-
204
- [repo-size]: https://img.shields.io/github/repo-size/michijs/dev-server
205
- [npm-downloads]: https://img.shields.io/npm/dt/@michijs/dev-server
206
- [version]: https://img.shields.io/npm/v/@michijs/dev-server
207
- [github-license]: https://img.shields.io/github/license/michijs/dev-server
208
- [github-license-url]: https://github.com/michijs/dev-server/blob/master/LICENSE.md
1
+ # Michijs Dev Server
2
+ Development server built on top of esbuild.
3
+ <!-- TODO: To generate feature-image require to install roboto -->
4
+
5
+ ![npm][version] [![license][github-license]][github-license-url] ![npm][npm-downloads] ![npm][repo-size]
6
+ [![CodeQL](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml)
7
+ [![Tests](https://github.com/michijs/dev-server/actions/workflows/tests.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/tests.yml)
8
+
9
+ ## Main features
10
+ - Configure esbuild options with Typescript
11
+ - First-class PWA support
12
+ - Custom environments
13
+ - Packages distribution
14
+
15
+ ## Getting started
16
+
17
+ You can use the following [test project](https://github.com/michijs/michijs-template) or setup a project from scratch:
18
+
19
+ npm install -D @michijs/dev-server
20
+
21
+ ## CLI commands
22
+ You have the following CLI commands:
23
+ <table>
24
+ <thead>
25
+ <tr>
26
+ <th>CLI command</th>
27
+ <th>Default environment</th>
28
+ <th>Description</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <tr>
33
+ <td>start</td>
34
+ <td>DEVELOPMENT</td>
35
+ <td>Allows to start a dev server as a webpage.</td>
36
+ </tr>
37
+ <tr>
38
+ <td>build</td>
39
+ <td>PRODUCTION</td>
40
+ <td>Allows to build the src code as a webpage.</td>
41
+ </tr>
42
+ <tr>
43
+ <td>dist</td>
44
+ <td>DISTRIBUTION</td>
45
+ <td>Allows to distribute the src code as a package. At the moment ESBuild does not support .d.ts files so we still use the Typescript compiler with the tsconfig provided by esbuildOptions field.</td>
46
+ </tr>
47
+ <tr>
48
+ <td>generate-icons</td>
49
+ <td>-</td>
50
+ <td>Allows to generate a full set of icons from a src icon.</td>
51
+ </tr>
52
+ </tbody>
53
+ </table>
54
+
55
+
56
+ ## Configure the server
57
+ To configure the server you just need to create an optional file called michi.config.ts at the root of your project. This file would look like this:
58
+
59
+ ```ts
60
+ import { ServerConfig, ServerConfigFactory, DefaultEnvironment } from '@michijs/server';
61
+
62
+ export const config: ServerConfigFactory = (environment) => {
63
+ const defaultConfig: ServerConfig = {
64
+ // Your custom configuration
65
+ }
66
+ return defaultConfig;
67
+ };
68
+
69
+ export default config;
70
+ ```
71
+
72
+ <table>
73
+ <thead>
74
+ <tr>
75
+ <th colspan="4">ServerConfig</th>
76
+ <th>Default value</th>
77
+ </tr>
78
+ </thead>
79
+ <tbody>
80
+ <tr>
81
+ <td>env</td>
82
+ <td colspan="3">Allows to add environment variables</td>
83
+ <td></td>
84
+ </tr>
85
+ <tr>
86
+ <td>esbuildOptions</td>
87
+ <td colspan="3">All the options available at <a href="https://esbuild.github.io/plugins/#build-options">esbuild documentation</a></td>
88
+ <td>Can be chequed <a href="#esbuild-default-options">here</a></td>
89
+ </tr>
90
+ <tr>
91
+ <td>openBrowser</td>
92
+ <td colspan="3">If the browser should open at localhost url when server starts</td>
93
+ <td>"true"</td>
94
+ </tr>
95
+ <tr>
96
+ <td>watch</td>
97
+ <td colspan="3">If the server should watch for changes on the folders</td>
98
+ <td>"true"</td>
99
+ </tr>
100
+ <tr>
101
+ <td>port</td>
102
+ <td colspan="3">Port to run dev server on</td>
103
+ <td>"3000"</td>
104
+ </tr>
105
+ <tr>
106
+ <td rowspan="14">public</td>
107
+ <td rowspan="14">Public folder - will be copied at server start</td>
108
+ <tr>
109
+ <td rowspan="4">assets</td>
110
+ <tr>
111
+ <td>path</td>
112
+ <td>"assets"</td>
113
+ </tr>
114
+ <tr>
115
+ <td>screenshots</td>
116
+ <td></td>
117
+ </tr>
118
+ <tr>
119
+ <td>featureImage</td>
120
+ <td></td>
121
+ </tr>
122
+ </tr>
123
+ <tr>
124
+ <td colspan="2">indexName</td>
125
+ <td>"index.html"</td>
126
+ </tr>
127
+ <tr>
128
+ <td colspan="2">minify</td>
129
+ <td>"true" if environment is PRODUCTION</td>
130
+ </tr>
131
+ <tr>
132
+ <td colspan="2">path</td>
133
+ <td>"public"</td>
134
+ </tr>
135
+ <tr>
136
+ <td rowspan="3">manifest <br/><small>(A JSON document that contains startup parameters and application defaults for when a web application is launched.)</small></td>
137
+ <tr>
138
+ <td>name</td>
139
+ <td>"manifest.json"</td>
140
+ </tr>
141
+ <tr>
142
+ <td>options</td>
143
+ <td></td>
144
+ </tr>
145
+ </tr>
146
+ <tr>
147
+ <td rowspan="3">wellKnown <br/><small>(A URI with the path component /.well-known/assetlinks.json is used by the AssetLinks protocol to identify one or more digital assets (such as web sites or mobile apps) that are related to the hosting web site in some fashion.)</small></td>
148
+ <tr>
149
+ <td>relation</td>
150
+ <td></td>
151
+ </tr>
152
+ <tr>
153
+ <td>target</td>
154
+ <td></td>
155
+ </tr>
156
+ </tr>
157
+ </tr>
158
+ </tbody>
159
+ </table>
160
+
161
+ ## Esbuild default options
162
+
163
+ <table>
164
+ <thead>
165
+ <tr>
166
+ <th>Field</th>
167
+ <th>Default value</th>
168
+ </tr>
169
+ </thead>
170
+ <tbody>
171
+ <tr>
172
+ <td>bundle</td>
173
+ <td>"true"</td>
174
+ </tr>
175
+ <tr>
176
+ <td>entryPoints</td>
177
+ <td>['src/index.ts']</td>
178
+ </tr>
179
+ <tr>
180
+ <td>format</td>
181
+ <td>"esm"</td>
182
+ </tr>
183
+ <tr>
184
+ <td>keepNames</td>
185
+ <td>"true" if environment is PRODUCTION</td>
186
+ </tr>
187
+ <tr>
188
+ <td>logLevel</td>
189
+ <td>"error"</td>
190
+ </tr>
191
+ <tr>
192
+ <td>minifySyntax</td>
193
+ <td>"true" if environment is PRODUCTION</td>
194
+ </tr>
195
+ <tr>
196
+ <td>minifyWhitespace</td>
197
+ <td>"true" if environment is PRODUCTION</td>
198
+ </tr>
199
+ <tr>
200
+ <td>outdir</td>
201
+ <td>"build"</td>
202
+ </tr>
203
+ <tr>
204
+ <td>sourcemap</td>
205
+ <td>"true" if environment is <b>NOT</b> PRODUCTION</td>
206
+ </tr>
207
+ <tr>
208
+ <td>splitting</td>
209
+ <td>"true"</td>
210
+ </tr>
211
+ <tr>
212
+ <td>target</td>
213
+ <td>"esnext"</td>
214
+ </tr>
215
+ <tr>
216
+ <td>tsconfig</td>
217
+ <td>"tsconfig.json"</td>
218
+ </tr>
219
+ </tbody>
220
+ </table>
221
+
222
+ ## License
223
+ - [MIT](https://github.com/michijs/dev-server/blob/master/LICENSE.md)
224
+
225
+ [repo-size]: https://img.shields.io/github/repo-size/michijs/dev-server
226
+ [npm-downloads]: https://img.shields.io/npm/dt/@michijs/dev-server
227
+ [version]: https://img.shields.io/npm/v/@michijs/dev-server
228
+ [github-license]: https://img.shields.io/github/license/michijs/dev-server
229
+ [github-license-url]: https://github.com/michijs/dev-server/blob/master/LICENSE.md
@@ -1,5 +1,5 @@
1
- import { config } from '../config/config.js';
2
- import { build as esbuild } from 'esbuild';
1
+ import { config } from "../config/config.js";
2
+ import { build as esbuild } from "esbuild";
3
3
  export function build(callback) {
4
4
  return new Promise((resolve, reject) => {
5
5
  esbuild(config.esbuildOptions)
@@ -1,11 +1,11 @@
1
- import { tsconfig } from '../config/tsconfig.js';
2
- import { config } from '../config/config.js';
3
- import { exec } from 'child_process';
4
- import fs from 'fs';
1
+ import { tsconfig } from "../config/tsconfig.js";
2
+ import { config } from "../config/config.js";
3
+ import { exec } from "child_process";
4
+ import fs from "fs";
5
5
  export function dist(callback, watch = false) {
6
6
  if (tsconfig.compilerOptions.outDir &&
7
7
  fs.existsSync(tsconfig.compilerOptions.outDir)) {
8
8
  fs.rmSync(tsconfig.compilerOptions.outDir, { recursive: true });
9
9
  }
10
- exec(`tsc ${watch ? '-w' : ''} --project ${config.esbuildOptions.tsconfig}`, callback);
10
+ exec(`tsc ${watch ? "-w" : ""} --project ${config.esbuildOptions.tsconfig}`, callback);
11
11
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare function generateFeatureImage(src: string): Promise<void>;
3
+ export declare function generateScreenshots(): Promise<(string | Buffer)[][]>;
4
+ export declare function generateAssets(callback: () => void, src: string): Promise<void>;
@@ -0,0 +1,125 @@
1
+ import { getPath } from "../utils/getPath.js";
2
+ import { config } from "../config/config.js";
3
+ import { mkdirSync, existsSync, writeFileSync, readFileSync, rmSync } from "fs";
4
+ import { pngToIco } from "../utils/pngToIco.js";
5
+ import { fileURLToPath } from "url";
6
+ import { dirname, resolve } from "path";
7
+ import sharp from "sharp";
8
+ import { getLocalURL } from "../utils/getLocalURL.js";
9
+ import { assetsSizes } from "../constants.js";
10
+ import puppeteer from "puppeteer";
11
+ const generatedPath = getPath(`${config.public.path}/${config.public.assets.path}/generated`);
12
+ const screenshotsPath = getPath(`${generatedPath}/screenshots`);
13
+ const svgPath = resolve(getPath(dirname(fileURLToPath(import.meta.url))), "../..");
14
+ const generateFavicon = async (src, dest) => {
15
+ const { default: sharp } = await import("sharp");
16
+ const image = await sharp(src);
17
+ const iconSizes = [16, 24, 32, 48, 64, 128, 256];
18
+ const resizedBuffers = await Promise.all(iconSizes.map((size) => {
19
+ return image.resize(size, size).png().toBuffer();
20
+ }));
21
+ writeFileSync(dest, await pngToIco(resizedBuffers, iconSizes));
22
+ };
23
+ config.watch = false;
24
+ config.openBrowser = false;
25
+ const browser = await puppeteer.launch({
26
+ dumpio: true,
27
+ headless: "new",
28
+ product: "chrome",
29
+ });
30
+ const port = await new Promise(async (resolve) => {
31
+ const { start } = await import("./start.js");
32
+ start((port) => resolve(port));
33
+ });
34
+ async function takeScreenshots({ viewports, options, pageCallback, path, }) {
35
+ return await Promise.all(viewports.map(async (viewport) => {
36
+ // Create a new page
37
+ const page = await browser.newPage();
38
+ await page.goto(`${getLocalURL(port)}${path}`);
39
+ await page.setViewport(viewport);
40
+ const prefix = await pageCallback?.(page);
41
+ const screenshot = await page.screenshot({
42
+ fullPage: true,
43
+ ...options?.(viewport, prefix ? `_${prefix}` : prefix),
44
+ });
45
+ await page.close();
46
+ return screenshot;
47
+ }));
48
+ }
49
+ export async function generateFeatureImage(src) {
50
+ const svgFilePath = getPath(`${svgPath}/feature-image-template.svg`);
51
+ const [screenshots, icon] = await Promise.all([
52
+ takeScreenshots({
53
+ viewports: [
54
+ // Phone
55
+ { width: 288, height: 387 },
56
+ // Tablet
57
+ { width: 390, height: 280 },
58
+ // Desktop
59
+ { width: 900, height: 550 },
60
+ ],
61
+ path: config.public.assets.featureImage.path,
62
+ pageCallback: config.public.assets.featureImage.pageCallback,
63
+ }),
64
+ sharp(src).resize(512, 512).png().toBuffer(),
65
+ ]);
66
+ const svg = readFileSync(svgFilePath);
67
+ const svgString = svg
68
+ .toString()
69
+ .replace("{{phone-href}}", `data:image/png;base64,${screenshots[0].toString("base64")}`)
70
+ .replace("{{tablet-href}}", `data:image/png;base64,${screenshots[1].toString("base64")}`)
71
+ .replace("{{pc-href}}", `data:image/png;base64,${screenshots[2].toString("base64")}`)
72
+ .replace("{{icon-href}}", `data:image/png;base64,${icon.toString("base64")}`)
73
+ .replace("{{background}}", config.public.manifest?.options?.background_color ?? "transparent")
74
+ .replace("{{app-title}}", config.public.manifest?.options?.name ?? "");
75
+ writeFileSync(getPath(`${generatedPath}/feature-image.svg`), svgString);
76
+ await sharp(Buffer.from(svgString))
77
+ .resize(1024, 500)
78
+ .png()
79
+ .toFile(getPath(`${generatedPath}/feature-image.png`));
80
+ }
81
+ export async function generateScreenshots() {
82
+ return await Promise.all(config.public.assets.screenshots.paths.flatMap((path) => config.public.assets.screenshots.pageCallbacks.map(async (pageCallback, index) => await takeScreenshots({
83
+ viewports: assetsSizes.screenshots,
84
+ path,
85
+ pageCallback,
86
+ options(viewport, pagePrefix = config.public.assets.screenshots.pageCallbacks
87
+ .length > 1
88
+ ? `_${index}`
89
+ : "") {
90
+ const screenshotPath = getPath(`${screenshotsPath}${pagePrefix}${path.replace("?", "_")}`);
91
+ if (!existsSync(screenshotPath))
92
+ mkdirSync(screenshotPath, { recursive: true });
93
+ return {
94
+ path: getPath(`${screenshotPath}/screenshot-${viewport.width}x${viewport.height}.png`),
95
+ };
96
+ },
97
+ }))));
98
+ }
99
+ export async function generateAssets(callback, src) {
100
+ rmSync(generatedPath, { recursive: true });
101
+ if (!existsSync(generatedPath))
102
+ mkdirSync(screenshotsPath, { recursive: true });
103
+ const image = sharp(src);
104
+ const fileNameWithoutExtension = src.split("/").at(-1)?.split(".")[0];
105
+ await Promise.all([
106
+ ...assetsSizes.webp.map((x) => {
107
+ return image
108
+ .resize(x, x)
109
+ .webp()
110
+ .toFile(getPath(`${generatedPath}/${fileNameWithoutExtension}-${x}.webp`));
111
+ }),
112
+ ...assetsSizes.png.map((x) => {
113
+ return image
114
+ .resize(x, x)
115
+ .png()
116
+ .toFile(getPath(`${generatedPath}/${fileNameWithoutExtension}-${x}.png`));
117
+ }),
118
+ generateFavicon(src, getPath(`${config.public.path}/favicon.ico`)),
119
+ generateFeatureImage(src),
120
+ generateScreenshots(),
121
+ ]);
122
+ callback();
123
+ await browser.close();
124
+ process.exit();
125
+ }
@@ -1 +1 @@
1
- export declare const start: (callback: () => void) => void;
1
+ export declare const start: (callback: (selectedPort: number) => void) => void;