@universal-pwa/cli 0.1.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 +22 -0
- package/README.md +110 -0
- package/dist/index.cjs +334 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +311 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 UniversalPWA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @universal-pwa/cli
|
|
2
|
+
|
|
3
|
+
Interface en ligne de commande pour UniversalPWA.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @universal-pwa/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Utilisation
|
|
12
|
+
|
|
13
|
+
### Commande `init`
|
|
14
|
+
|
|
15
|
+
Initialise une PWA dans votre projet.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
universal-pwa init [options]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Options :**
|
|
22
|
+
|
|
23
|
+
- `-p, --project-path <path>` : Chemin du projet (défaut: répertoire courant)
|
|
24
|
+
- `-n, --name <name>` : Nom de l'application
|
|
25
|
+
- `-s, --short-name <shortName>` : Nom court (max 12 caractères)
|
|
26
|
+
- `-i, --icon-source <path>` : Image source pour les icônes
|
|
27
|
+
- `-t, --theme-color <color>` : Couleur du thème (hex, ex: `#2c3e50`)
|
|
28
|
+
- `-b, --background-color <color>` : Couleur de fond (hex)
|
|
29
|
+
- `--skip-icons` : Ignorer la génération d'icônes
|
|
30
|
+
- `--skip-service-worker` : Ignorer la génération du service worker
|
|
31
|
+
- `--skip-injection` : Ignorer l'injection des meta-tags
|
|
32
|
+
- `-o, --output-dir <dir>` : Répertoire de sortie (défaut: `public`)
|
|
33
|
+
|
|
34
|
+
**Exemple :**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
universal-pwa init \
|
|
38
|
+
--name "Mon Application" \
|
|
39
|
+
--short-name "MonApp" \
|
|
40
|
+
--icon-source ./logo.png \
|
|
41
|
+
--theme-color "#2c3e50"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Commande `scan`
|
|
45
|
+
|
|
46
|
+
Scanne un projet et détecte le framework, l'architecture et les assets.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
universal-pwa scan [options]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Options :**
|
|
53
|
+
|
|
54
|
+
- `-p, --project-path <path>` : Chemin du projet (défaut: répertoire courant)
|
|
55
|
+
|
|
56
|
+
**Exemple :**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
universal-pwa scan
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Commande `preview`
|
|
63
|
+
|
|
64
|
+
Prévisualise la configuration PWA d'un projet.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
universal-pwa preview [options]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Options :**
|
|
71
|
+
|
|
72
|
+
- `-p, --project-path <path>` : Chemin du projet (défaut: répertoire courant)
|
|
73
|
+
- `--port <port>` : Port du serveur (défaut: `3000`)
|
|
74
|
+
- `--open` : Ouvrir dans le navigateur
|
|
75
|
+
|
|
76
|
+
**Exemple :**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
universal-pwa preview --port 8080
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API Programmatique
|
|
83
|
+
|
|
84
|
+
Vous pouvez également utiliser le CLI comme module :
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { initCommand } from '@universal-pwa/cli'
|
|
88
|
+
|
|
89
|
+
const result = await initCommand({
|
|
90
|
+
projectPath: './my-project',
|
|
91
|
+
name: 'My App',
|
|
92
|
+
iconSource: './icon.png',
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Développement
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Installer les dépendances
|
|
100
|
+
pnpm install
|
|
101
|
+
|
|
102
|
+
# Build
|
|
103
|
+
pnpm build
|
|
104
|
+
|
|
105
|
+
# Tests
|
|
106
|
+
pnpm test
|
|
107
|
+
|
|
108
|
+
# Lint
|
|
109
|
+
pnpm lint
|
|
110
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_commander = require("commander");
|
|
28
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
29
|
+
|
|
30
|
+
// src/commands/init.ts
|
|
31
|
+
var import_core = require("@universal-pwa/core");
|
|
32
|
+
var import_core2 = require("@universal-pwa/core");
|
|
33
|
+
var import_core3 = require("@universal-pwa/core");
|
|
34
|
+
var import_core4 = require("@universal-pwa/core");
|
|
35
|
+
var import_core5 = require("@universal-pwa/core");
|
|
36
|
+
var import_core6 = require("@universal-pwa/core");
|
|
37
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
38
|
+
var import_fs = require("fs");
|
|
39
|
+
var import_glob = require("glob");
|
|
40
|
+
var import_path = require("path");
|
|
41
|
+
async function initCommand(options = {}) {
|
|
42
|
+
const {
|
|
43
|
+
projectPath = process.cwd(),
|
|
44
|
+
name,
|
|
45
|
+
shortName,
|
|
46
|
+
iconSource,
|
|
47
|
+
themeColor,
|
|
48
|
+
backgroundColor,
|
|
49
|
+
skipIcons = false,
|
|
50
|
+
skipServiceWorker = false,
|
|
51
|
+
skipInjection = false,
|
|
52
|
+
outputDir
|
|
53
|
+
} = options;
|
|
54
|
+
const result = {
|
|
55
|
+
success: false,
|
|
56
|
+
projectPath: (0, import_path.resolve)(projectPath),
|
|
57
|
+
framework: null,
|
|
58
|
+
architecture: "static",
|
|
59
|
+
iconsGenerated: 0,
|
|
60
|
+
htmlFilesInjected: 0,
|
|
61
|
+
warnings: [],
|
|
62
|
+
errors: []
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
if (!(0, import_fs.existsSync)(result.projectPath)) {
|
|
66
|
+
result.errors.push(`Project path does not exist: ${result.projectPath}`);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
console.log(import_chalk.default.blue("\u{1F50D} Scanning project..."));
|
|
70
|
+
const scanResult = await (0, import_core.scanProject)({
|
|
71
|
+
projectPath: result.projectPath,
|
|
72
|
+
includeAssets: true,
|
|
73
|
+
includeArchitecture: true
|
|
74
|
+
});
|
|
75
|
+
result.framework = scanResult.framework.framework;
|
|
76
|
+
result.architecture = scanResult.architecture.architecture;
|
|
77
|
+
console.log(import_chalk.default.green(`\u2713 Framework detected: ${result.framework ?? "Unknown"}`));
|
|
78
|
+
console.log(import_chalk.default.green(`\u2713 Architecture: ${result.architecture}`));
|
|
79
|
+
const httpsCheck = (0, import_core6.checkProjectHttps)({ projectPath: result.projectPath });
|
|
80
|
+
if (!httpsCheck.isSecure && !httpsCheck.isLocalhost) {
|
|
81
|
+
result.warnings.push(httpsCheck.warning ?? "HTTPS required for production PWA");
|
|
82
|
+
console.log(import_chalk.default.yellow(`\u26A0 ${httpsCheck.warning}`));
|
|
83
|
+
}
|
|
84
|
+
const finalOutputDir = outputDir ?? (result.framework === "WordPress" ? (0, import_path.join)(result.projectPath, "public") : (0, import_path.join)(result.projectPath, "public"));
|
|
85
|
+
console.log(import_chalk.default.blue("\u{1F4DD} Generating manifest.json..."));
|
|
86
|
+
const appName = name ?? (result.framework ? `${result.framework} App` : "My PWA");
|
|
87
|
+
const appShortName = shortName ?? appName.substring(0, 12);
|
|
88
|
+
let iconPaths = [];
|
|
89
|
+
if (!skipIcons && iconSource) {
|
|
90
|
+
const iconSourcePath = (0, import_fs.existsSync)(iconSource) ? iconSource : (0, import_path.join)(result.projectPath, iconSource);
|
|
91
|
+
if ((0, import_fs.existsSync)(iconSourcePath)) {
|
|
92
|
+
console.log(import_chalk.default.blue("\u{1F3A8} Generating icons..."));
|
|
93
|
+
try {
|
|
94
|
+
const iconResult = await (0, import_core3.generateIcons)({
|
|
95
|
+
sourceImage: iconSourcePath,
|
|
96
|
+
outputDir: finalOutputDir
|
|
97
|
+
});
|
|
98
|
+
iconPaths = iconResult.icons.map((icon) => icon.src);
|
|
99
|
+
result.iconsGenerated = iconResult.icons.length;
|
|
100
|
+
console.log(import_chalk.default.green(`\u2713 Generated ${result.iconsGenerated} icons`));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
103
|
+
result.errors.push(`Failed to generate icons: ${errorMessage}`);
|
|
104
|
+
console.log(import_chalk.default.red(`\u2717 Failed to generate icons: ${errorMessage}`));
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
result.warnings.push(`Icon source not found: ${iconSourcePath}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (iconPaths.length > 0) {
|
|
111
|
+
const manifestWithIcons = (0, import_core2.generateManifest)({
|
|
112
|
+
name: appName,
|
|
113
|
+
shortName: appShortName,
|
|
114
|
+
startUrl: "/",
|
|
115
|
+
scope: "/",
|
|
116
|
+
display: "standalone",
|
|
117
|
+
themeColor: themeColor ?? "#ffffff",
|
|
118
|
+
backgroundColor: backgroundColor ?? "#000000",
|
|
119
|
+
icons: iconPaths.map((src) => ({
|
|
120
|
+
src,
|
|
121
|
+
sizes: src.match(/(\d+)x(\d+)/)?.[0] ?? "192x192",
|
|
122
|
+
type: "image/png"
|
|
123
|
+
}))
|
|
124
|
+
});
|
|
125
|
+
const manifestPath = (0, import_core2.generateAndWriteManifest)(manifestWithIcons, finalOutputDir);
|
|
126
|
+
result.manifestPath = manifestPath;
|
|
127
|
+
} else {
|
|
128
|
+
result.warnings.push("No icons provided. Manifest requires at least one icon. Please provide an icon source with --icon-source");
|
|
129
|
+
console.log(import_chalk.default.yellow("\u26A0 Manifest not generated: icons are required"));
|
|
130
|
+
}
|
|
131
|
+
if (!skipServiceWorker) {
|
|
132
|
+
console.log(import_chalk.default.blue("\u2699\uFE0F Generating service worker..."));
|
|
133
|
+
try {
|
|
134
|
+
const swResult = await (0, import_core4.generateServiceWorker)({
|
|
135
|
+
projectPath: result.projectPath,
|
|
136
|
+
outputDir: finalOutputDir,
|
|
137
|
+
architecture: result.architecture,
|
|
138
|
+
framework: result.framework,
|
|
139
|
+
globDirectory: finalOutputDir,
|
|
140
|
+
globPatterns: ["**/*.{html,js,css,png,jpg,jpeg,svg,webp,woff,woff2}"]
|
|
141
|
+
});
|
|
142
|
+
result.serviceWorkerPath = swResult.swPath;
|
|
143
|
+
console.log(import_chalk.default.green(`\u2713 Service worker generated: ${result.serviceWorkerPath}`));
|
|
144
|
+
console.log(import_chalk.default.gray(` Pre-cached ${swResult.count} files`));
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
147
|
+
result.errors.push(`Failed to generate service worker: ${errorMessage}`);
|
|
148
|
+
console.log(import_chalk.default.red(`\u2717 Failed to generate service worker: ${errorMessage}`));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!skipInjection) {
|
|
152
|
+
console.log(import_chalk.default.blue("\u{1F489} Injecting meta-tags..."));
|
|
153
|
+
try {
|
|
154
|
+
const htmlFiles = await (0, import_glob.glob)("**/*.html", {
|
|
155
|
+
cwd: result.projectPath,
|
|
156
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/.next/**", "**/.nuxt/**"],
|
|
157
|
+
absolute: true
|
|
158
|
+
});
|
|
159
|
+
let injectedCount = 0;
|
|
160
|
+
for (const htmlFile of htmlFiles.slice(0, 10)) {
|
|
161
|
+
try {
|
|
162
|
+
const injectionResult = (0, import_core5.injectMetaTagsInFile)(htmlFile, {
|
|
163
|
+
manifestPath: result.manifestPath ? (0, import_path.join)("/", result.manifestPath.replace(result.projectPath, "")) : "/manifest.json",
|
|
164
|
+
themeColor: themeColor ?? "#ffffff",
|
|
165
|
+
backgroundColor: backgroundColor ?? "#000000",
|
|
166
|
+
appleTouchIcon: iconPaths.find((p) => p.includes("180")) ?? "/apple-touch-icon.png",
|
|
167
|
+
appleMobileWebAppCapable: true,
|
|
168
|
+
serviceWorkerPath: result.serviceWorkerPath ? (0, import_path.join)("/", result.serviceWorkerPath.replace(result.projectPath, "")) : "/sw.js"
|
|
169
|
+
});
|
|
170
|
+
if (injectionResult.injected.length > 0) {
|
|
171
|
+
injectedCount++;
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
175
|
+
result.warnings.push(`Failed to inject meta-tags in ${htmlFile}: ${errorMessage}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
result.htmlFilesInjected = injectedCount;
|
|
179
|
+
console.log(import_chalk.default.green(`\u2713 Injected meta-tags in ${injectedCount} HTML file(s)`));
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
182
|
+
result.errors.push(`Failed to inject meta-tags: ${errorMessage}`);
|
|
183
|
+
console.log(import_chalk.default.red(`\u2717 Failed to inject meta-tags: ${errorMessage}`));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
result.success = result.errors.length === 0;
|
|
187
|
+
if (result.success) {
|
|
188
|
+
console.log(import_chalk.default.green("\n\u2705 PWA setup completed successfully!"));
|
|
189
|
+
} else {
|
|
190
|
+
console.log(import_chalk.default.red(`
|
|
191
|
+
\u274C PWA setup completed with ${result.errors.length} error(s)`));
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
196
|
+
result.errors.push(`Unexpected error: ${errorMessage}`);
|
|
197
|
+
console.log(import_chalk.default.red(`\u2717 Unexpected error: ${errorMessage}`));
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/commands/preview.ts
|
|
203
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
204
|
+
var import_fs2 = require("fs");
|
|
205
|
+
var import_path2 = require("path");
|
|
206
|
+
var import_core7 = require("@universal-pwa/core");
|
|
207
|
+
function previewCommand(options = {}) {
|
|
208
|
+
const {
|
|
209
|
+
projectPath = process.cwd(),
|
|
210
|
+
port = 3e3
|
|
211
|
+
} = options;
|
|
212
|
+
const result = {
|
|
213
|
+
success: false,
|
|
214
|
+
port,
|
|
215
|
+
url: `http://localhost:${port}`,
|
|
216
|
+
manifestExists: false,
|
|
217
|
+
serviceWorkerExists: false,
|
|
218
|
+
warnings: [],
|
|
219
|
+
errors: []
|
|
220
|
+
};
|
|
221
|
+
try {
|
|
222
|
+
const resolvedPath = (0, import_path2.resolve)(projectPath);
|
|
223
|
+
if (!(0, import_fs2.existsSync)(resolvedPath)) {
|
|
224
|
+
result.errors.push(`Project path does not exist: ${resolvedPath}`);
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
console.log(import_chalk2.default.blue("\u{1F50D} Checking PWA setup..."));
|
|
228
|
+
const manifestPath = (0, import_path2.join)(resolvedPath, "public", "manifest.json");
|
|
229
|
+
const manifestPathAlt = (0, import_path2.join)(resolvedPath, "manifest.json");
|
|
230
|
+
if ((0, import_fs2.existsSync)(manifestPath) || (0, import_fs2.existsSync)(manifestPathAlt)) {
|
|
231
|
+
result.manifestExists = true;
|
|
232
|
+
console.log(import_chalk2.default.green("\u2713 manifest.json found"));
|
|
233
|
+
} else {
|
|
234
|
+
result.warnings.push("manifest.json not found");
|
|
235
|
+
console.log(import_chalk2.default.yellow("\u26A0 manifest.json not found"));
|
|
236
|
+
}
|
|
237
|
+
const swPath = (0, import_path2.join)(resolvedPath, "public", "sw.js");
|
|
238
|
+
const swPathAlt = (0, import_path2.join)(resolvedPath, "sw.js");
|
|
239
|
+
if ((0, import_fs2.existsSync)(swPath) || (0, import_fs2.existsSync)(swPathAlt)) {
|
|
240
|
+
result.serviceWorkerExists = true;
|
|
241
|
+
console.log(import_chalk2.default.green("\u2713 Service worker found"));
|
|
242
|
+
} else {
|
|
243
|
+
result.warnings.push("Service worker (sw.js) not found");
|
|
244
|
+
console.log(import_chalk2.default.yellow("\u26A0 Service worker (sw.js) not found"));
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const httpsCheck = (0, import_core7.checkProjectHttps)({ projectPath: resolvedPath });
|
|
248
|
+
if (!httpsCheck.isSecure && !httpsCheck.isLocalhost && httpsCheck.warning) {
|
|
249
|
+
result.warnings.push(httpsCheck.warning);
|
|
250
|
+
console.log(import_chalk2.default.yellow(`\u26A0 ${httpsCheck.warning}`));
|
|
251
|
+
}
|
|
252
|
+
} catch {
|
|
253
|
+
}
|
|
254
|
+
console.log(import_chalk2.default.blue(`
|
|
255
|
+
\u{1F4E6} PWA Preview would be available at: ${result.url}`));
|
|
256
|
+
console.log(import_chalk2.default.gray(" (Server not started in preview mode - use a static server like `serve` or `http-server`)"));
|
|
257
|
+
result.success = result.errors.length === 0;
|
|
258
|
+
if (result.success) {
|
|
259
|
+
console.log(import_chalk2.default.green("\n\u2705 PWA preview check completed"));
|
|
260
|
+
} else {
|
|
261
|
+
console.log(import_chalk2.default.red(`
|
|
262
|
+
\u274C PWA preview check failed with ${result.errors.length} error(s)`));
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
267
|
+
result.errors.push(`Unexpected error: ${errorMessage}`);
|
|
268
|
+
console.log(import_chalk2.default.red(`\u2717 Unexpected error: ${errorMessage}`));
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/index.ts
|
|
274
|
+
var import_core8 = require("@universal-pwa/core");
|
|
275
|
+
var program = new import_commander.Command();
|
|
276
|
+
program.name("universal-pwa").description("Transform any web project into a PWA with one click").version("0.0.0");
|
|
277
|
+
program.command("init").description("Initialize PWA in your project").option("-p, --project-path <path>", "Project path", process.cwd()).option("-n, --name <name>", "App name").option("-s, --short-name <shortName>", "App short name (max 12 chars)").option("-i, --icon-source <path>", "Source image for icons").option("-t, --theme-color <color>", "Theme color (hex)").option("-b, --background-color <color>", "Background color (hex)").option("--skip-icons", "Skip icon generation").option("--skip-service-worker", "Skip service worker generation").option("--skip-injection", "Skip HTML meta-tag injection").option("-o, --output-dir <dir>", "Output directory", "public").action(async (options) => {
|
|
278
|
+
try {
|
|
279
|
+
const result = await initCommand({
|
|
280
|
+
projectPath: options.projectPath,
|
|
281
|
+
name: options.name,
|
|
282
|
+
shortName: options.shortName,
|
|
283
|
+
iconSource: options.iconSource,
|
|
284
|
+
themeColor: options.themeColor,
|
|
285
|
+
backgroundColor: options.backgroundColor,
|
|
286
|
+
skipIcons: options.skipIcons,
|
|
287
|
+
skipServiceWorker: options.skipServiceWorker,
|
|
288
|
+
skipInjection: options.skipInjection,
|
|
289
|
+
outputDir: options.outputDir
|
|
290
|
+
});
|
|
291
|
+
process.exit(result.success ? 0 : 1);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
console.error(import_chalk3.default.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
program.command("preview").description("Preview PWA setup").option("-p, --project-path <path>", "Project path", process.cwd()).option("--port <port>", "Server port", "3000").option("--open", "Open in browser", false).action(async (options) => {
|
|
298
|
+
try {
|
|
299
|
+
const result = await previewCommand({
|
|
300
|
+
projectPath: options.projectPath,
|
|
301
|
+
port: options.port ? Number.parseInt(options.port, 10) : void 0,
|
|
302
|
+
open: options.open
|
|
303
|
+
});
|
|
304
|
+
process.exit(result.success ? 0 : 1);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error(import_chalk3.default.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
program.command("scan").description("Scan project and detect framework/architecture").option("-p, --project-path <path>", "Project path", process.cwd()).action(async (options) => {
|
|
311
|
+
try {
|
|
312
|
+
console.log(import_chalk3.default.blue("\u{1F50D} Scanning project..."));
|
|
313
|
+
const result = await (0, import_core8.scanProject)({
|
|
314
|
+
projectPath: options.projectPath ?? process.cwd(),
|
|
315
|
+
includeAssets: true,
|
|
316
|
+
includeArchitecture: true
|
|
317
|
+
});
|
|
318
|
+
console.log(import_chalk3.default.green(`
|
|
319
|
+
\u2713 Framework: ${result.framework.framework ?? "Unknown"}`));
|
|
320
|
+
console.log(import_chalk3.default.green(`\u2713 Architecture: ${result.architecture.architecture}`));
|
|
321
|
+
console.log(import_chalk3.default.green(`\u2713 Build Tool: ${result.architecture.buildTool ?? "Unknown"}`));
|
|
322
|
+
console.log(import_chalk3.default.gray(`
|
|
323
|
+
Assets found:`));
|
|
324
|
+
console.log(import_chalk3.default.gray(` - JavaScript: ${result.assets.javascript.length} files`));
|
|
325
|
+
console.log(import_chalk3.default.gray(` - CSS: ${result.assets.css.length} files`));
|
|
326
|
+
console.log(import_chalk3.default.gray(` - Images: ${result.assets.images.length} files`));
|
|
327
|
+
console.log(import_chalk3.default.gray(` - Fonts: ${result.assets.fonts.length} files`));
|
|
328
|
+
process.exit(0);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error(import_chalk3.default.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
program.parse();
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import chalk3 from "chalk";
|
|
6
|
+
|
|
7
|
+
// src/commands/init.ts
|
|
8
|
+
import { scanProject } from "@universal-pwa/core";
|
|
9
|
+
import { generateManifest, generateAndWriteManifest } from "@universal-pwa/core";
|
|
10
|
+
import { generateIcons } from "@universal-pwa/core";
|
|
11
|
+
import { generateServiceWorker } from "@universal-pwa/core";
|
|
12
|
+
import { injectMetaTagsInFile } from "@universal-pwa/core";
|
|
13
|
+
import { checkProjectHttps } from "@universal-pwa/core";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import { existsSync } from "fs";
|
|
16
|
+
import { glob } from "glob";
|
|
17
|
+
import { join, resolve } from "path";
|
|
18
|
+
async function initCommand(options = {}) {
|
|
19
|
+
const {
|
|
20
|
+
projectPath = process.cwd(),
|
|
21
|
+
name,
|
|
22
|
+
shortName,
|
|
23
|
+
iconSource,
|
|
24
|
+
themeColor,
|
|
25
|
+
backgroundColor,
|
|
26
|
+
skipIcons = false,
|
|
27
|
+
skipServiceWorker = false,
|
|
28
|
+
skipInjection = false,
|
|
29
|
+
outputDir
|
|
30
|
+
} = options;
|
|
31
|
+
const result = {
|
|
32
|
+
success: false,
|
|
33
|
+
projectPath: resolve(projectPath),
|
|
34
|
+
framework: null,
|
|
35
|
+
architecture: "static",
|
|
36
|
+
iconsGenerated: 0,
|
|
37
|
+
htmlFilesInjected: 0,
|
|
38
|
+
warnings: [],
|
|
39
|
+
errors: []
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
if (!existsSync(result.projectPath)) {
|
|
43
|
+
result.errors.push(`Project path does not exist: ${result.projectPath}`);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
console.log(chalk.blue("\u{1F50D} Scanning project..."));
|
|
47
|
+
const scanResult = await scanProject({
|
|
48
|
+
projectPath: result.projectPath,
|
|
49
|
+
includeAssets: true,
|
|
50
|
+
includeArchitecture: true
|
|
51
|
+
});
|
|
52
|
+
result.framework = scanResult.framework.framework;
|
|
53
|
+
result.architecture = scanResult.architecture.architecture;
|
|
54
|
+
console.log(chalk.green(`\u2713 Framework detected: ${result.framework ?? "Unknown"}`));
|
|
55
|
+
console.log(chalk.green(`\u2713 Architecture: ${result.architecture}`));
|
|
56
|
+
const httpsCheck = checkProjectHttps({ projectPath: result.projectPath });
|
|
57
|
+
if (!httpsCheck.isSecure && !httpsCheck.isLocalhost) {
|
|
58
|
+
result.warnings.push(httpsCheck.warning ?? "HTTPS required for production PWA");
|
|
59
|
+
console.log(chalk.yellow(`\u26A0 ${httpsCheck.warning}`));
|
|
60
|
+
}
|
|
61
|
+
const finalOutputDir = outputDir ?? (result.framework === "WordPress" ? join(result.projectPath, "public") : join(result.projectPath, "public"));
|
|
62
|
+
console.log(chalk.blue("\u{1F4DD} Generating manifest.json..."));
|
|
63
|
+
const appName = name ?? (result.framework ? `${result.framework} App` : "My PWA");
|
|
64
|
+
const appShortName = shortName ?? appName.substring(0, 12);
|
|
65
|
+
let iconPaths = [];
|
|
66
|
+
if (!skipIcons && iconSource) {
|
|
67
|
+
const iconSourcePath = existsSync(iconSource) ? iconSource : join(result.projectPath, iconSource);
|
|
68
|
+
if (existsSync(iconSourcePath)) {
|
|
69
|
+
console.log(chalk.blue("\u{1F3A8} Generating icons..."));
|
|
70
|
+
try {
|
|
71
|
+
const iconResult = await generateIcons({
|
|
72
|
+
sourceImage: iconSourcePath,
|
|
73
|
+
outputDir: finalOutputDir
|
|
74
|
+
});
|
|
75
|
+
iconPaths = iconResult.icons.map((icon) => icon.src);
|
|
76
|
+
result.iconsGenerated = iconResult.icons.length;
|
|
77
|
+
console.log(chalk.green(`\u2713 Generated ${result.iconsGenerated} icons`));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
80
|
+
result.errors.push(`Failed to generate icons: ${errorMessage}`);
|
|
81
|
+
console.log(chalk.red(`\u2717 Failed to generate icons: ${errorMessage}`));
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
result.warnings.push(`Icon source not found: ${iconSourcePath}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (iconPaths.length > 0) {
|
|
88
|
+
const manifestWithIcons = generateManifest({
|
|
89
|
+
name: appName,
|
|
90
|
+
shortName: appShortName,
|
|
91
|
+
startUrl: "/",
|
|
92
|
+
scope: "/",
|
|
93
|
+
display: "standalone",
|
|
94
|
+
themeColor: themeColor ?? "#ffffff",
|
|
95
|
+
backgroundColor: backgroundColor ?? "#000000",
|
|
96
|
+
icons: iconPaths.map((src) => ({
|
|
97
|
+
src,
|
|
98
|
+
sizes: src.match(/(\d+)x(\d+)/)?.[0] ?? "192x192",
|
|
99
|
+
type: "image/png"
|
|
100
|
+
}))
|
|
101
|
+
});
|
|
102
|
+
const manifestPath = generateAndWriteManifest(manifestWithIcons, finalOutputDir);
|
|
103
|
+
result.manifestPath = manifestPath;
|
|
104
|
+
} else {
|
|
105
|
+
result.warnings.push("No icons provided. Manifest requires at least one icon. Please provide an icon source with --icon-source");
|
|
106
|
+
console.log(chalk.yellow("\u26A0 Manifest not generated: icons are required"));
|
|
107
|
+
}
|
|
108
|
+
if (!skipServiceWorker) {
|
|
109
|
+
console.log(chalk.blue("\u2699\uFE0F Generating service worker..."));
|
|
110
|
+
try {
|
|
111
|
+
const swResult = await generateServiceWorker({
|
|
112
|
+
projectPath: result.projectPath,
|
|
113
|
+
outputDir: finalOutputDir,
|
|
114
|
+
architecture: result.architecture,
|
|
115
|
+
framework: result.framework,
|
|
116
|
+
globDirectory: finalOutputDir,
|
|
117
|
+
globPatterns: ["**/*.{html,js,css,png,jpg,jpeg,svg,webp,woff,woff2}"]
|
|
118
|
+
});
|
|
119
|
+
result.serviceWorkerPath = swResult.swPath;
|
|
120
|
+
console.log(chalk.green(`\u2713 Service worker generated: ${result.serviceWorkerPath}`));
|
|
121
|
+
console.log(chalk.gray(` Pre-cached ${swResult.count} files`));
|
|
122
|
+
} catch (error) {
|
|
123
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
124
|
+
result.errors.push(`Failed to generate service worker: ${errorMessage}`);
|
|
125
|
+
console.log(chalk.red(`\u2717 Failed to generate service worker: ${errorMessage}`));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (!skipInjection) {
|
|
129
|
+
console.log(chalk.blue("\u{1F489} Injecting meta-tags..."));
|
|
130
|
+
try {
|
|
131
|
+
const htmlFiles = await glob("**/*.html", {
|
|
132
|
+
cwd: result.projectPath,
|
|
133
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/.next/**", "**/.nuxt/**"],
|
|
134
|
+
absolute: true
|
|
135
|
+
});
|
|
136
|
+
let injectedCount = 0;
|
|
137
|
+
for (const htmlFile of htmlFiles.slice(0, 10)) {
|
|
138
|
+
try {
|
|
139
|
+
const injectionResult = injectMetaTagsInFile(htmlFile, {
|
|
140
|
+
manifestPath: result.manifestPath ? join("/", result.manifestPath.replace(result.projectPath, "")) : "/manifest.json",
|
|
141
|
+
themeColor: themeColor ?? "#ffffff",
|
|
142
|
+
backgroundColor: backgroundColor ?? "#000000",
|
|
143
|
+
appleTouchIcon: iconPaths.find((p) => p.includes("180")) ?? "/apple-touch-icon.png",
|
|
144
|
+
appleMobileWebAppCapable: true,
|
|
145
|
+
serviceWorkerPath: result.serviceWorkerPath ? join("/", result.serviceWorkerPath.replace(result.projectPath, "")) : "/sw.js"
|
|
146
|
+
});
|
|
147
|
+
if (injectionResult.injected.length > 0) {
|
|
148
|
+
injectedCount++;
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
152
|
+
result.warnings.push(`Failed to inject meta-tags in ${htmlFile}: ${errorMessage}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
result.htmlFilesInjected = injectedCount;
|
|
156
|
+
console.log(chalk.green(`\u2713 Injected meta-tags in ${injectedCount} HTML file(s)`));
|
|
157
|
+
} catch (error) {
|
|
158
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
159
|
+
result.errors.push(`Failed to inject meta-tags: ${errorMessage}`);
|
|
160
|
+
console.log(chalk.red(`\u2717 Failed to inject meta-tags: ${errorMessage}`));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
result.success = result.errors.length === 0;
|
|
164
|
+
if (result.success) {
|
|
165
|
+
console.log(chalk.green("\n\u2705 PWA setup completed successfully!"));
|
|
166
|
+
} else {
|
|
167
|
+
console.log(chalk.red(`
|
|
168
|
+
\u274C PWA setup completed with ${result.errors.length} error(s)`));
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
173
|
+
result.errors.push(`Unexpected error: ${errorMessage}`);
|
|
174
|
+
console.log(chalk.red(`\u2717 Unexpected error: ${errorMessage}`));
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/commands/preview.ts
|
|
180
|
+
import chalk2 from "chalk";
|
|
181
|
+
import { existsSync as existsSync2 } from "fs";
|
|
182
|
+
import { join as join2, resolve as resolve2 } from "path";
|
|
183
|
+
import { checkProjectHttps as checkProjectHttps2 } from "@universal-pwa/core";
|
|
184
|
+
function previewCommand(options = {}) {
|
|
185
|
+
const {
|
|
186
|
+
projectPath = process.cwd(),
|
|
187
|
+
port = 3e3
|
|
188
|
+
} = options;
|
|
189
|
+
const result = {
|
|
190
|
+
success: false,
|
|
191
|
+
port,
|
|
192
|
+
url: `http://localhost:${port}`,
|
|
193
|
+
manifestExists: false,
|
|
194
|
+
serviceWorkerExists: false,
|
|
195
|
+
warnings: [],
|
|
196
|
+
errors: []
|
|
197
|
+
};
|
|
198
|
+
try {
|
|
199
|
+
const resolvedPath = resolve2(projectPath);
|
|
200
|
+
if (!existsSync2(resolvedPath)) {
|
|
201
|
+
result.errors.push(`Project path does not exist: ${resolvedPath}`);
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
console.log(chalk2.blue("\u{1F50D} Checking PWA setup..."));
|
|
205
|
+
const manifestPath = join2(resolvedPath, "public", "manifest.json");
|
|
206
|
+
const manifestPathAlt = join2(resolvedPath, "manifest.json");
|
|
207
|
+
if (existsSync2(manifestPath) || existsSync2(manifestPathAlt)) {
|
|
208
|
+
result.manifestExists = true;
|
|
209
|
+
console.log(chalk2.green("\u2713 manifest.json found"));
|
|
210
|
+
} else {
|
|
211
|
+
result.warnings.push("manifest.json not found");
|
|
212
|
+
console.log(chalk2.yellow("\u26A0 manifest.json not found"));
|
|
213
|
+
}
|
|
214
|
+
const swPath = join2(resolvedPath, "public", "sw.js");
|
|
215
|
+
const swPathAlt = join2(resolvedPath, "sw.js");
|
|
216
|
+
if (existsSync2(swPath) || existsSync2(swPathAlt)) {
|
|
217
|
+
result.serviceWorkerExists = true;
|
|
218
|
+
console.log(chalk2.green("\u2713 Service worker found"));
|
|
219
|
+
} else {
|
|
220
|
+
result.warnings.push("Service worker (sw.js) not found");
|
|
221
|
+
console.log(chalk2.yellow("\u26A0 Service worker (sw.js) not found"));
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const httpsCheck = checkProjectHttps2({ projectPath: resolvedPath });
|
|
225
|
+
if (!httpsCheck.isSecure && !httpsCheck.isLocalhost && httpsCheck.warning) {
|
|
226
|
+
result.warnings.push(httpsCheck.warning);
|
|
227
|
+
console.log(chalk2.yellow(`\u26A0 ${httpsCheck.warning}`));
|
|
228
|
+
}
|
|
229
|
+
} catch {
|
|
230
|
+
}
|
|
231
|
+
console.log(chalk2.blue(`
|
|
232
|
+
\u{1F4E6} PWA Preview would be available at: ${result.url}`));
|
|
233
|
+
console.log(chalk2.gray(" (Server not started in preview mode - use a static server like `serve` or `http-server`)"));
|
|
234
|
+
result.success = result.errors.length === 0;
|
|
235
|
+
if (result.success) {
|
|
236
|
+
console.log(chalk2.green("\n\u2705 PWA preview check completed"));
|
|
237
|
+
} else {
|
|
238
|
+
console.log(chalk2.red(`
|
|
239
|
+
\u274C PWA preview check failed with ${result.errors.length} error(s)`));
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
244
|
+
result.errors.push(`Unexpected error: ${errorMessage}`);
|
|
245
|
+
console.log(chalk2.red(`\u2717 Unexpected error: ${errorMessage}`));
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/index.ts
|
|
251
|
+
import { scanProject as scanProject2 } from "@universal-pwa/core";
|
|
252
|
+
var program = new Command();
|
|
253
|
+
program.name("universal-pwa").description("Transform any web project into a PWA with one click").version("0.0.0");
|
|
254
|
+
program.command("init").description("Initialize PWA in your project").option("-p, --project-path <path>", "Project path", process.cwd()).option("-n, --name <name>", "App name").option("-s, --short-name <shortName>", "App short name (max 12 chars)").option("-i, --icon-source <path>", "Source image for icons").option("-t, --theme-color <color>", "Theme color (hex)").option("-b, --background-color <color>", "Background color (hex)").option("--skip-icons", "Skip icon generation").option("--skip-service-worker", "Skip service worker generation").option("--skip-injection", "Skip HTML meta-tag injection").option("-o, --output-dir <dir>", "Output directory", "public").action(async (options) => {
|
|
255
|
+
try {
|
|
256
|
+
const result = await initCommand({
|
|
257
|
+
projectPath: options.projectPath,
|
|
258
|
+
name: options.name,
|
|
259
|
+
shortName: options.shortName,
|
|
260
|
+
iconSource: options.iconSource,
|
|
261
|
+
themeColor: options.themeColor,
|
|
262
|
+
backgroundColor: options.backgroundColor,
|
|
263
|
+
skipIcons: options.skipIcons,
|
|
264
|
+
skipServiceWorker: options.skipServiceWorker,
|
|
265
|
+
skipInjection: options.skipInjection,
|
|
266
|
+
outputDir: options.outputDir
|
|
267
|
+
});
|
|
268
|
+
process.exit(result.success ? 0 : 1);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error(chalk3.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
program.command("preview").description("Preview PWA setup").option("-p, --project-path <path>", "Project path", process.cwd()).option("--port <port>", "Server port", "3000").option("--open", "Open in browser", false).action(async (options) => {
|
|
275
|
+
try {
|
|
276
|
+
const result = await previewCommand({
|
|
277
|
+
projectPath: options.projectPath,
|
|
278
|
+
port: options.port ? Number.parseInt(options.port, 10) : void 0,
|
|
279
|
+
open: options.open
|
|
280
|
+
});
|
|
281
|
+
process.exit(result.success ? 0 : 1);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error(chalk3.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
program.command("scan").description("Scan project and detect framework/architecture").option("-p, --project-path <path>", "Project path", process.cwd()).action(async (options) => {
|
|
288
|
+
try {
|
|
289
|
+
console.log(chalk3.blue("\u{1F50D} Scanning project..."));
|
|
290
|
+
const result = await scanProject2({
|
|
291
|
+
projectPath: options.projectPath ?? process.cwd(),
|
|
292
|
+
includeAssets: true,
|
|
293
|
+
includeArchitecture: true
|
|
294
|
+
});
|
|
295
|
+
console.log(chalk3.green(`
|
|
296
|
+
\u2713 Framework: ${result.framework.framework ?? "Unknown"}`));
|
|
297
|
+
console.log(chalk3.green(`\u2713 Architecture: ${result.architecture.architecture}`));
|
|
298
|
+
console.log(chalk3.green(`\u2713 Build Tool: ${result.architecture.buildTool ?? "Unknown"}`));
|
|
299
|
+
console.log(chalk3.gray(`
|
|
300
|
+
Assets found:`));
|
|
301
|
+
console.log(chalk3.gray(` - JavaScript: ${result.assets.javascript.length} files`));
|
|
302
|
+
console.log(chalk3.gray(` - CSS: ${result.assets.css.length} files`));
|
|
303
|
+
console.log(chalk3.gray(` - Images: ${result.assets.images.length} files`));
|
|
304
|
+
console.log(chalk3.gray(` - Fonts: ${result.assets.fonts.length} files`));
|
|
305
|
+
process.exit(0);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
console.error(chalk3.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
308
|
+
process.exit(1);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@universal-pwa/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI pour transformer n'importe quel projet web en PWA",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pwa",
|
|
7
|
+
"progressive-web-app",
|
|
8
|
+
"cli",
|
|
9
|
+
"workbox",
|
|
10
|
+
"service-worker"
|
|
11
|
+
],
|
|
12
|
+
"author": "julien-lin",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/julien-lin/UniversalPWA.git",
|
|
17
|
+
"directory": "packages/cli"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/julien-lin/UniversalPWA#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/julien-lin/UniversalPWA/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"universal-pwa": "dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"module": "dist/index.mjs",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.mjs",
|
|
34
|
+
"require": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"chalk": "^5.6.2",
|
|
42
|
+
"commander": "^12.1.0",
|
|
43
|
+
"fs-extra": "^11.3.3",
|
|
44
|
+
"glob": "^13.0.0",
|
|
45
|
+
"pino": "^9.14.0",
|
|
46
|
+
"zod": "^4.2.1",
|
|
47
|
+
"@universal-pwa/core": "^0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@vitest/coverage-v8": "^2.1.4",
|
|
51
|
+
"tsup": "^8.3.0",
|
|
52
|
+
"tsx": "^4.19.0",
|
|
53
|
+
"typescript": "~5.9.3",
|
|
54
|
+
"vitest": "^2.1.4"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"dev": "tsx src/index.ts",
|
|
58
|
+
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
59
|
+
"lint": "eslint src --ext .ts",
|
|
60
|
+
"test": "vitest"
|
|
61
|
+
}
|
|
62
|
+
}
|