@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.
- package/LICENSE.md +8 -8
- package/README.md +229 -208
- package/bin/actions/build.js +2 -2
- package/bin/actions/dist.js +5 -5
- package/bin/actions/generateAssets.d.ts +4 -0
- package/bin/actions/generateAssets.js +125 -0
- package/bin/actions/start.d.ts +1 -1
- package/bin/actions/start.js +46 -30
- package/bin/cli.js +33 -33
- package/bin/config/config.d.ts +111 -6
- package/bin/config/config.js +40 -31
- package/bin/config/getIPAddress.js +5 -3
- package/bin/config/michi.config.cjs +159 -0
- package/bin/config/public/client.js +1 -1
- package/bin/config/tsconfig.d.ts +1 -1
- package/bin/config/tsconfig.js +3 -3
- package/bin/config/userConfig.d.ts +1 -1
- package/bin/config/userConfig.js +18 -14
- package/bin/constants.d.ts +8 -0
- package/bin/constants.js +12 -0
- package/bin/index.d.ts +1 -1
- package/bin/index.js +1 -1
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/bin/types.d.ts +71 -7
- package/bin/utils/copy.js +4 -4
- package/bin/utils/feature-image-template.svg +62 -0
- package/bin/utils/getAllFiles.js +2 -2
- package/bin/utils/getHostURL.d.ts +1 -0
- package/bin/utils/getHostURL.js +4 -0
- package/bin/utils/getLocalURL.d.ts +1 -0
- package/bin/utils/getLocalURL.js +3 -0
- package/bin/utils/getPath.js +1 -1
- package/bin/utils/minify.js +3 -3
- package/bin/utils/serviceWorkerTransformer.d.ts +1 -1
- package/bin/utils/serviceWorkerTransformer.js +8 -8
- package/bin/utils/transformers.d.ts +1 -1
- package/bin/utils/transformers.js +4 -4
- package/package.json +63 -74
- package/bin/actions/generateIcons.d.ts +0 -1
- 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
|
-
|
|
5
|
-
|
|
6
|
-
[![
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<th>
|
|
27
|
-
<th>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<td>
|
|
34
|
-
<td>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<td>
|
|
39
|
-
<td>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<td>
|
|
44
|
-
<td>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<td
|
|
49
|
-
<td
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
</
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
<th>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<td
|
|
82
|
-
<td
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<td
|
|
87
|
-
<td>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<td
|
|
92
|
-
<td
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<td
|
|
97
|
-
<td
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<td
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
</
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
</tr>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<td>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
<td>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<td>
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
<td>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
<td>
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
<td>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
<td>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
+
[](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml)
|
|
7
|
+
[](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
|
package/bin/actions/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { config } from
|
|
2
|
-
import { build as esbuild } from
|
|
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)
|
package/bin/actions/dist.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { tsconfig } from
|
|
2
|
-
import { config } from
|
|
3
|
-
import { exec } from
|
|
4
|
-
import fs from
|
|
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 ?
|
|
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
|
+
}
|
package/bin/actions/start.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const start: (callback: () => void) => void;
|
|
1
|
+
export declare const start: (callback: (selectedPort: number) => void) => void;
|