@metricinsights/pp-dev 0.17.0 ā 0.18.1
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/CHANGELOG.md +81 -61
- package/README.md +91 -66
- package/dist/CHANGELOG.md +81 -61
- package/dist/README.md +91 -66
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index-B1GblhLQ.js +2 -0
- package/dist/cjs/index-B1GblhLQ.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/plugin-DY9gjLm8.js +2 -0
- package/dist/cjs/plugin-DY9gjLm8.js.map +1 -0
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/version-plugin-DSLhm6Q1.js +2 -0
- package/dist/cjs/version-plugin-DSLhm6Q1.js.map +1 -0
- package/dist/client/client.css +1 -1
- package/dist/client/client.css.map +1 -1
- package/dist/client/client.js +91 -2
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.html +12 -9
- package/dist/esm/cli.js +1 -1
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index-basLGB1P.js +2 -0
- package/dist/esm/index-basLGB1P.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/package.json +2 -2
- package/dist/esm/plugin-B6DaUVqp.js +2 -0
- package/dist/esm/plugin-B6DaUVqp.js.map +1 -0
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/version-plugin-DekxT1OJ.js +2 -0
- package/dist/esm/version-plugin-DekxT1OJ.js.map +1 -0
- package/dist/types/index.d.ts +1 -205
- package/package.json +4 -3
- package/pp-dev.d.ts +1 -0
- package/scripts/patch-npm-bundled-vulnerabilities.mjs +8 -11
- package/dist/cjs/index-Bu8AM2lb.js +0 -2
- package/dist/cjs/index-Bu8AM2lb.js.map +0 -1
- package/dist/cjs/plugin-D-TIdILy.js +0 -2
- package/dist/cjs/plugin-D-TIdILy.js.map +0 -1
- package/dist/cjs/version-plugin-Cj4Pv-pw.js +0 -2
- package/dist/cjs/version-plugin-Cj4Pv-pw.js.map +0 -1
- package/dist/esm/index-Cx5STeh7.js +0 -2
- package/dist/esm/index-Cx5STeh7.js.map +0 -1
- package/dist/esm/plugin-CE47-pTE.js +0 -2
- package/dist/esm/plugin-CE47-pTE.js.map +0 -1
- package/dist/esm/version-plugin-B1n39tE6.js +0 -2
- package/dist/esm/version-plugin-B1n39tE6.js.map +0 -1
package/dist/README.md
CHANGED
|
@@ -53,6 +53,7 @@ import '@metricinsights/pp-dev/client/css/client.css';
|
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
**Available Exports**:
|
|
56
|
+
|
|
56
57
|
- **Main**: Complete pp-dev functionality with CLI and plugins
|
|
57
58
|
- **Plugin**: Vite plugin for integration with build tools
|
|
58
59
|
- **Helpers**: Utility functions for authentication and configuration
|
|
@@ -63,6 +64,7 @@ import '@metricinsights/pp-dev/client/css/client.css';
|
|
|
63
64
|
The pp-dev package includes optimized startup performance and build system with multiple strategies:
|
|
64
65
|
|
|
65
66
|
### Quick Start
|
|
67
|
+
|
|
66
68
|
```bash
|
|
67
69
|
# Standard build (parallel)
|
|
68
70
|
npm run build
|
|
@@ -84,6 +86,7 @@ npm run startup:optimize
|
|
|
84
86
|
```
|
|
85
87
|
|
|
86
88
|
### Performance Features
|
|
89
|
+
|
|
87
90
|
- **40-50% faster startup** with intelligent caching
|
|
88
91
|
- **60-70% faster subsequent starts** with connection pooling
|
|
89
92
|
- **Lazy loading** of heavy modules (jsdom, esbuild)
|
|
@@ -93,6 +96,7 @@ npm run startup:optimize
|
|
|
93
96
|
- **Intelligent dependency optimization** based on profiling data
|
|
94
97
|
|
|
95
98
|
### Build Features
|
|
99
|
+
|
|
96
100
|
- **Parallel builds** for 40-60% faster build times
|
|
97
101
|
- **Enhanced tree-shaking** for smaller bundles
|
|
98
102
|
- **Multiple output formats** (ESM, CJS, Types)
|
|
@@ -110,6 +114,7 @@ The new startup optimization system in v0.11.0 provides:
|
|
|
110
114
|
- **Optimization Suggestions**: Automated recommendations for performance improvements
|
|
111
115
|
|
|
112
116
|
Run the startup optimizer to analyze and improve your development environment:
|
|
117
|
+
|
|
113
118
|
```bash
|
|
114
119
|
npm run startup:optimize
|
|
115
120
|
```
|
|
@@ -122,6 +127,7 @@ npm run startup:optimize
|
|
|
122
127
|
### Configuration File
|
|
123
128
|
|
|
124
129
|
Create a configuration file named `pp-dev.config` with one of these extensions:
|
|
130
|
+
|
|
125
131
|
- `.js` or `.cjs` (for CommonJS)
|
|
126
132
|
- `.ts` (for TypeScript)
|
|
127
133
|
- `.json`
|
|
@@ -200,28 +206,28 @@ export default config;
|
|
|
200
206
|
|
|
201
207
|
### Required Options
|
|
202
208
|
|
|
203
|
-
| Option
|
|
204
|
-
|
|
205
|
-
| `backendBaseURL` | string | URL of the Metric Insights instance for API proxying
|
|
206
|
-
| `portalPageId`
|
|
207
|
-
| `appId`
|
|
209
|
+
| Option | Type | Description |
|
|
210
|
+
| ---------------- | ------ | --------------------------------------------------------------------------- |
|
|
211
|
+
| `backendBaseURL` | string | URL of the Metric Insights instance for API proxying |
|
|
212
|
+
| `portalPageId` | number | ID of the Portal Page for variable values (deprecated, use `appId` instead) |
|
|
213
|
+
| `appId` | number | ID of the Portal Page for variable values (synonym for `portalPageId`) |
|
|
208
214
|
|
|
209
215
|
### Optional Options
|
|
210
216
|
|
|
211
|
-
| Option
|
|
212
|
-
|
|
213
|
-
| `miHudLess`
|
|
214
|
-
| `integrateMiTopBar`
|
|
215
|
-
| `templateLess`
|
|
216
|
-
| `enableProxyCache`
|
|
217
|
-
| `proxyCacheTTL`
|
|
218
|
-
| `disableSSLValidation` | boolean
|
|
219
|
-
| `imageOptimizer`
|
|
220
|
-
| `outDir`
|
|
221
|
-
| `distZip`
|
|
222
|
-
| `syncBackupsDir`
|
|
223
|
-
| `v7Features`
|
|
224
|
-
| `personalAccessToken`
|
|
217
|
+
| Option | Type | Default | Description |
|
|
218
|
+
| ---------------------- | ----------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
219
|
+
| `miHudLess` | boolean | `false` | Disables Metric Insights navigation bar in development |
|
|
220
|
+
| `integrateMiTopBar` | boolean \| object | `false` | Integrates MI Top Bar and scripts into the App build (requires `miHudLess: true`). When `true`, enables both `addRootElement` and `addSharedComponentsScripts`. When an object, allows selective enabling: `{ addRootElement?: boolean, addSharedComponentsScripts?: boolean }` |
|
|
221
|
+
| `templateLess` | boolean | `false` | Disables template variable transformation |
|
|
222
|
+
| `enableProxyCache` | boolean | `true` | Enables caching of proxied requests |
|
|
223
|
+
| `proxyCacheTTL` | number | `600000` | Cache TTL in milliseconds (10 minutes) |
|
|
224
|
+
| `disableSSLValidation` | boolean | `false` | Disables SSL certificate validation for proxy requests |
|
|
225
|
+
| `imageOptimizer` | boolean \| object | `true` | Controls image optimization. See [vite-plugin-image-optimizer](https://www.npmjs.com/package/vite-plugin-image-optimizer#plugin-options) for object options |
|
|
226
|
+
| `outDir` | string | `dist` | Output directory for builds |
|
|
227
|
+
| `distZip` | boolean \| object | `true` | Controls build output zipping. Object options: `{ outDir?: string, outFileName?: string }` |
|
|
228
|
+
| `syncBackupsDir` | string | `backups` | Directory for asset backups from MI server |
|
|
229
|
+
| `v7Features` | boolean | `false` | Enables Metric Insights v7 features |
|
|
230
|
+
| `personalAccessToken` | string | `process.env.MI_ACCESS_TOKEN` | Personal Access Token for the MI instance |
|
|
225
231
|
|
|
226
232
|
### integrateMiTopBar Details
|
|
227
233
|
|
|
@@ -238,10 +244,12 @@ The `integrateMiTopBar` option allows you to integrate the Metric Insights Top B
|
|
|
238
244
|
`integrateMiTopBar` can be configured in two ways:
|
|
239
245
|
|
|
240
246
|
**1. Boolean (Simple)**
|
|
247
|
+
|
|
241
248
|
- `true`: Enables both `addRootElement` and `addSharedComponentsScripts`
|
|
242
249
|
- `false`: Disables integration (default)
|
|
243
250
|
|
|
244
251
|
**2. Object (Advanced)**
|
|
252
|
+
|
|
245
253
|
- `addRootElement`: Adds `<div id="mi-react-root">` element to the body for React mounting
|
|
246
254
|
- `addSharedComponentsScripts`: Adds MI shared component scripts and styles:
|
|
247
255
|
- `/auth/info.js` - Authentication info script
|
|
@@ -251,17 +259,19 @@ The `integrateMiTopBar` option allows you to integrate the Metric Insights Top B
|
|
|
251
259
|
#### Examples
|
|
252
260
|
|
|
253
261
|
**Simple boolean configuration:**
|
|
262
|
+
|
|
254
263
|
```javascript
|
|
255
264
|
// pp-dev.config.js
|
|
256
265
|
module.exports = {
|
|
257
266
|
backendBaseURL: 'https://mi.company.com',
|
|
258
267
|
appId: 1,
|
|
259
|
-
miHudLess: true,
|
|
260
|
-
integrateMiTopBar: true,
|
|
268
|
+
miHudLess: true, // Required: Disable dynamic MI scripts
|
|
269
|
+
integrateMiTopBar: true, // Enable: Integrate Top Bar into build
|
|
261
270
|
};
|
|
262
271
|
```
|
|
263
272
|
|
|
264
273
|
**Advanced object configuration (selective features):**
|
|
274
|
+
|
|
265
275
|
```javascript
|
|
266
276
|
// pp-dev.config.js
|
|
267
277
|
module.exports = {
|
|
@@ -269,13 +279,14 @@ module.exports = {
|
|
|
269
279
|
appId: 1,
|
|
270
280
|
miHudLess: true,
|
|
271
281
|
integrateMiTopBar: {
|
|
272
|
-
addRootElement: true,
|
|
273
|
-
addSharedComponentsScripts: true,
|
|
282
|
+
addRootElement: true, // Add root element for React
|
|
283
|
+
addSharedComponentsScripts: true, // Add MI scripts and styles
|
|
274
284
|
},
|
|
275
285
|
};
|
|
276
286
|
```
|
|
277
287
|
|
|
278
288
|
**Partial integration (scripts only, manual root element):**
|
|
289
|
+
|
|
279
290
|
```javascript
|
|
280
291
|
// pp-dev.config.js
|
|
281
292
|
module.exports = {
|
|
@@ -283,8 +294,8 @@ module.exports = {
|
|
|
283
294
|
appId: 1,
|
|
284
295
|
miHudLess: true,
|
|
285
296
|
integrateMiTopBar: {
|
|
286
|
-
addRootElement: false,
|
|
287
|
-
addSharedComponentsScripts: true,
|
|
297
|
+
addRootElement: false, // Don't add root element
|
|
298
|
+
addSharedComponentsScripts: true, // Add MI scripts and styles
|
|
288
299
|
},
|
|
289
300
|
};
|
|
290
301
|
```
|
|
@@ -292,6 +303,7 @@ module.exports = {
|
|
|
292
303
|
### v7Features Details
|
|
293
304
|
|
|
294
305
|
When enabled (`true`), this option:
|
|
306
|
+
|
|
295
307
|
1. Changes development path from `/pt/<portal-page-name>` to `/pl/<portal-page-name>`
|
|
296
308
|
2. Updates Code Sync feature to use v7.1.0+ URLs
|
|
297
309
|
|
|
@@ -300,6 +312,7 @@ When enabled (`true`), this option:
|
|
|
300
312
|
The `personalAccessToken` option allows you to authenticate with the Metric Insights instance. You can set it in your configuration or use the `MI_ACCESS_TOKEN` environment variable.
|
|
301
313
|
|
|
302
314
|
Example with authentication and Top Bar integration:
|
|
315
|
+
|
|
303
316
|
```javascript
|
|
304
317
|
// pp-dev.config.js
|
|
305
318
|
module.exports = {
|
|
@@ -312,10 +325,16 @@ module.exports = {
|
|
|
312
325
|
```
|
|
313
326
|
|
|
314
327
|
**Environment Variable**: Set `MI_ACCESS_TOKEN` in your `.env` file:
|
|
328
|
+
|
|
315
329
|
```bash
|
|
316
330
|
MI_ACCESS_TOKEN=your_token_here
|
|
317
331
|
```
|
|
318
332
|
|
|
333
|
+
**Local development and network exposure**: pp-dev is a **development** tool. It assumes a trusted machine. Personal access tokens and session helpers are still sensitive: they can authenticate to your Metric Insights backend as you.
|
|
334
|
+
|
|
335
|
+
- Prefer binding the dev server to **`localhost`** when you do not need access from other devices. If you use **`--host`** (or equivalent) so the app listens on **all interfaces** or your LAN, other machines on the same network can reach the dev server and its dev-only routes (for example the in-browser token login flow). Treat that like exposing credentials: use only on networks you trust, or restrict access with your OS firewall.
|
|
336
|
+
- Do not commit real tokens; keep them in `.env` (gitignored) or your secret store. Avoid sharing screen recordings or logs that contain `MI_ACCESS_TOKEN` or bearer tokens.
|
|
337
|
+
|
|
319
338
|
### Enhanced Authentication (v0.11.0+)
|
|
320
339
|
|
|
321
340
|
The new authentication system in v0.11.0 provides:
|
|
@@ -326,11 +345,13 @@ The new authentication system in v0.11.0 provides:
|
|
|
326
345
|
- **Connection Pooling**: Optimized HTTP connections for better performance
|
|
327
346
|
|
|
328
347
|
**Supported Environment Variables**:
|
|
348
|
+
|
|
329
349
|
- `MI_ACCESS_TOKEN`: Personal access token for authentication
|
|
330
350
|
- `MI_BACKEND_URL`: Alternative to `backendBaseURL` in config
|
|
331
351
|
- `MI_APP_ID`: Alternative to `appId` in config
|
|
332
352
|
|
|
333
353
|
**Automatic Loading**: pp-dev automatically detects and loads these variables from your project's `.env` file:
|
|
354
|
+
|
|
334
355
|
```bash
|
|
335
356
|
# .env
|
|
336
357
|
MI_ACCESS_TOKEN=your_personal_access_token
|
|
@@ -342,13 +363,13 @@ MI_APP_ID=123
|
|
|
342
363
|
|
|
343
364
|
### Global Options
|
|
344
365
|
|
|
345
|
-
| Option
|
|
346
|
-
|
|
347
|
-
| `-c, --config <file>`
|
|
348
|
-
| `--base <path>`
|
|
366
|
+
| Option | Description |
|
|
367
|
+
| ------------------------ | -------------------------------------------------------------------------------- |
|
|
368
|
+
| `-c, --config <file>` | Path to configuration file (default: `pp-dev.config.js`) |
|
|
369
|
+
| `--base <path>` | Public base path (default: `/`) |
|
|
349
370
|
| `-l, --logLevel <level>` | Log level: `trace`, `debug`, `info`, `warn`, `error`, `silent` (default: `info`) |
|
|
350
|
-
| `--clearScreen`
|
|
351
|
-
| `--mode <mode>`
|
|
371
|
+
| `--clearScreen` | Clear screen before logging |
|
|
372
|
+
| `--mode <mode>` | Environment mode: `development`, `production`, `test` (default: `development`) |
|
|
352
373
|
|
|
353
374
|
### Development Server
|
|
354
375
|
|
|
@@ -357,15 +378,16 @@ pp-dev [root] [options]
|
|
|
357
378
|
# Aliases: pp-dev dev, pp-dev serve
|
|
358
379
|
```
|
|
359
380
|
|
|
360
|
-
| Option
|
|
361
|
-
|
|
362
|
-
| `[root]`
|
|
363
|
-
| `--host <host>` | `localhost` | Server hostname
|
|
364
|
-
| `--port <port>` | `3000`
|
|
365
|
-
| `--open [path]` | -
|
|
366
|
-
| `--strictPort`
|
|
381
|
+
| Option | Default | Description |
|
|
382
|
+
| --------------- | ----------- | --------------------------------- |
|
|
383
|
+
| `[root]` | `.` | Root directory of the application |
|
|
384
|
+
| `--host <host>` | `localhost` | Server hostname |
|
|
385
|
+
| `--port <port>` | `3000` | Server port |
|
|
386
|
+
| `--open [path]` | - | Open browser on server start |
|
|
387
|
+
| `--strictPort` | - | Exit if port is already in use |
|
|
367
388
|
|
|
368
389
|
**Development Shortcuts**:
|
|
390
|
+
|
|
369
391
|
- `p` - Start/stop performance profiler (v0.11.0+)
|
|
370
392
|
- `l` - Proxy re-login (refresh authentication)
|
|
371
393
|
- `r` - Restart dev server
|
|
@@ -381,11 +403,11 @@ pp-dev next [options]
|
|
|
381
403
|
# Aliases: pp-dev next-server, pp-dev next-dev
|
|
382
404
|
```
|
|
383
405
|
|
|
384
|
-
| Option
|
|
385
|
-
|
|
386
|
-
| `[root]`
|
|
387
|
-
| `--port <port>` | `3000`
|
|
388
|
-
| `--host <host>` | `localhost` | Server hostname
|
|
406
|
+
| Option | Default | Description |
|
|
407
|
+
| --------------- | ----------- | --------------------------------- |
|
|
408
|
+
| `[root]` | `.` | Root directory of the application |
|
|
409
|
+
| `--port <port>` | `3000` | Server port |
|
|
410
|
+
| `--host <host>` | `localhost` | Server hostname |
|
|
389
411
|
|
|
390
412
|
### Build
|
|
391
413
|
|
|
@@ -393,13 +415,13 @@ pp-dev next [options]
|
|
|
393
415
|
pp-dev build [options]
|
|
394
416
|
```
|
|
395
417
|
|
|
396
|
-
| Option
|
|
397
|
-
|
|
398
|
-
| `[root]`
|
|
399
|
-
| `--target <target>`
|
|
400
|
-
| `--outDir <dir>`
|
|
401
|
-
| `--assetsDir <dir>`
|
|
402
|
-
| `--changelog [file]` | `true`
|
|
418
|
+
| Option | Default | Description |
|
|
419
|
+
| -------------------- | --------- | --------------------------------- |
|
|
420
|
+
| `[root]` | `.` | Root directory of the application |
|
|
421
|
+
| `--target <target>` | `modules` | Transpile target |
|
|
422
|
+
| `--outDir <dir>` | `dist` | Output directory |
|
|
423
|
+
| `--assetsDir <dir>` | `assets` | Assets directory under outDir |
|
|
424
|
+
| `--changelog [file]` | `true` | Create changelog file |
|
|
403
425
|
|
|
404
426
|
### Changelog Generation
|
|
405
427
|
|
|
@@ -407,14 +429,14 @@ pp-dev build [options]
|
|
|
407
429
|
pp-dev changelog [oldAssetPath] [newAssetPath] [options]
|
|
408
430
|
```
|
|
409
431
|
|
|
410
|
-
| Option
|
|
411
|
-
|
|
412
|
-
| `[oldAssetPath]`
|
|
413
|
-
| `[newAssetPath]`
|
|
414
|
-
| `--oldAssetsPath <path>` | -
|
|
415
|
-
| `--newAssetsPath <path>` | -
|
|
416
|
-
| `--destination <path>`
|
|
417
|
-
| `--filename <name>`
|
|
432
|
+
| Option | Default | Description |
|
|
433
|
+
| ------------------------ | ---------------- | -------------------------- |
|
|
434
|
+
| `[oldAssetPath]` | - | Path to previous assets |
|
|
435
|
+
| `[newAssetPath]` | - | Path to current assets |
|
|
436
|
+
| `--oldAssetsPath <path>` | - | Path to previous assets |
|
|
437
|
+
| `--newAssetsPath <path>` | - | Path to current assets |
|
|
438
|
+
| `--destination <path>` | `.` | Changelog output directory |
|
|
439
|
+
| `--filename <name>` | `CHANGELOG.html` | Changelog filename |
|
|
418
440
|
|
|
419
441
|
### Icon Font Generation
|
|
420
442
|
|
|
@@ -422,13 +444,13 @@ pp-dev changelog [oldAssetPath] [newAssetPath] [options]
|
|
|
422
444
|
pp-dev generate-icon-font [source] [destination] [options]
|
|
423
445
|
```
|
|
424
446
|
|
|
425
|
-
| Option
|
|
426
|
-
|
|
427
|
-
| `[source]`
|
|
428
|
-
| `[destination]`
|
|
429
|
-
| `--source <path>`
|
|
430
|
-
| `--destination <path>` | -
|
|
431
|
-
| `--fontName <name>`
|
|
447
|
+
| Option | Default | Description |
|
|
448
|
+
| ---------------------- | ----------- | ------------------------------- |
|
|
449
|
+
| `[source]` | - | Source directory with SVG icons |
|
|
450
|
+
| `[destination]` | - | Output directory |
|
|
451
|
+
| `--source <path>` | - | Source directory with SVG icons |
|
|
452
|
+
| `--destination <path>` | - | Output directory |
|
|
453
|
+
| `--fontName <name>` | `icon-font` | Font name |
|
|
432
454
|
|
|
433
455
|
## Next.js Integration
|
|
434
456
|
|
|
@@ -442,12 +464,13 @@ pp-dev generate-icon-font [source] [destination] [options]
|
|
|
442
464
|
}
|
|
443
465
|
```
|
|
444
466
|
3. Wrap your Next.js config:
|
|
467
|
+
|
|
445
468
|
```javascript
|
|
446
469
|
// next.config.js
|
|
447
470
|
const { withPPDev } = require('@metricinsights/pp-dev');
|
|
448
471
|
|
|
449
472
|
module.exports = withPPDev({
|
|
450
|
-
|
|
473
|
+
// your Next.js config
|
|
451
474
|
});
|
|
452
475
|
```
|
|
453
476
|
|
|
@@ -464,11 +487,13 @@ For custom build configuration, create a `vite.config` file. See [Vite Configura
|
|
|
464
487
|
If you encounter an error like "Next.js is required but not available":
|
|
465
488
|
|
|
466
489
|
1. **Install Next.js in your project:**
|
|
490
|
+
|
|
467
491
|
```bash
|
|
468
492
|
npm install next@^15
|
|
469
493
|
```
|
|
470
494
|
|
|
471
495
|
2. **Verify the installation:**
|
|
496
|
+
|
|
472
497
|
```bash
|
|
473
498
|
npm list next
|
|
474
499
|
```
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e=require("path"),o=require("fs"),t=require("node:perf_hooks"),n=require("chokidar"),i=require("cac"),r=require("vite"),s=require("./index-Bu8AM2lb.js"),a=require("./plugin-D-TIdILy.js"),l=require("url"),c=require("dir-compare"),d=require("diff-match-patch"),p=require("isbinaryfile"),f=require("os"),u=require("crypto"),h=require("extract-zip"),g=require("svgtofont");require("ejs"),require("http-proxy-middleware"),require("picocolors"),require("axios"),require("jsdom"),require("https"),require("memory-cache"),require("process"),require("child_process"),require("console"),require("zlib"),require("express");const m=e=>e&&"object"==typeof e&&"default"in e?e.default:e;function b(e){if(e&&"object"==typeof e&&"default"in e)return e;const o=Object.create(null);if(e)for(const t in e)o[t]=e[t];return o.default=e,Object.freeze(o)}const w=b(e),v=b(o),y=b(c),x=m(d),P=b(f),T=b(u),L=m(h),S=m(g);function $(e){return null!=e&&!1!==e}const k=[{key:"r",description:"restart the server",async action(e){await e.restart()}},{key:"u",description:"show server url",action(e){e.config.logger.info(""),e.printUrls()}},{key:"o",description:"open in browser",action(e){e.openBrowser()}},{key:"c",description:"clear console",action(e){e.config.logger.clearScreen("error")}},{key:"q",description:"quit",async action(e){await e.close().finally(()=>process.exit())}},{key:"C",description:"clear proxy cache",action(e){e.cache&&(e.cache.clear(),e.config.logger.info("Proxy cache cleared"))}}];const E=/(.+)(-[a-f0-9]{6,20})(\.[a-z0-9]+)$/i;class F{oldAssetsPath;newAssetsPath;destinationPath;changelogFilename;changelogTemplate='<!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="UTF-8" />\n <title>Changelog Diff</title>\n <style>\n tr,\n td {\n padding: 0;\n }\n .diff-file {\n margin-top: 20px;\n border: 1px solid #e1e4e8;\n border-radius: 6px;\n }\n .diff-file-title {\n padding: 10px 20px;\n background-color: #f6f8fa;\n border-bottom: 1px solid #e1e4e8;\n border-radius: 6px 6px 0 0;\n font-weight: bold;\n }\n .diff-file-title .renamed {\n font-weight: normal;\n }\n .diff-file-title .renamed .from {\n color: #cb2431;\n }\n .diff-file-title .renamed .to {\n color: #22863a;\n }\n .diff-file-title .added {\n color: #22863a;\n }\n .diff-file-title .deleted {\n color: #cb2431;\n }\n .diff-file-content {\n }\n .diff-table {\n tab-size: 8;\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n }\n .blob-num {\n position: relative;\n color: #1f2328;\n width: 1%;\n min-width: 50px;\n padding: 0 10px;\n font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;\n font-size: 12px;\n line-height: 20px;\n text-align: right;\n white-space: nowrap;\n vertical-align: top;\n cursor: pointer;\n -webkit-user-select: none;\n user-select: none;\n }\n .blob-num.addition {\n background-color: #ccffd8;\n border-color: #1f883e;\n }\n .blob-num.deletion {\n background-color: #ffd7d5;\n border-color: #cf222e;\n }\n .blob-num::before {\n content: attr(data-line-number);\n }\n .blob-code {\n position: relative;\n padding: 0 10px 0 22px;\n vertical-align: top;\n color: #1f2329;\n }\n .blob-code.code-addition {\n background-color: #e6ffec;\n }\n .blob-code.code-deletion {\n background-color: #ffebe9;\n }\n .blob-code.skip,\n .blob-code.message {\n text-align: center;\n }\n .blob-code.skip .blob-code-inner,\n .blob-code.message .blob-code-inner {\n font-weight: bold;\n color: #6a737d;\n padding: 10px 0;\n }\n .blob-code-inner {\n display: table-cell;\n overflow: visible;\n font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;\n font-size: 12px;\n word-wrap: anywhere;\n white-space: pre-wrap;\n }\n .blob-code-inner::before {\n content: attr(data-code-prefix);\n position: absolute;\n top: 1px;\n left: 8px;\n padding-right: 8px;\n }\n </style>\n </head>\n <body>\n <h1>Changelog Diff</h1>\n\n %FILES%\n </body>\n </html>';diffFileTemplateHandler;diffLineTemplateHandler;contextLines=3;logger;constructor(e){const{oldAssetsPath:o,newAssetsPath:t,destinationPath:n,changelogTemplate:i,diffFileTemplateHandler:r,diffLineTemplateHandler:s,changelogFilename:l,contextLines:c}=e;if(this.logger=a.createLogger(),!o||!t||!n)throw new Error("Previous assets path, current assets path and destination path are required");if(o===t)throw new Error("Previous and current assets paths must be different");if(!this.isExists(o))throw new Error(`Previous assets path ${o} does not exist`);if(!this.isExists(t))throw new Error(`Current assets path ${t} does not exist`);if(this.isZipFile(o)){const e=w.resolve(P.tmpdir(),T.createHash("md5").update(o).digest("hex"));this.oldAssetsPath=this.unzipFile(o,e).then(()=>this.normalizeAssetFolderPath(e)).then(e=>{if(this.isEmptyFolder(e))throw new Error(`Previous assets path ${e} is empty`);return e})}else{if(!this.isFolder(o))throw new Error(`Invalid previous assets path ${o}. It must be a folder or a zip file`);{const e=this.normalizeAssetFolderPath(o);if(this.isEmptyFolder(e))throw new Error(`Previous assets path ${e} is empty`);this.oldAssetsPath=Promise.resolve(e)}}if(this.isZipFile(t)){const e=w.resolve(P.tmpdir(),T.createHash("md5").update(t).digest("hex"));this.newAssetsPath=this.unzipFile(t,e).then(()=>this.normalizeAssetFolderPath(e)).then(e=>{if(this.isEmptyFolder(e))throw new Error(`Current assets path ${e} is empty`);return e})}else{if(!this.isFolder(t))throw new Error(`Invalid current assets path ${t}. It must be a folder or a zip file`);{const e=this.normalizeAssetFolderPath(t);if(this.isEmptyFolder(e))throw new Error(`Current assets path ${t} is empty`);this.newAssetsPath=Promise.resolve(e)}}this.destinationPath=n,this.mkdirpSync(this.destinationPath),this.changelogFilename=l||"CHANGELOG.html",i&&(this.templateIsValid(i)?this.changelogTemplate=i:this.logger.warn(a.colors.yellow("Invalid changelog template, using default"))),"function"==typeof r&&(this.diffFileTemplateHandler=r),"function"==typeof s&&(this.diffLineTemplateHandler=s),c&&(this.contextLines=c)}templateIsValid(e){return e.includes("%FILES%")}isExists(e){return v.existsSync(e)}isZipFile(e){return e.endsWith(".zip")}isFolder(e){return v.lstatSync(e).isDirectory()}isEmptyFolder(e){return 0===v.readdirSync(e,{withFileTypes:!0}).length}mkdirpSync(e){v.existsSync(e)||v.mkdirSync(e,{recursive:!0})}async unzipFile(e,o){return v.rmSync(o,{force:!0,recursive:!0}),L(e,{dir:o})}normalizeAssetFolderPath(e){const o=v.readdirSync(e);return 1===o.length&&v.lstatSync(w.join(e,o[0])).isDirectory()?this.normalizeAssetFolderPath(w.join(e,o[0])):e}pathToPosix(e){return e.replace(/\\/g,"/")}diffTableTemplate(e){return`<table class="diff-table">\n <tbody>\n ${e}\n </tbody>\n </table>`}getDiffTableHTML(e){const o=e.filter((e,o,t)=>0!==e.lineType||(o>=0&&o<this.contextLines||o>t.length-(this.contextLines+1)&&o<=t.length-1||t.slice(o-this.contextLines,o+this.contextLines+1).some(e=>0!==e.lineType))).map((e,o,t)=>{if(o>0){const n=t[o-1];if(e.lineNumber-n.lineNumber>1)return[{lineNumber:-1,lineContent:"",lineType:0},e]}return[e]}).flat().map(e=>this.diffLineHTML(e)).join("");return this.diffTableTemplate(o)}diffLineMessageTemplate(e){return`<tr>\n <td class="blob-num"></td>\n <td class="blob-num"></td>\n <td class="blob-code message">\n <span class="blob-code-inner">${e}</span>\n </td>\n </tr>`}diffLineSkipTemplate(){return'<tr>\n <td class="blob-num"></td>\n <td class="blob-num"></td>\n <td class="blob-code skip">\n <span class="blob-code-inner">Skip</span>\n </td>\n </tr>'}diffLineTemplate(e){const{lineNumber:o,lineContent:t,lineType:n}=e,i=1===n?"addition":-1===n?"deletion":"";return`<tr>\n <td\n class="blob-num ${i}${"addition"===i?" empty":""}"\n ${"addition"!==i?` data-line-number="${o}"`:""}\n ></td>\n <td\n class="blob-num ${i}${"deletion"===i?" empty":""}"\n ${"deletion"!==i?` data-line-number="${o}"`:""}\n ></td>\n <td class="blob-code ${1===n?"code-addition":-1===n?"code-deletion":""}">\n <span class="blob-code-inner" data-code-prefix="${1===n?"+":-1===n?"-":" "}">${r=t??"",r.replace(/[\u00A0-\u9999<>&]/g,e=>"&#"+e.charCodeAt(0)+";")}</span>\n </td>\n </tr>`;var r}diffLineHTML(e){if(this.diffLineTemplateHandler)return this.diffLineTemplateHandler(e);const{lineNumber:o}=e;return-1===o?this.diffLineSkipTemplate():this.diffLineTemplate(e)}diffFileTemplate(e,o){return this.diffFileTemplateHandler?this.diffFileTemplateHandler(e,o):`<div class="diff-file">\n <div class="diff-file-title">${e}</div>\n <div class="diff-file-content">${o}</div>\n </div>`}async generateAssetFoldersDiff(){this.logger.info(a.colors.blue(`Comparing asset folders ${await this.oldAssetsPath} and ${await this.newAssetsPath}`));const e=await y.compare(await this.oldAssetsPath,await this.newAssetsPath,{compareContent:!0,skipSymlinks:!0,compareSize:!0,compareDate:!1,compareNameHandler:(e,o)=>(E.test(e)&&(e=e.replace(E,"$1$3")),E.test(o)&&(o=o.replace(E,"$1$3")),0===e.localeCompare(o)?0:e.localeCompare(o)>0?1:-1)});return e.diffSet?.filter(e=>"equal"!==e.state||e.name1!==e.name2)||[]}async generateAssetFilesDiff(e,o){const t=new x,n=t.diff_linesToChars_(e,o),i=t.diff_main(n.chars1,n.chars2,!1);t.diff_charsToLines_(i,n.lineArray);let r=0;return i.map(e=>{const[o,t]=e,n=t.endsWith("\n")?t.split("\n").length-1:t.split("\n").length,i=t.split("\n").map((e,t)=>({lineContent:e,lineNumber:r+t+1,lineType:o})).slice(0,n);return-1!==o&&(r+=n),i}).flat()}async generateFilesDiff(e){if("equal"===e.state){const o=this.pathToPosix(w.join(".",e.relativePath,e.name1??"")),t=this.pathToPosix(w.join(".",e.relativePath,e.name2??""));return this.diffFileTemplate(`<span class="renamed"\n >Renamed <span class="from">${o}</span> -> <span class="to">${t}</span></span\n >`,this.diffTableTemplate(this.diffLineMessageTemplate("No changes")))}const o=e.path1&&e.name1?w.join(e.path1,e.name1):null,t=e.path2&&e.name2?w.join(e.path2,e.name2):null,n=this.pathToPosix(w.join(".",e.relativePath,(e.name1||e.name2)??""));if("left"===e.state&&o)return this.diffFileTemplate(`<span class="removed">Removed ${n}</span>`,this.diffTableTemplate(this.diffLineMessageTemplate("File removed")));if("right"===e.state&&t)return this.diffFileTemplate(`<span class="added">Added ${n}</span>`,this.diffTableTemplate(this.diffLineMessageTemplate("File added")));if("distinct"===e.state&&o&&t){const i=this.pathToPosix(w.join(".",e.relativePath,e.name1??"")),r=this.pathToPosix(w.join(".",e.relativePath,e.name2??"")),s=e.name1!==e.name2?`<span class="renamed"\n >Renamed <span class="from">${i}</span> -> <span class="to">${r}</span></span\n >`:n;return this.diffFileTemplate(s,await p.isBinaryFile(o)||await p.isBinaryFile(t)?this.diffTableTemplate(this.diffLineMessageTemplate("Binary file")):this.getDiffTableHTML(await this.generateAssetFilesDiff(v.readFileSync(o,"utf-8"),v.readFileSync(t,"utf-8"))))}return""}async generateChangelog(){this.logger.info(a.colors.green("Generating changelog"));const e=await this.generateAssetFoldersDiff(),o=(await Promise.all(e.map(e=>this.generateFilesDiff(e)))).join("");this.logger.info(a.colors.green("Writing changelog file"));const t=this.changelogTemplate.split("%FILES%");t.splice(1,0,o);const n=t.join("");v.writeFileSync(w.join(this.destinationPath,this.changelogFilename),n),this.logger.info(a.colors.green(`Changelog file written to ${w.join(this.destinationPath,this.changelogFilename)}`))}}class C{sourceDir;outputDir;fontName;constructor(e){this.sourceDir=e.sourceDir,this.outputDir=e.outputDir,this.fontName=e.fontName}async generate(){await S({src:this.sourceDir,dist:this.outputDir,fontName:this.fontName,css:!0,typescript:!0,startUnicode:59905,svgicons2svgfont:{fontHeight:1024}})}}const j=i.cac("pp-dev");function A(e,o,t){const i=[...s.PP_DEV_CONFIG_NAMES,...s.PP_WATCH_CONFIG_NAMES,"package.json","next.config.js","next.config.mjs","next.config.ts","vite.config.js","vite.config.mjs","vite.config.ts",".env",".env.local",".env.development",".env.development.local"].map(o=>w.join(e,o)),r=n.watch(i,{ignored:e=>{const o=w.basename(e);return/(^|[\/\\])\../.test(e)&&!o.startsWith(".env")&&!o.startsWith(".pp-dev")&&!o.startsWith(".pp-watch")},persistent:!0,ignoreInitial:!0,followSymlinks:!1});let l=null;return r.on("change",n=>{t(a.colors.blue(`š§ Config file changed: ${w.relative(e,n)}`)),l&&clearTimeout(l),l=setTimeout(async()=>{try{t(a.colors.yellow("š Restarting dev server due to config change...")),await o()}catch(e){t(a.colors.red(`ā Failed to restart dev server: ${e?.message}. Stack: ${e?.stack}`))}},500)}),r.on("error",e=>{t(a.colors.red(`ā Config watcher error: ${e}`))}),{watcher:r,restartCallback:o,logger:t}}function _(e){e.watcher&&e.watcher.close()}function I(e){if(!e||"object"!=typeof e||!("message"in e))return!1;const o=String(e.message);return/Turbopack is not supported/i.test(o)||/native bindings are not available/i.test(o)||/Only WebAssembly \(WASM\) bindings were loaded/i.test(o)}let D=global.__pp_dev_profile_session,N=0;const R=e=>{if(D)return new Promise((o,t)=>{D.post("Profiler.stop",(n,{profile:i})=>{if(n)t(n);else{const t=w.resolve(`./pp-dev-profile-${N++}.cpuprofile`);v.writeFileSync(t,JSON.stringify(i)),e(a.colors.yellow(`CPU profile written to ${a.colors.white(a.colors.dim(t))}`)),D=void 0,o()}})})},q=e=>{for(const[o,t]of Object.entries(e))Array.isArray(t)&&(e[o]=t[t.length-1])};function M(e){const o={...e};return delete o["--"],delete o.c,delete o.config,delete o.base,delete o.l,delete o.logLevel,delete o.clearScreen,delete o.d,delete o.debug,delete o.f,delete o.filter,delete o.m,delete o.mode,o}j.option("-c, --config <file>","[string] use specified config file").option("--base <path>","[string] public base path (default: /)").option("-l, --logLevel <level>","[string] info | warn | error | silent").option("--clearScreen","[boolean] allow/disable clear screen when logging").option("-d, --debug [feat]","[string | boolean] show debug logs").option("-f, --filter <filter>","[string] filter debug logs").option("-m, --mode <mode>","[string] set env mode"),j.command("[root]","start dev server").alias("serve").alias("dev").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port").option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--cors","[boolean] enable CORS").option("--strictPort","[boolean] exit if specified port is already in use").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").action(async(e,o)=>{q(o);let n=null,i=null,l=!1;const c=e?w.resolve(process.cwd(),e):process.cwd(),d=a.createLogger(o.logLevel),p=async()=>{if(!l){l=!0;try{n&&(d.info(a.colors.yellow("š Stopping existing dev server...")),await n.close(),n=null);const{clearConfigCache:f}=await Promise.resolve().then(()=>require("./index-Bu8AM2lb.js")).then(e=>e.config);f();const{createServer:u}=await import("vite"),h=await r.loadConfigFromFile({mode:o.mode||"development",command:"serve"},o.config,e,o.logLevel);let g=await s.getViteConfig();const m=r.loadEnv(o.mode||"development",e??process.cwd(),"");if(m&&Object.keys(m).forEach(e=>{e.startsWith("MI_")&&(process.env[e]=m[e])}),h){const{plugins:e,...o}=h.config;g=r.mergeConfig(g,o)}if(n=await u(r.mergeConfig(g,{root:e,base:o.base,mode:o.mode,configFile:o.config,logLevel:o.logLevel,clearScreen:o.clearScreen,optimizeDeps:{force:o.force},server:M(o),customLogger:d},!0)),!n.config.base||"/"===n.config.base)throw new Error('base cannot be equal to "/" or empty string');if(!n.httpServer)throw new Error("HTTP server not available");await n.listen();const b=global.__pp_dev_start_time??!1,w=b?a.colors.dim(`ready in ${a.colors.reset(a.colors.bold(Math.ceil(t.performance.now()-b)))} ms`):"";d.info(`\n ${a.colors.green(`${a.colors.bold("PP-DEV")} v${s.VERSION}`)} ${w}\n`),n.printUrls(),function(e,o){if(!e.httpServer||!process.stdin.isTTY||process.env.CI)return;e._shortcutsOptions=o;const t=a.createLogger();o.print&&t.info(a.colors.dim(a.colors.green(" ā"))+a.colors.dim(" press ")+a.colors.bold("h")+a.colors.dim(" to show help"));const n=(o.customShortcuts??[]).filter($).concat(k);let i=!1;const r=async o=>{if(""===o||""===o)return void await e.close().finally(()=>process.exit(1));if(i)return;"h"===o&&t.info(["",a.colors.bold(" Shortcuts"),...n.map(e=>a.colors.dim(" press ")+a.colors.bold(e.key)+a.colors.dim(` to ${e.description}`))].join("\n"));const r=n.find(e=>e.key===o);r&&(i=!0,await r.action(e),i=!1)};process.stdin.setRawMode(!0),process.stdin.on("data",r).setEncoding("utf8").resume(),e.httpServer.on("close",()=>{process.stdin.off("data",r).pause()})}(n,{print:!0,customShortcuts:[...D?[{key:"p",description:"start/stop the profiler",async action(e){if(D)await R(d.info);else{const e=await import("node:inspector").then(e=>e.default);await new Promise(o=>{D=new e.Session,D.connect(),D.post("Profiler.enable",()=>{D?.post("Profiler.start",()=>{d.info("Profiler started"),o()})})})}}}]:[],{key:"l",description:"proxy re-login",action(e){e.ws.send({type:"custom",event:"redirect",data:{url:`/auth/index/logout?proxyRedirect=${encodeURIComponent("/")}`}})}}]}),i||(i=A(c,p,d.info),d.info(a.colors.blue("š§ Config file watcher started"))),l=!1}catch(e){l=!1,d.error(a.colors.red(`error when starting dev server:\n${e.stack}`),{error:e}),R(d.info),process.exit(1)}}},f=async e=>{d.info(a.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));try{i&&(_(i),i=null),n&&(await n.close(),n=null),R(d.info),d.info(a.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){d.error(a.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};process.on("SIGINT",()=>f("SIGINT")),process.on("SIGTERM",()=>f("SIGTERM")),process.on("uncaughtException",e=>{d.error(a.colors.red(`ā Uncaught Exception: ${e}`)),f("uncaughtException")}),process.on("unhandledRejection",(e,o)=>{d.error(a.colors.red(`ā Unhandled Rejection at: ${o}, reason: ${e}`)),f("unhandledRejection")}),await p()}),j.command("next [root]","start Next.js development server with pp-dev integration").alias("next-serve").alias("next-dev").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port",{default:3e3}).option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--cors","[boolean] enable CORS").option("--strictPort","[boolean] exit if specified port is already in use").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").option("--webpack","[boolean] use Webpack for Next dev (use when Turbopack/native SWC is unavailable)").option("--turbopack","[boolean] use Turbopack for Next dev when native bindings work").action(async(e,o)=>{q(o);let t=null,n=null,i=null,c=!1;const d=a.createLogger(),p=async()=>{if(!c){c=!0;try{const{next:u,constants:h}=await s.safeNextImport(),{PHASE_DEVELOPMENT_SERVER:g}=h;n&&(d.info(a.colors.yellow("š Stopping existing Next.js server...")),await new Promise(e=>{n.close(()=>{n=null,e()})})),t&&"function"==typeof t.close&&(await t.close(),t=null);const{clearConfigCache:m}=await Promise.resolve().then(()=>require("./index-Bu8AM2lb.js")).then(e=>e.config);m();const{join:b,basename:w}=await import("path"),{createServer:v}=await import("http"),y=await import("next/dist/server/config.js"),x=y.default.default||y["module.exports"].default||y.default,P=M(o),T=r.loadEnv(o.mode||"development",e??process.cwd(),"");T&&Object.keys(T).forEach(e=>{e.startsWith("MI_")&&(process.env[e]=T[e])});const L=e?b(process.cwd(),e):process.cwd();d.info(L);const S=await x(g,L);let $=S?.ppDev||{};if(0===Object.keys($).length)try{const{getConfig:e}=await Promise.resolve().then(()=>require("./index-Bu8AM2lb.js")).then(e=>e.config),o=await e();Object.keys(o).length>0?($=o,d.info(a.colors.blue("š§ Loaded pp-dev config from standalone config file"))):d.info(a.colors.yellow("ā ļø No pp-dev config found in Next.js config or standalone file, using defaults"))}catch(e){d.info(a.colors.yellow("ā ļø Failed to load standalone pp-dev config, using defaults")),console.debug("Error loading standalone config:",e)}else d.info(a.colors.blue("š§ Loaded pp-dev config from Next.js config"));const{backendBaseURL:k=process.env.MI_BACKEND_URL||"http://localhost:8080",appId:E,portalPageId:F,templateLess:C=!0,v7Features:j=!0,disableSSLValidation:D=!1,enableProxyCache:N=!0,proxyCacheTTL:R=6e5,personalAccessToken:q=process.env.MI_ACCESS_TOKEN,miHudLess:z=!1}=$,H=E??F??(process.env.MI_APP_ID&&parseInt(process.env.MI_APP_ID,10)||void 0)??(process.env.MI_PORTAL_PAGE_ID&&parseInt(process.env.MI_PORTAL_PAGE_ID,10)||void 0)??1;let G=null;if(!G)try{const{getPkg:e}=await Promise.resolve().then(()=>require("./index-Bu8AM2lb.js")).then(e=>e.config),o=e();G=o.name}catch(e){G=w(L)}const O="/p",W="/pl",U=S?.basePath;let V="";U?V=U:(V=C?O:j?W:"/pt",V+=`/${G}`);const B=function(e){const o="1"===process.env.PP_DEV_NEXT_WEBPACK||"true"===process.env.PP_DEV_NEXT_WEBPACK;if(o&&(e.webpack||e.turbopack))throw new Error("Do not combine PP_DEV_NEXT_WEBPACK with --webpack or --turbopack");if(o)return{webpack:!0};if(e.webpack&&e.turbopack)throw new Error("Use only one of --webpack or --turbopack");return e.webpack?{webpack:!0}:e.turbopack?{turbopack:!0}:{}}(o),K=async e=>{delete process.env.TURBOPACK,t&&"function"==typeof t.close&&(await t.close(),t=null);const o={dev:!0,customServer:!0,hostname:P.host||"localhost",port:P.port,dir:L,conf:{...S,basePath:V,assetPrefix:`${C?O:"/pt"}/${G}`}};e.webpack?o.webpack=!0:e.turbopack&&(o.turbopack=!0),t=u(o),await t.prepare()};if(B.webpack)await K({webpack:!0});else if(B.turbopack)try{await K({turbopack:!0})}catch(e){if(!I(e))throw e;d.warn(a.colors.yellow("ā Turbopack is unavailable (native bindings). Falling back to Webpack.")),await K({webpack:!0})}else try{await K({})}catch(e){if(!I(e))throw e;d.warn(a.colors.yellow("ā Turbopack cannot run (native Next.js bindings unavailable). Falling back to Webpack.")),await K({webpack:!0})}if(!t)throw new Error("Next.js app failed to initialize");if(V.endsWith("/")||(V+="/"),"/"===V)throw new Error('basePath cannot be equal to "/" or equal to empty string');d.info(a.colors.green("ā
Next.js app prepared successfully")),d.info(a.colors.blue(`š§ pp-dev plugin configured for template: ${G}`)),d.info(a.colors.blue(`š§ Base path configured: ${V}`)),k&&(d.info(a.colors.blue(`š Backend URL: ${k}`)),d.info(a.colors.blue(`š Custom App ID: ${H}`)));const Z=t.getRequestHandler(),X="number"==typeof P.port?P.port:3e3,Y="string"==typeof P.host?P.host||"0.0.0.0":"localhost",J=new Set;n=v(async(e,o)=>{try{const t=e.url||"/",n=t.split("?")[0];let i=l.parse(t,!0);if(ee.length>0){if(n.startsWith("/_next/")||"/favicon.ico"===n||n.startsWith("/__nextjs_")){if(oe.length>0){let c=0;const d=()=>{if(c>=oe.length)return void r();const t=oe[c];c++,t(e,o,d)};return void d()}return void r()}let s=0;const a=()=>{if(s>=ee.length)return void r();const t=ee[s];s++,t(e,o,a)};return void a()}async function r(){if(n.startsWith(V))i=l.parse(t,!0);else{if(n===V.replace(/\/$/,"")){const e=t.replace(n,V);return o.writeHead(302,{Location:e}),void o.end()}if(n.startsWith("/_next/")||"/favicon.ico"===n||n.startsWith("/__nextjs_"));else if("/"===n)return o.writeHead(302,{Location:V}),void o.end()}await Z(e,o,i)}r()}catch(p){console.error("[DEBUG] Error:",p),o.statusCode=500,o.end("Internal Server Error")}});let Q=null,ee=[],oe=[];if(k){const e=new URL(k).host,o={headers:{host:e,referer:k,origin:k.replace(/^(https?:\/\/)([^/]+)(\/.*)?$/i,"$1$2")},portalPageId:H,appId:H,templateLess:C,disableSSLValidation:D,v7Features:j,personalAccessToken:q??process.env.MI_ACCESS_TOKEN};Q=new a.MiAPI(k,o);const t=a.initPPRedirect(V,G??void 0),n=(e,o,n)=>{t(e,o,n)};if(oe.push(n),ee.push(n),N){let e=+R;(!e||Number.isNaN(e)||e<0)&&(e=6e5);const o={devServer:{middlewares:{use:e=>e},config:{logger:console}},ttl:e},t=a.initProxyCache(o),n=(e,o,n)=>{t(e,o,n)};ee.push(n),d.info(a.colors.blue(`š§ Proxy cache middleware added with TTL: ${e}ms`))}const i=V.endsWith("/")?V.substring(0,V.length-1):V,r={middlewares:{use:e=>e},config:{logger:console}},s=a.initProxy({devServer:r,baseURL:k,proxyIgnore:["/@vite","/@metricinsights","/@",i,"/_next","/favicon.ico","/__nextjs_","/installHook.js.map"],disableSSLValidation:D,miAPI:Q}),l=(e,o,t)=>{s(e,o,t)};ee.push(l);const c=new RegExp(`^((${f=V,f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})|/)$`),p=a.initLoadPPData(c,Q,Object.assign({base:V},o)),u=(e,o,t)=>{p(e,o,t)};ee.push(u);const h=a.internalServer,g=(e,o,t)=>{if(e.url?.startsWith("/@api/")){return void h(e,o,()=>{})}t()};oe.push(g),ee.push(g);const m=a.initRewriteResponse(e=>{const o=e.split("?")[0];return o.startsWith(V)&&!o.includes("/_next/")},(o,t)=>Buffer.from(a.urlReplacer(e,t.headers.host??"",Q.buildPage(o,z)))),b=(e,o,t)=>{m(e,o,t)};ee.push(b),d.info(a.colors.blue(`š§ ${ee.length} pp-dev middlewares initialized`)),d.info(a.colors.blue(`š§ ${oe.length} essential middlewares for internal routes`)),d.info(a.colors.blue(`š§ MiAPI initialized for backend: ${k}`)),d.info(a.colors.blue(`š§ Custom App ID: ${H}`))}n.listen(X,Y,()=>{d.info(a.colors.green(`ā
pp-dev Next.js server running at http://${Y}:${X}`)),d.info(a.colors.blue(`š± Next.js app accessible at http://${Y}:${X}${V}`)),d.info(a.colors.blue("š§ Base path handling active")),i||(i=A(L,p,d.info),d.info(a.colors.blue("š§ Config file watcher started"))),n.on("connection",e=>{J.add(e),e.on("close",()=>J.delete(e))});const e=async e=>{d.info(a.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));const o=setTimeout(()=>{d.info(a.colors.yellow("ā° Shutdown timeout reached, forcing exit")),process.exit(0)},5e3);try{i&&(_(i),i=null);for(const e of Array.from(J))e.destroy();J.clear(),await new Promise(e=>{n.close(()=>{d.info(a.colors.yellow("š HTTP server closed")),e()})}),t&&"function"==typeof t.close&&(await t.close(),d.info(a.colors.yellow("š Next.js app closed"))),clearTimeout(o),d.info(a.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){clearTimeout(o),d.error(a.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};let o=process;if("function"!=typeof process.on){const e=globalThis.process||global.process;e&&"function"==typeof e.on&&(o=e,d.info(a.colors.green("ā
Using global process object for event handlers")))}if("function"==typeof o.on)try{o.on("SIGINT",()=>e("SIGINT")),o.on("SIGTERM",()=>e("SIGTERM")),o.on("uncaughtException",o=>{d.error(a.colors.red(`ā Uncaught Exception: ${o}`)),e("uncaughtException")}),o.on("unhandledRejection",(o,t)=>{d.error(a.colors.red(`ā Unhandled Rejection at: ${t}, reason: ${o}`)),e("unhandledRejection")}),d.info(a.colors.green("ā
Process event handlers registered successfully"))}catch(e){d.warn(a.colors.yellow(`ā ļø Failed to register process event handlers: ${e}`))}else d.warn(a.colors.yellow("ā ļø process.on is not available, graceful shutdown handlers will not be registered")),d.info(a.colors.blue("š” This might be due to bundling or environment constraints"))}),c=!1}catch(e){c=!1,d.error(a.colors.red(`ā Failed to start Next.js server: ${e?.message}. Stack: ${e?.stack}`)),e instanceof Error&&e.message.includes("Next.js is required")&&(d.error(a.colors.red("ā Next.js Peer Dependency Error:")),d.error(a.colors.red(e.message)),d.error(a.colors.yellow("\nš” To fix this issue:")),d.error(a.colors.blue(" 1. Install Next.js in your project:")),d.error(a.colors.white(" npm install next@^16")),d.error(a.colors.blue(" 2. Or use yarn:")),d.error(a.colors.white(" yarn add next@^16")),d.error(a.colors.blue(" 3. Or use pnpm:")),d.error(a.colors.white(" pnpm add next@^16")),d.error(a.colors.yellow("\nš For more information, see:")),d.error(a.colors.blue(" https://nextjs.org/docs/getting-started"))),process.exit(1)}var f}},f=async e=>{d.info(a.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));try{i&&(_(i),i=null),n&&await new Promise(e=>{n.close(()=>{n=null,e()})}),t&&"function"==typeof t.close&&(await t.close(),t=null),d.info(a.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){d.error(a.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};process.on("SIGINT",()=>f("SIGINT")),process.on("SIGTERM",()=>f("SIGTERM")),process.on("uncaughtException",e=>{d.error(a.colors.red(`ā Uncaught Exception: ${e}`)),f("uncaughtException")}),process.on("unhandledRejection",(e,o)=>{d.error(a.colors.red(`ā Unhandled Rejection at: ${o}, reason: ${e}`)),f("unhandledRejection")}),await p()}),j.command("build [root]","build for production").option("--target <target>","[string] transpile target (default: 'modules')").option("--outDir <dir>","[string] output directory (default: dist)").option("--assetsDir <dir>","[string] directory under outDir to place assets in (default: assets)").option("--assetsInlineLimit <number>","[number] static asset base64 inline threshold in bytes (default: 4096)").option("--ssr [entry]","[string] build specified entry for server-side rendering").option("--sourcemap [output]",'[boolean | "inline" | "hidden"] output source maps for build (default: false)').option("--minify [minifier]",'[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)').option("--manifest [name]","[boolean | string] emit build manifest json").option("--ssrManifest [name]","[boolean | string] emit ssr manifest json").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle (experimental)").option("--emptyOutDir","[boolean] force empty outDir when it's outside of root").option("-w, --watch","[boolean] rebuilds when modules have changed on disk").option("--changelog [assetsFile]","[boolean | string] generate changelog between assetsFile and current build (default: false)").action(async(e,o)=>{q(o);const t=M(o);try{const n=await r.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let i=await s.getViteConfig();if(n){const{plugins:e,...o}=n.config;i=r.mergeConfig(i,o)}const l=r.mergeConfig(i,{root:e,base:o.base,mode:o.mode,configFile:o.config,logLevel:o.logLevel,clearScreen:o.clearScreen,optimizeDeps:{force:o.force},build:t},!0);if(await r.build(l),t.changelog){const n=e||process.cwd(),i=l.build?.outDir||"dist";let r="";if("string"==typeof t.changelog)r=w.resolve(n,t.changelog);else{const e=w.resolve(n,l.ppDevConfig?.syncBackupsDir||"backups");if(!v.existsSync(e))return void a.createLogger(o.logLevel).warn(a.colors.yellow("backups directory not found, skipping changelog generation"));const t=v.readdirSync(e,{withFileTypes:!0});if(!t.length)return void a.createLogger(o.logLevel).warn(a.colors.yellow("no backups found, skipping changelog generation"));const i=t.filter(e=>e.isFile()&&e.name.endsWith(".zip")).reduce((o,t)=>v.statSync(w.resolve(e,o.name)).mtimeMs>v.statSync(w.resolve(e,t.name)).mtimeMs?o:t,t[0]).name;r=w.resolve(e,i)}const s=w.resolve(n,i);let c="dist-zip";l.ppDevConfig&&(!1===l.ppDevConfig.distZip?c=l.build?.outDir||"dist":"object"==typeof l.ppDevConfig.distZip&&"string"==typeof l.ppDevConfig.distZip.outDir&&(c=l.ppDevConfig.distZip.outDir));const d=new F({oldAssetsPath:r,newAssetsPath:s,destinationPath:w.resolve(n,c)});await d.generateChangelog()}}catch(e){a.createLogger(o.logLevel).error(a.colors.red(`error during build:\n${e.stack}`),{error:e}),process.exit(1)}finally{R(e=>a.createLogger(o.logLevel).info(e))}}),j.command("changelog [oldAssetPath] [newAssetPath]","generate changelog between two assets files/folders").option("--oldAssetsPath <oldAssetsPath>","[string] path to the old assets zip file or folder").option("--newAssetsPath <newAssetsPath>","[string] path to the new assets zip file or folder").option("--destination <destination>","[string] destination folder for the changelog (default: .)").option("--filename <filename>","[string] filename for the changelog (default: CHANGELOG.html)").action(async(e,o,t)=>{q(t);const{oldAssetsPath:n=e,newAssetsPath:i=o,destination:r=".",filename:s="CHANGELOG.html",logLevel:l}=t,c=process.cwd();n&&i||(a.createLogger(l).error(a.colors.red("error during changelog generation: oldAssetPath and newAssetPath are required")),process.exit(1));const d=w.resolve(c,n),p=w.resolve(c,i),f=w.resolve(c,r),u=new F({oldAssetsPath:d,newAssetsPath:p,destinationPath:f,changelogFilename:s});await u.generateChangelog()}),j.command("generate-icon-font [source] [destination]","generate icon font from SVG files").option("--source <source>","[string] path to the source directory with SVG files").option("--destination <destination>","[string] path to the destination directory to save the generated font files").option("--font-name, -n <fontName>","[string] name of the font to generate (default: 'icon-font')").action(async(e,o,t)=>{q(t);const{source:n=e,destination:i=o,fontName:r="icon-font"}=t,s=process.cwd(),l=w.resolve(s,n),c=w.resolve(s,i),d=new C({sourceDir:l,outputDir:c,fontName:r}),p=a.createLogger(t.logLevel);p.info(`Generating icon font from SVG files in ${a.colors.dim(l)}`),await d.generate(),p.info(`Icon font generated and saved to ${a.colors.dim(c)}`)}),j.command("optimize [root]","pre-bundle dependencies").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").action(async(e,o)=>{q(o);try{const t=await r.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let n=await s.getViteConfig();if(t){const{plugins:e,...o}=t.config;n=r.mergeConfig(n,o)}const i=await r.resolveConfig(r.mergeConfig(n,{root:e,base:o.base,configFile:o.config,logLevel:o.logLevel,mode:o.mode}),"serve");await r.optimizeDeps(i,o.force,!0)}catch(e){a.createLogger(o.logLevel).error(a.colors.red(`error when optimizing deps:\n${e.stack}`),{error:e}),process.exit(1)}}),j.command("preview [root]","locally preview production build").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port").option("--strictPort","[boolean] exit if specified port is already in use").option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--outDir <dir>","[string] output directory (default: dist)").action(async(e,o)=>{q(o);try{const t=await r.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let n=await s.getViteConfig();if(t){const{plugins:e,...o}=t.config;n=r.mergeConfig(n,o)}(await r.preview(r.mergeConfig(n,{root:e,base:o.base,configFile:o.config,logLevel:o.logLevel,mode:o.mode,build:{outDir:o.outDir},preview:{port:o.port,strictPort:o.strictPort,host:o.host,https:o.https,open:o.open}}))).printUrls()}catch(e){a.createLogger(o.logLevel).error(a.colors.red(`error when starting preview server:\n${e.stack}`),{error:e}),process.exit(1)}finally{R(e=>a.createLogger(o.logLevel).info(e))}}),j.help(),j.version(s.VERSION),j.parse(),exports.stopProfiler=R;
|
|
1
|
+
"use strict";const e=require("path"),o=require("fs"),t=require("node:events"),n=require("node:perf_hooks"),i=require("chokidar"),r=require("cac"),s=require("vite"),a=require("./index-B1GblhLQ.js"),l=require("./plugin-DY9gjLm8.js"),c=require("url"),d=require("dir-compare"),p=require("diff-match-patch"),f=require("isbinaryfile"),u=require("os"),h=require("crypto"),g=require("extract-zip"),m=require("svgtofont");require("child_process"),require("ejs"),require("http-proxy-middleware"),require("picocolors"),require("axios"),require("node:http"),require("node:https"),require("jsdom"),require("process"),require("console"),require("memory-cache"),require("zlib"),require("express");const b=e=>e&&"object"==typeof e&&"default"in e?e.default:e;function w(e){if(e&&"object"==typeof e&&"default"in e)return e;const o=Object.create(null);if(e)for(const t in e)o[t]=e[t];return o.default=e,Object.freeze(o)}const v=w(e),y=w(o),x=w(d),P=b(p),T=w(u),L=w(h),S=b(g),$=b(m);function k(e){return null!=e&&!1!==e}let E=null;const F=[{key:"r",description:"restart the server",async action(e){await e.restart()}},{key:"u",description:"show server url",action(e){e.config.logger.info(""),e.printUrls()}},{key:"o",description:"open in browser",action(e){e.openBrowser()}},{key:"c",description:"clear console",action(e){e.config.logger.clearScreen("error")}},{key:"q",description:"quit",async action(e){await e.close().finally(()=>process.exit())}},{key:"C",description:"clear proxy cache",action(e){e.cache&&(e.cache.clear(),e.config.logger.info("Proxy cache cleared"))}}];const C=/(.+)(-[a-f0-9]{6,20})(\.[a-z0-9]+)$/i;class j{oldAssetsPath;newAssetsPath;destinationPath;changelogFilename;changelogTemplate='<!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="UTF-8" />\n <title>Changelog Diff</title>\n <style>\n tr,\n td {\n padding: 0;\n }\n .diff-file {\n margin-top: 20px;\n border: 1px solid #e1e4e8;\n border-radius: 6px;\n }\n .diff-file-title {\n padding: 10px 20px;\n background-color: #f6f8fa;\n border-bottom: 1px solid #e1e4e8;\n border-radius: 6px 6px 0 0;\n font-weight: bold;\n }\n .diff-file-title .renamed {\n font-weight: normal;\n }\n .diff-file-title .renamed .from {\n color: #cb2431;\n }\n .diff-file-title .renamed .to {\n color: #22863a;\n }\n .diff-file-title .added {\n color: #22863a;\n }\n .diff-file-title .deleted {\n color: #cb2431;\n }\n .diff-file-content {\n }\n .diff-table {\n tab-size: 8;\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n }\n .blob-num {\n position: relative;\n color: #1f2328;\n width: 1%;\n min-width: 50px;\n padding: 0 10px;\n font-family:\n ui-monospace,\n SFMono-Regular,\n SF Mono,\n Menlo,\n Consolas,\n Liberation Mono,\n monospace;\n font-size: 12px;\n line-height: 20px;\n text-align: right;\n white-space: nowrap;\n vertical-align: top;\n cursor: pointer;\n -webkit-user-select: none;\n user-select: none;\n }\n .blob-num.addition {\n background-color: #ccffd8;\n border-color: #1f883e;\n }\n .blob-num.deletion {\n background-color: #ffd7d5;\n border-color: #cf222e;\n }\n .blob-num::before {\n content: attr(data-line-number);\n }\n .blob-code {\n position: relative;\n padding: 0 10px 0 22px;\n vertical-align: top;\n color: #1f2329;\n }\n .blob-code.code-addition {\n background-color: #e6ffec;\n }\n .blob-code.code-deletion {\n background-color: #ffebe9;\n }\n .blob-code.skip,\n .blob-code.message {\n text-align: center;\n }\n .blob-code.skip .blob-code-inner,\n .blob-code.message .blob-code-inner {\n font-weight: bold;\n color: #6a737d;\n padding: 10px 0;\n }\n .blob-code-inner {\n display: table-cell;\n overflow: visible;\n font-family:\n ui-monospace,\n SFMono-Regular,\n SF Mono,\n Menlo,\n Consolas,\n Liberation Mono,\n monospace;\n font-size: 12px;\n word-wrap: anywhere;\n white-space: pre-wrap;\n }\n .blob-code-inner::before {\n content: attr(data-code-prefix);\n position: absolute;\n top: 1px;\n left: 8px;\n padding-right: 8px;\n }\n </style>\n </head>\n <body>\n <h1>Changelog Diff</h1>\n\n %FILES%\n </body>\n </html>';diffFileTemplateHandler;diffLineTemplateHandler;contextLines=3;logger;constructor(e){const{oldAssetsPath:o,newAssetsPath:t,destinationPath:n,changelogTemplate:i,diffFileTemplateHandler:r,diffLineTemplateHandler:s,changelogFilename:a,contextLines:c}=e;if(this.logger=l.createLogger(),!o||!t||!n)throw new Error("Previous assets path, current assets path and destination path are required");if(o===t)throw new Error("Previous and current assets paths must be different");if(!this.isExists(o))throw new Error(`Previous assets path ${o} does not exist`);if(!this.isExists(t))throw new Error(`Current assets path ${t} does not exist`);if(this.isZipFile(o)){const e=v.resolve(T.tmpdir(),L.createHash("md5").update(o).digest("hex"));this.oldAssetsPath=this.unzipFile(o,e).then(()=>this.normalizeAssetFolderPath(e)).then(e=>{if(this.isEmptyFolder(e))throw new Error(`Previous assets path ${e} is empty`);return e})}else{if(!this.isFolder(o))throw new Error(`Invalid previous assets path ${o}. It must be a folder or a zip file`);{const e=this.normalizeAssetFolderPath(o);if(this.isEmptyFolder(e))throw new Error(`Previous assets path ${e} is empty`);this.oldAssetsPath=Promise.resolve(e)}}if(this.isZipFile(t)){const e=v.resolve(T.tmpdir(),L.createHash("md5").update(t).digest("hex"));this.newAssetsPath=this.unzipFile(t,e).then(()=>this.normalizeAssetFolderPath(e)).then(e=>{if(this.isEmptyFolder(e))throw new Error(`Current assets path ${e} is empty`);return e})}else{if(!this.isFolder(t))throw new Error(`Invalid current assets path ${t}. It must be a folder or a zip file`);{const e=this.normalizeAssetFolderPath(t);if(this.isEmptyFolder(e))throw new Error(`Current assets path ${t} is empty`);this.newAssetsPath=Promise.resolve(e)}}this.destinationPath=n,this.mkdirpSync(this.destinationPath),this.changelogFilename=a||"CHANGELOG.html",i&&(this.templateIsValid(i)?this.changelogTemplate=i:this.logger.warn(l.colors.yellow("Invalid changelog template, using default"))),"function"==typeof r&&(this.diffFileTemplateHandler=r),"function"==typeof s&&(this.diffLineTemplateHandler=s),c&&(this.contextLines=c)}templateIsValid(e){return e.includes("%FILES%")}isExists(e){return y.existsSync(e)}isZipFile(e){return e.endsWith(".zip")}isFolder(e){return y.lstatSync(e).isDirectory()}isEmptyFolder(e){return 0===y.readdirSync(e,{withFileTypes:!0}).length}mkdirpSync(e){y.existsSync(e)||y.mkdirSync(e,{recursive:!0})}async unzipFile(e,o){return y.rmSync(o,{force:!0,recursive:!0}),S(e,{dir:o})}normalizeAssetFolderPath(e){const o=y.readdirSync(e);return 1===o.length&&y.lstatSync(v.join(e,o[0])).isDirectory()?this.normalizeAssetFolderPath(v.join(e,o[0])):e}pathToPosix(e){return e.replace(/\\/g,"/")}diffTableTemplate(e){return`<table class="diff-table">\n <tbody>\n ${e}\n </tbody>\n </table>`}getDiffTableHTML(e){const o=e.filter((e,o,t)=>0!==e.lineType||(o>=0&&o<this.contextLines||o>t.length-(this.contextLines+1)&&o<=t.length-1||t.slice(o-this.contextLines,o+this.contextLines+1).some(e=>0!==e.lineType))).map((e,o,t)=>{if(o>0){const n=t[o-1];if(e.lineNumber-n.lineNumber>1)return[{lineNumber:-1,lineContent:"",lineType:0},e]}return[e]}).flat().map(e=>this.diffLineHTML(e)).join("");return this.diffTableTemplate(o)}diffLineMessageTemplate(e){return`<tr>\n <td class="blob-num"></td>\n <td class="blob-num"></td>\n <td class="blob-code message">\n <span class="blob-code-inner">${e}</span>\n </td>\n </tr>`}diffLineSkipTemplate(){return'<tr>\n <td class="blob-num"></td>\n <td class="blob-num"></td>\n <td class="blob-code skip">\n <span class="blob-code-inner">Skip</span>\n </td>\n </tr>'}diffLineTemplate(e){const{lineNumber:o,lineContent:t,lineType:n}=e,i=1===n?"addition":-1===n?"deletion":"";return`<tr>\n <td\n class="blob-num ${i}${"addition"===i?" empty":""}"\n ${"addition"!==i?` data-line-number="${o}"`:""}\n ></td>\n <td\n class="blob-num ${i}${"deletion"===i?" empty":""}"\n ${"deletion"!==i?` data-line-number="${o}"`:""}\n ></td>\n <td class="blob-code ${1===n?"code-addition":-1===n?"code-deletion":""}">\n <span class="blob-code-inner" data-code-prefix="${1===n?"+":-1===n?"-":" "}">${r=t??"",r.replace(/[\u00A0-\u9999<>&]/g,e=>"&#"+e.charCodeAt(0)+";")}</span>\n </td>\n </tr>`;var r}diffLineHTML(e){if(this.diffLineTemplateHandler)return this.diffLineTemplateHandler(e);const{lineNumber:o}=e;return-1===o?this.diffLineSkipTemplate():this.diffLineTemplate(e)}diffFileTemplate(e,o){return this.diffFileTemplateHandler?this.diffFileTemplateHandler(e,o):`<div class="diff-file">\n <div class="diff-file-title">${e}</div>\n <div class="diff-file-content">${o}</div>\n </div>`}async generateAssetFoldersDiff(){this.logger.info(l.colors.blue(`Comparing asset folders ${await this.oldAssetsPath} and ${await this.newAssetsPath}`));const e=await x.compare(await this.oldAssetsPath,await this.newAssetsPath,{compareContent:!0,skipSymlinks:!0,compareSize:!0,compareDate:!1,compareNameHandler:(e,o)=>(C.test(e)&&(e=e.replace(C,"$1$3")),C.test(o)&&(o=o.replace(C,"$1$3")),0===e.localeCompare(o)?0:e.localeCompare(o)>0?1:-1)});return e.diffSet?.filter(e=>"equal"!==e.state||e.name1!==e.name2)||[]}async generateAssetFilesDiff(e,o){const t=new P,n=t.diff_linesToChars_(e,o),i=t.diff_main(n.chars1,n.chars2,!1);t.diff_charsToLines_(i,n.lineArray);let r=0;return i.map(e=>{const[o,t]=e,n=t.endsWith("\n")?t.split("\n").length-1:t.split("\n").length,i=t.split("\n").map((e,t)=>({lineContent:e,lineNumber:r+t+1,lineType:o})).slice(0,n);return-1!==o&&(r+=n),i}).flat()}async generateFilesDiff(e){if("equal"===e.state){const o=this.pathToPosix(v.join(".",e.relativePath,e.name1??"")),t=this.pathToPosix(v.join(".",e.relativePath,e.name2??""));return this.diffFileTemplate(`<span class="renamed"\n >Renamed <span class="from">${o}</span> -> <span class="to">${t}</span></span\n >`,this.diffTableTemplate(this.diffLineMessageTemplate("No changes")))}const o=e.path1&&e.name1?v.join(e.path1,e.name1):null,t=e.path2&&e.name2?v.join(e.path2,e.name2):null,n=this.pathToPosix(v.join(".",e.relativePath,(e.name1||e.name2)??""));if("left"===e.state&&o)return this.diffFileTemplate(`<span class="removed">Removed ${n}</span>`,this.diffTableTemplate(this.diffLineMessageTemplate("File removed")));if("right"===e.state&&t)return this.diffFileTemplate(`<span class="added">Added ${n}</span>`,this.diffTableTemplate(this.diffLineMessageTemplate("File added")));if("distinct"===e.state&&o&&t){const i=this.pathToPosix(v.join(".",e.relativePath,e.name1??"")),r=this.pathToPosix(v.join(".",e.relativePath,e.name2??"")),s=e.name1!==e.name2?`<span class="renamed"\n >Renamed <span class="from">${i}</span> -> <span class="to">${r}</span></span\n >`:n;return this.diffFileTemplate(s,await f.isBinaryFile(o)||await f.isBinaryFile(t)?this.diffTableTemplate(this.diffLineMessageTemplate("Binary file")):this.getDiffTableHTML(await this.generateAssetFilesDiff(y.readFileSync(o,"utf-8"),y.readFileSync(t,"utf-8"))))}return""}async generateChangelog(){this.logger.info(l.colors.green("Generating changelog"));const e=await this.generateAssetFoldersDiff(),o=(await Promise.all(e.map(e=>this.generateFilesDiff(e)))).join("");this.logger.info(l.colors.green("Writing changelog file"));const t=this.changelogTemplate.split("%FILES%");t.splice(1,0,o);const n=t.join("");y.writeFileSync(v.join(this.destinationPath,this.changelogFilename),n),this.logger.info(l.colors.green(`Changelog file written to ${v.join(this.destinationPath,this.changelogFilename)}`))}}class A{sourceDir;outputDir;fontName;constructor(e){this.sourceDir=e.sourceDir,this.outputDir=e.outputDir,this.fontName=e.fontName}async generate(){await $({src:this.sourceDir,dist:this.outputDir,fontName:this.fontName,css:!0,typescript:!0,startUnicode:59905,svgicons2svgfont:{fontHeight:1024}})}}const I=r.cac("pp-dev");function _(e,o,t){const n=[...a.PP_DEV_CONFIG_NAMES,...a.PP_WATCH_CONFIG_NAMES,"package.json","next.config.js","next.config.mjs","next.config.ts","vite.config.js","vite.config.mjs","vite.config.ts",".env",".env.local",".env.development",".env.development.local"].map(o=>v.join(e,o)),r=i.watch(n,{ignored:e=>{const o=v.basename(e);return/(^|[\/\\])\../.test(e)&&!o.startsWith(".env")&&!o.startsWith(".pp-dev")&&!o.startsWith(".pp-watch")},persistent:!0,ignoreInitial:!0,followSymlinks:!1});let s=null;return r.on("change",n=>{t(l.colors.blue(`š§ Config file changed: ${v.relative(e,n)}`)),s&&clearTimeout(s),s=setTimeout(async()=>{try{t(l.colors.yellow("š Restarting dev server due to config change...")),await o()}catch(e){t(l.colors.red(`ā Failed to restart dev server: ${e?.message}. Stack: ${e?.stack}`))}},500)}),r.on("error",e=>{t(l.colors.red(`ā Config watcher error: ${e}`))}),{watcher:r,restartCallback:o,logger:t}}function D(e){e.watcher&&e.watcher.close()}function N(e){if(!e||"object"!=typeof e||!("message"in e))return!1;const o=String(e.message);return/Turbopack is not supported/i.test(o)||/native bindings are not available/i.test(o)||/Only WebAssembly \(WASM\) bindings were loaded/i.test(o)}let R=global.__pp_dev_profile_session,M=0;const q=e=>{if(R)return new Promise((o,t)=>{R.post("Profiler.stop",(n,{profile:i})=>{if(n)t(n);else{const t=v.resolve(`./pp-dev-profile-${M++}.cpuprofile`);y.writeFileSync(t,JSON.stringify(i)),e(l.colors.yellow(`CPU profile written to ${l.colors.white(l.colors.dim(t))}`)),R=void 0,o()}})})},z=e=>{for(const[o,t]of Object.entries(e))Array.isArray(t)&&(e[o]=t[t.length-1])};function H(e){const o={...e};return delete o["--"],delete o.c,delete o.config,delete o.base,delete o.l,delete o.logLevel,delete o.clearScreen,delete o.d,delete o.debug,delete o.f,delete o.filter,delete o.m,delete o.mode,o}I.option("-c, --config <file>","[string] use specified config file").option("--base <path>","[string] public base path (default: /)").option("-l, --logLevel <level>","[string] info | warn | error | silent").option("--clearScreen","[boolean] allow/disable clear screen when logging").option("-d, --debug [feat]","[string | boolean] show debug logs").option("-f, --filter <filter>","[string] filter debug logs").option("-m, --mode <mode>","[string] set env mode"),I.command("[root]","start dev server").alias("serve").alias("dev").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port").option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--cors","[boolean] enable CORS").option("--strictPort","[boolean] exit if specified port is already in use").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").action(async(e,o)=>{z(o);let t=null,i=null,r=!1;const c=e?v.resolve(process.cwd(),e):process.cwd(),d=l.createLogger(o.logLevel),p=async()=>{if(!r){r=!0;try{t&&(d.info(l.colors.yellow("š Stopping existing dev server...")),await t.close(),t=null);const{clearConfigCache:f}=await Promise.resolve().then(()=>require("./index-B1GblhLQ.js")).then(e=>e.config);f();const{createServer:u}=await import("vite"),h=await s.loadConfigFromFile({mode:o.mode||"development",command:"serve"},o.config,e,o.logLevel);let g=await a.getViteConfig();const m=s.loadEnv(o.mode||"development",e??process.cwd(),"");if(m&&Object.keys(m).forEach(e=>{e.startsWith("MI_")&&(process.env[e]=m[e])}),h){const{plugins:e,...o}=h.config;g=s.mergeConfig(g,o)}if(t=await u(s.mergeConfig(g,{root:e,base:o.base,mode:o.mode,configFile:o.config,logLevel:o.logLevel,clearScreen:o.clearScreen,optimizeDeps:{force:o.force},server:H(o),customLogger:d},!0)),!t.config.base||"/"===t.config.base)throw new Error('base cannot be equal to "/" or empty string');if(!t.httpServer)throw new Error("HTTP server not available");await t.listen();const b=global.__pp_dev_start_time??!1,w=b?l.colors.dim(`ready in ${l.colors.reset(l.colors.bold(Math.ceil(n.performance.now()-b)))} ms`):"";d.info(`\n ${l.colors.green(`${l.colors.bold("PP-DEV")} v${a.VERSION}`)} ${w}\n`),t.printUrls(),function(e,o){if(!e.httpServer||!process.stdin.isTTY||process.env.CI)return;e._shortcutsOptions=o;const t=l.createLogger();o.print&&t.info(l.colors.dim(l.colors.green(" ā"))+l.colors.dim(" press ")+l.colors.bold("h")+l.colors.dim(" to show help"));const n=(o.customShortcuts??[]).filter(k).concat(F);E?.(),E=null;let i=!1;const r=process.stdin.isPaused(),s=process.stdin,a=Boolean(s.isRaw),c=async o=>{if(""===o)return void process.kill(process.pid,"SIGINT");if(""===o)return void await e.close().finally(()=>process.exit(0));if(i)return;"h"===o&&t.info(["",l.colors.bold(" Shortcuts"),...n.map(e=>l.colors.dim(" press ")+l.colors.bold(e.key)+l.colors.dim(` to ${e.description}`))].join("\n"));const r=n.find(e=>e.key===o);r&&(i=!0,await r.action(e),i=!1)};process.stdin.setRawMode(!0),process.stdin.on("data",c).setEncoding("utf8").resume();const d=e.httpServer,p=()=>{E===p&&(d.removeListener("close",p),process.stdin.off("data",c),a||process.stdin.setRawMode(!1),r&&process.stdin.pause(),E=null)};E=p,d.on("close",p)}(t,{print:!0,customShortcuts:[...R?[{key:"p",description:"start/stop the profiler",async action(e){if(R)await q(d.info);else{const e=await import("node:inspector").then(e=>e.default);await new Promise(o=>{R=new e.Session,R.connect(),R.post("Profiler.enable",()=>{R?.post("Profiler.start",()=>{d.info("Profiler started"),o()})})})}}}]:[],{key:"l",description:"proxy re-login",action(e){e.ws.send({type:"custom",event:"redirect",data:{url:`/auth/index/logout?proxyRedirect=${encodeURIComponent("/")}`}})}}]}),i||(i=_(c,p,d.info),d.info(l.colors.blue("š§ Config file watcher started"))),r=!1}catch(e){r=!1,d.error(l.colors.red(`error when starting dev server:\n${e.stack}`),{error:e}),q(d.info),process.exit(1)}}},f=async e=>{d.info(l.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));try{i&&(D(i),i=null),t&&(await t.close(),t=null),q(d.info),d.info(l.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){d.error(l.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};process.on("SIGINT",()=>f("SIGINT")),process.on("SIGTERM",()=>f("SIGTERM")),process.on("uncaughtException",e=>{d.error(l.colors.red(`ā Uncaught Exception: ${e}`)),f("uncaughtException")}),process.on("unhandledRejection",(e,o)=>{d.error(l.colors.red(`ā Unhandled Rejection at: ${o}, reason: ${e}`)),f("unhandledRejection")}),await p()}),I.command("next [root]","start Next.js development server with pp-dev integration").alias("next-serve").alias("next-dev").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port",{default:3e3}).option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--cors","[boolean] enable CORS").option("--strictPort","[boolean] exit if specified port is already in use").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").option("--webpack","[boolean] use Webpack for Next dev (use when Turbopack/native SWC is unavailable)").option("--turbopack","[boolean] use Turbopack for Next dev when native bindings work").action(async(e,o)=>{z(o);let n=null,i=null,r=null,d=!1;const p=l.createLogger(),f=async()=>{if(!d){d=!0;try{const{next:h,constants:g}=await a.safeNextImport(),{PHASE_DEVELOPMENT_SERVER:m}=g;i&&(p.info(l.colors.yellow("š Stopping existing Next.js server...")),await new Promise(e=>{i.close(()=>{i=null,e()})})),n&&"function"==typeof n.close&&(await n.close(),n=null);const{clearConfigCache:b}=await Promise.resolve().then(()=>require("./index-B1GblhLQ.js")).then(e=>e.config);b();const{join:w,basename:v}=await import("path"),{createServer:y}=await import("http"),x=await import("next/dist/server/config.js"),P=x.default.default||x["module.exports"].default||x.default,T=H(o),L=s.loadEnv(o.mode||"development",e??process.cwd(),"");L&&Object.keys(L).forEach(e=>{e.startsWith("MI_")&&(process.env[e]=L[e])});const S=e?w(process.cwd(),e):process.cwd();p.info(S);const $=await P(m,S);let k=$?.ppDev||{};if(0===Object.keys(k).length)try{const{getConfig:e}=await Promise.resolve().then(()=>require("./index-B1GblhLQ.js")).then(e=>e.config),o=await e();Object.keys(o).length>0?(k=o,p.info(l.colors.blue("š§ Loaded pp-dev config from standalone config file"))):p.info(l.colors.yellow("ā ļø No pp-dev config found in Next.js config or standalone file, using defaults"))}catch(e){p.info(l.colors.yellow("ā ļø Failed to load standalone pp-dev config, using defaults")),console.debug("Error loading standalone config:",e)}else p.info(l.colors.blue("š§ Loaded pp-dev config from Next.js config"));const{backendBaseURL:E=process.env.MI_BACKEND_URL||"http://localhost:8080",appId:F,portalPageId:C,templateLess:j=!0,v7Features:A=!0,disableSSLValidation:I=!1,enableProxyCache:R=!0,proxyCacheTTL:M=6e5,personalAccessToken:q=process.env.MI_ACCESS_TOKEN,miHudLess:z=!1}=k,G=F??C??(process.env.MI_APP_ID&&parseInt(process.env.MI_APP_ID,10)||void 0)??(process.env.MI_PORTAL_PAGE_ID&&parseInt(process.env.MI_PORTAL_PAGE_ID,10)||void 0)??1;let O=null;if(!O)try{const{getPkg:e}=await Promise.resolve().then(()=>require("./index-B1GblhLQ.js")).then(e=>e.config),o=e();O=o.name}catch(e){O=v(S)}const W="/p",U="/pl",V=$?.basePath;let B="";V?B=V:(B=j?W:A?U:"/pt",B+=`/${O}`);const Z=function(e){const o="1"===process.env.PP_DEV_NEXT_WEBPACK||"true"===process.env.PP_DEV_NEXT_WEBPACK;if(o&&(e.webpack||e.turbopack))throw new Error("Do not combine PP_DEV_NEXT_WEBPACK with --webpack or --turbopack");if(o)return{webpack:!0};if(e.webpack&&e.turbopack)throw new Error("Use only one of --webpack or --turbopack");return e.webpack?{webpack:!0}:e.turbopack?{turbopack:!0}:{}}(o),K=async e=>{delete process.env.TURBOPACK,n&&"function"==typeof n.close&&(await n.close(),n=null);const o={dev:!0,customServer:!0,hostname:T.host||"localhost",port:T.port,dir:S,conf:{...$,basePath:B,assetPrefix:`${j?W:"/pt"}/${O}`}};e.webpack?o.webpack=!0:e.turbopack&&(o.turbopack=!0),n=h(o),await n.prepare()};if(Z.webpack)await K({webpack:!0});else if(Z.turbopack)try{await K({turbopack:!0})}catch(e){if(!N(e))throw e;p.warn(l.colors.yellow("ā Turbopack is unavailable (native bindings). Falling back to Webpack.")),await K({webpack:!0})}else try{await K({})}catch(e){if(!N(e))throw e;p.warn(l.colors.yellow("ā Turbopack cannot run (native Next.js bindings unavailable). Falling back to Webpack.")),await K({webpack:!0})}if(!n)throw new Error("Next.js app failed to initialize");if(B.endsWith("/")||(B+="/"),"/"===B)throw new Error('basePath cannot be equal to "/" or equal to empty string');p.info(l.colors.green("ā
Next.js app prepared successfully")),p.info(l.colors.blue(`š§ pp-dev plugin configured for template: ${O}`)),p.info(l.colors.blue(`š§ Base path configured: ${B}`)),E&&(p.info(l.colors.blue(`š Backend URL: ${E}`)),p.info(l.colors.blue(`š Custom App ID: ${G}`)));const X=n.getRequestHandler(),Y="number"==typeof T.port?T.port:3e3,J="string"==typeof T.host?T.host||"0.0.0.0":"localhost",Q=new Set;i=y(async(e,o)=>{try{const t=e.url||"/",n=t.split("?")[0];let i=c.parse(t,!0);if(oe.length>0){if(n.startsWith("/_next/")||"/favicon.ico"===n||n.startsWith("/__nextjs_")){if(te.length>0){let l=0;const d=()=>{if(l>=te.length)return void r();const t=te[l];l++,t(e,o,d)};return void d()}return void r()}let s=0;const a=()=>{if(s>=oe.length)return void r();const t=oe[s];s++,t(e,o,a)};return void a()}async function r(){if(n.startsWith(B))i=c.parse(t,!0);else{if(n===B.replace(/\/$/,"")){const e=t.replace(n,B);return o.writeHead(302,{Location:e}),void o.end()}if(n.startsWith("/_next/")||"/favicon.ico"===n||n.startsWith("/__nextjs_"));else if("/"===n)return o.writeHead(302,{Location:B}),void o.end()}await X(e,o,i)}r()}catch(p){console.error("[DEBUG] Error:",p),o.statusCode=500,o.end("Internal Server Error")}});let ee=null,oe=[],te=[];if(E){const e=new URL(E).host;E.startsWith("https://")&&(t.EventEmitter.defaultMaxListeners=Math.max(t.EventEmitter.defaultMaxListeners,20));const o={headers:{host:e,referer:E,origin:E.replace(/^(https?:\/\/)([^/]+)(\/.*)?$/i,"$1$2")},portalPageId:G,appId:G,templateLess:j,disableSSLValidation:I,v7Features:A,personalAccessToken:q??process.env.MI_ACCESS_TOKEN};ee=new l.MiAPI(E,o);const n=l.initPPRedirect(B,O??void 0),i=(e,o,t)=>{n(e,o,t)};if(te.push(i),oe.push(i),R){let e=+M;(!e||Number.isNaN(e)||e<0)&&(e=6e5);const o={devServer:{middlewares:{use:e=>e},config:{logger:console}},ttl:e},t=l.initProxyCache(o),n=(e,o,n)=>{t(e,o,n)};oe.push(n),p.info(l.colors.blue(`š§ Proxy cache middleware added with TTL: ${e}ms`))}const r=new RegExp(`^((${u=B,u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})|/)$`),s=l.initLoadPPData(r,ee,Object.assign({base:B},o)),a=(e,o,t)=>{s(e,o,t)};oe.push(a);const c=B.endsWith("/")?B.substring(0,B.length-1):B,d={middlewares:{use:e=>e},config:{logger:console}},f=l.initProxy({devServer:d,baseURL:E,proxyIgnore:["/@vite","/@metricinsights","/@",c,"/_next","/favicon.ico","/__nextjs_","/installHook.js.map"],disableSSLValidation:I,miAPI:ee,templateName:O??void 0}),h=(e,o,t)=>{f(e,o,t)};oe.push(h);const g=l.internalServer,m=(e,o,t)=>{if(e.url?.startsWith("/@api/")){return void g(e,o,()=>{})}t()};te.push(m),oe.push(m);const b=l.initRewriteResponse(e=>{const o=e.split("?")[0];return o.startsWith(B)&&!o.includes("/_next/")},(o,t)=>Buffer.from(l.urlReplacer(e,t.headers.host??"",ee.buildPage(o,z)))),w=(e,o,t)=>{b(e,o,t)};oe.push(w),p.info(l.colors.blue(`š§ ${oe.length} pp-dev middlewares initialized`)),p.info(l.colors.blue(`š§ ${te.length} essential middlewares for internal routes`)),p.info(l.colors.blue(`š§ MiAPI initialized for backend: ${E}`)),p.info(l.colors.blue(`š§ Custom App ID: ${G}`))}i.listen(Y,J,()=>{p.info(l.colors.green(`ā
pp-dev Next.js server running at http://${J}:${Y}`)),p.info(l.colors.blue(`š± Next.js app accessible at http://${J}:${Y}${B}`)),p.info(l.colors.blue("š§ Base path handling active")),r||(r=_(S,f,p.info),p.info(l.colors.blue("š§ Config file watcher started"))),i.on("connection",e=>{Q.add(e),e.on("close",()=>Q.delete(e))});const e=async e=>{p.info(l.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));const o=setTimeout(()=>{p.info(l.colors.yellow("ā° Shutdown timeout reached, forcing exit")),process.exit(0)},5e3);try{r&&(D(r),r=null);for(const e of Array.from(Q))e.destroy();Q.clear(),await new Promise(e=>{i.close(()=>{p.info(l.colors.yellow("š HTTP server closed")),e()})}),n&&"function"==typeof n.close&&(await n.close(),p.info(l.colors.yellow("š Next.js app closed"))),clearTimeout(o),p.info(l.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){clearTimeout(o),p.error(l.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};let o=process;if("function"!=typeof process.on){const e=globalThis.process||global.process;e&&"function"==typeof e.on&&(o=e,p.info(l.colors.green("ā
Using global process object for event handlers")))}if("function"==typeof o.on)try{o.on("SIGINT",()=>e("SIGINT")),o.on("SIGTERM",()=>e("SIGTERM")),o.on("uncaughtException",o=>{p.error(l.colors.red(`ā Uncaught Exception: ${o}`)),e("uncaughtException")}),o.on("unhandledRejection",(o,t)=>{p.error(l.colors.red(`ā Unhandled Rejection at: ${t}, reason: ${o}`)),e("unhandledRejection")}),p.info(l.colors.green("ā
Process event handlers registered successfully"))}catch(e){p.warn(l.colors.yellow(`ā ļø Failed to register process event handlers: ${e}`))}else p.warn(l.colors.yellow("ā ļø process.on is not available, graceful shutdown handlers will not be registered")),p.info(l.colors.blue("š” This might be due to bundling or environment constraints"))}),d=!1}catch(e){d=!1,p.error(l.colors.red(`ā Failed to start Next.js server: ${e?.message}. Stack: ${e?.stack}`)),e instanceof Error&&e.message.includes("Next.js is required")&&(p.error(l.colors.red("ā Next.js Peer Dependency Error:")),p.error(l.colors.red(e.message)),p.error(l.colors.yellow("\nš” To fix this issue:")),p.error(l.colors.blue(" 1. Install Next.js in your project:")),p.error(l.colors.white(" npm install next@^16")),p.error(l.colors.blue(" 2. Or use yarn:")),p.error(l.colors.white(" yarn add next@^16")),p.error(l.colors.blue(" 3. Or use pnpm:")),p.error(l.colors.white(" pnpm add next@^16")),p.error(l.colors.yellow("\nš For more information, see:")),p.error(l.colors.blue(" https://nextjs.org/docs/getting-started"))),process.exit(1)}var u}},u=async e=>{p.info(l.colors.yellow(`\nš Received ${e}, shutting down gracefully...`));try{r&&(D(r),r=null),i&&await new Promise(e=>{i.close(()=>{i=null,e()})}),n&&"function"==typeof n.close&&(await n.close(),n=null),p.info(l.colors.green("ā
Graceful shutdown completed")),process.exit(0)}catch(e){p.error(l.colors.red(`ā Error during graceful shutdown: ${e}`)),process.exit(1)}};process.on("SIGINT",()=>u("SIGINT")),process.on("SIGTERM",()=>u("SIGTERM")),process.on("uncaughtException",e=>{p.error(l.colors.red(`ā Uncaught Exception: ${e}`)),u("uncaughtException")}),process.on("unhandledRejection",(e,o)=>{p.error(l.colors.red(`ā Unhandled Rejection at: ${o}, reason: ${e}`)),u("unhandledRejection")}),await f()}),I.command("build [root]","build for production").option("--target <target>","[string] transpile target (default: 'modules')").option("--outDir <dir>","[string] output directory (default: dist)").option("--assetsDir <dir>","[string] directory under outDir to place assets in (default: assets)").option("--assetsInlineLimit <number>","[number] static asset base64 inline threshold in bytes (default: 4096)").option("--ssr [entry]","[string] build specified entry for server-side rendering").option("--sourcemap [output]",'[boolean | "inline" | "hidden"] output source maps for build (default: false)').option("--minify [minifier]",'[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)').option("--manifest [name]","[boolean | string] emit build manifest json").option("--ssrManifest [name]","[boolean | string] emit ssr manifest json").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle (experimental)").option("--emptyOutDir","[boolean] force empty outDir when it's outside of root").option("-w, --watch","[boolean] rebuilds when modules have changed on disk").option("--changelog [assetsFile]","[boolean | string] generate changelog between assetsFile and current build (default: false)").action(async(e,o)=>{z(o);const t=H(o);try{const n=await s.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let i=await a.getViteConfig();if(n){const{plugins:e,...o}=n.config;i=s.mergeConfig(i,o)}const r=s.mergeConfig(i,{root:e,base:o.base,mode:o.mode,configFile:o.config,logLevel:o.logLevel,clearScreen:o.clearScreen,optimizeDeps:{force:o.force},build:t},!0);if(await s.build(r),t.changelog){const n=e||process.cwd(),i=r.build?.outDir||"dist";let s="";if("string"==typeof t.changelog)s=v.resolve(n,t.changelog);else{const e=v.resolve(n,r.ppDevConfig?.syncBackupsDir||"backups");if(!y.existsSync(e))return void l.createLogger(o.logLevel).warn(l.colors.yellow("backups directory not found, skipping changelog generation"));const t=y.readdirSync(e,{withFileTypes:!0});if(!t.length)return void l.createLogger(o.logLevel).warn(l.colors.yellow("no backups found, skipping changelog generation"));const i=t.filter(e=>e.isFile()&&e.name.endsWith(".zip"));if(!i.length)return void l.createLogger(o.logLevel).warn(l.colors.yellow("no ZIP backups found, skipping changelog generation"));const a=i.reduce((o,t)=>y.statSync(v.resolve(e,o.name)).mtimeMs>y.statSync(v.resolve(e,t.name)).mtimeMs?o:t).name;s=v.resolve(e,a)}const a=v.resolve(n,i);let c="dist-zip";r.ppDevConfig&&(!1===r.ppDevConfig.distZip?c=r.build?.outDir||"dist":"object"==typeof r.ppDevConfig.distZip&&"string"==typeof r.ppDevConfig.distZip.outDir&&(c=r.ppDevConfig.distZip.outDir));const d=new j({oldAssetsPath:s,newAssetsPath:a,destinationPath:v.resolve(n,c)});await d.generateChangelog()}}catch(e){l.createLogger(o.logLevel).error(l.colors.red(`error during build:\n${e.stack}`),{error:e}),process.exit(1)}finally{q(e=>l.createLogger(o.logLevel).info(e))}}),I.command("changelog [oldAssetPath] [newAssetPath]","generate changelog between two assets files/folders").option("--oldAssetsPath <oldAssetsPath>","[string] path to the old assets zip file or folder").option("--newAssetsPath <newAssetsPath>","[string] path to the new assets zip file or folder").option("--destination <destination>","[string] destination folder for the changelog (default: .)").option("--filename <filename>","[string] filename for the changelog (default: CHANGELOG.html)").action(async(e,o,t)=>{z(t);const{oldAssetsPath:n=e,newAssetsPath:i=o,destination:r=".",filename:s="CHANGELOG.html",logLevel:a}=t,c=process.cwd();n&&i||(l.createLogger(a).error(l.colors.red("error during changelog generation: oldAssetPath and newAssetPath are required")),process.exit(1));const d=v.resolve(c,n),p=v.resolve(c,i),f=v.resolve(c,r),u=new j({oldAssetsPath:d,newAssetsPath:p,destinationPath:f,changelogFilename:s});await u.generateChangelog()}),I.command("generate-icon-font [source] [destination]","generate icon font from SVG files").option("--source <source>","[string] path to the source directory with SVG files").option("--destination <destination>","[string] path to the destination directory to save the generated font files").option("--font-name, -n <fontName>","[string] name of the font to generate (default: 'icon-font')").action(async(e,o,t)=>{z(t);const{source:n=e,destination:i=o,fontName:r="icon-font"}=t,s=process.cwd(),a=v.resolve(s,n),c=v.resolve(s,i),d=new A({sourceDir:a,outputDir:c,fontName:r}),p=l.createLogger(t.logLevel);p.info(`Generating icon font from SVG files in ${l.colors.dim(a)}`),await d.generate(),p.info(`Icon font generated and saved to ${l.colors.dim(c)}`)}),I.command("optimize [root]","pre-bundle dependencies").option("--force","[boolean] force the optimizer to ignore the cache and re-bundle").action(async(e,o)=>{z(o);try{const t=await s.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let n=await a.getViteConfig();if(t){const{plugins:e,...o}=t.config;n=s.mergeConfig(n,o)}const i=await s.resolveConfig(s.mergeConfig(n,{root:e,base:o.base,configFile:o.config,logLevel:o.logLevel,mode:o.mode}),"serve");await s.optimizeDeps(i,o.force,!0)}catch(e){l.createLogger(o.logLevel).error(l.colors.red(`error when optimizing deps:\n${e.stack}`),{error:e}),process.exit(1)}}),I.command("preview [root]","locally preview production build").option("--host [host]","[string] specify hostname").option("--port <port>","[number] specify port").option("--strictPort","[boolean] exit if specified port is already in use").option("--https","[boolean] use TLS + HTTP/2").option("--open [path]","[boolean | string] open browser on startup").option("--outDir <dir>","[string] output directory (default: dist)").action(async(e,o)=>{z(o);try{const t=await s.loadConfigFromFile({mode:o.mode||"production",command:"build"},o.config,e,o.logLevel);let n=await a.getViteConfig();if(t){const{plugins:e,...o}=t.config;n=s.mergeConfig(n,o)}(await s.preview(s.mergeConfig(n,{root:e,base:o.base,configFile:o.config,logLevel:o.logLevel,mode:o.mode,build:{outDir:o.outDir},preview:{port:o.port,strictPort:o.strictPort,host:o.host,https:o.https,open:o.open}}))).printUrls()}catch(e){l.createLogger(o.logLevel).error(l.colors.red(`error when starting preview server:\n${e.stack}`),{error:e}),process.exit(1)}finally{q(e=>l.createLogger(o.logLevel).info(e))}}),I.help(),I.version(a.VERSION),I.parse(),exports.stopProfiler=q;
|
|
2
2
|
//# sourceMappingURL=cli.js.map
|