ewvjs 1.0.0 → 1.0.2

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/bin/ewvjs-cli.js DELETED
@@ -1,318 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { Command } = require('commander');
4
- const path = require('path');
5
- const fs = require('fs');
6
- const packageApp = require('../lib/packager');
7
- const { setIcon } = require('../lib/icon');
8
-
9
- const program = new Command();
10
-
11
- program
12
- .name('ewvjs')
13
- .description('CLI tool for packaging ewvjs applications')
14
- .version(require('../package.json').version);
15
-
16
- program
17
- .command('package')
18
- .description('Package your ewvjs application into a standalone executable')
19
- .argument('<entry>', 'Entry point JavaScript file (e.g., app.js)')
20
- .option('-o, --output <name>', 'Output executable name', 'app')
21
- .option('-a, --assets <dir>', 'Assets directory to include (e.g., ./assets)', './assets')
22
- .option('-i, --icon <file>', 'Application icon (.ico file)')
23
- .option('-n, --name <name>', 'Application name', 'My App')
24
- .option('-t, --target <target>', 'Target platform', 'node18-win-x64')
25
- .option('-m, --modules <modules>', 'Additional node modules to bundle (comma-separated, e.g., "axios,lodash")')
26
- .option('--compress', 'Compress the executable with UPX', false)
27
- .option('--no-native', 'Skip bundling native DLLs (use if already included)')
28
- .action(async (entry, options) => {
29
- try {
30
- console.log('šŸ“¦ Packaging ewvjs application...\n');
31
-
32
- // Validate entry file exists
33
- const entryPath = path.resolve(process.cwd(), entry);
34
- if (!fs.existsSync(entryPath)) {
35
- console.error(`āŒ Error: Entry file not found: ${entry}`);
36
- process.exit(1);
37
- }
38
-
39
- // Validate icon if provided
40
- if (options.icon) {
41
- const iconPath = path.resolve(process.cwd(), options.icon);
42
- if (!fs.existsSync(iconPath)) {
43
- console.error(`āŒ Error: Icon file not found: ${options.icon}`);
44
- process.exit(1);
45
- }
46
- if (!iconPath.endsWith('.ico')) {
47
- console.error('āŒ Error: Icon must be a .ico file');
48
- process.exit(1);
49
- }
50
- }
51
-
52
- // Parse additional modules if provided
53
- const additionalModules = options.modules
54
- ? options.modules.split(',').map(m => m.trim()).filter(m => m)
55
- : [];
56
-
57
- const config = {
58
- entry: entryPath,
59
- output: options.output,
60
- assets: options.assets ? path.resolve(process.cwd(), options.assets) : null,
61
- icon: options.icon ? path.resolve(process.cwd(), options.icon) : null,
62
- name: options.name,
63
- target: options.target,
64
- compress: options.compress,
65
- includeNative: options.native,
66
- additionalModules: additionalModules
67
- };
68
-
69
- await packageApp(config);
70
-
71
- console.log('\nāœ… Packaging complete!');
72
- console.log(`šŸ“ Output: ${path.join(process.cwd(), 'dist', options.output + '.exe')}`);
73
-
74
- } catch (error) {
75
- console.error('\nāŒ Packaging failed:', error.message);
76
- process.exit(1);
77
- }
78
- });
79
-
80
- program
81
- .command('init')
82
- .description('Initialize a new ewvjs project')
83
- .argument('[name]', 'Project name', 'my-ewvjs-app')
84
- .action((name) => {
85
- const projectDir = path.join(process.cwd(), name);
86
-
87
- if (fs.existsSync(projectDir)) {
88
- console.error(`āŒ Error: Directory ${name} already exists`);
89
- process.exit(1);
90
- }
91
-
92
- console.log(`šŸ“‚ Creating new ewvjs project: ${name}\n`);
93
-
94
- // Create directory structure
95
- fs.mkdirSync(projectDir, { recursive: true });
96
- fs.mkdirSync(path.join(projectDir, 'assets'), { recursive: true });
97
-
98
- // Create package.json
99
- const packageJson = {
100
- name: name,
101
- version: '1.0.0',
102
- description: 'My ewvjs application',
103
- main: 'app.js',
104
- scripts: {
105
- start: 'node app.js',
106
- package: 'ewvjs package app.js -o myapp -n "My App"'
107
- },
108
- dependencies: {
109
- ewvjs: '^1.0.0'
110
- }
111
- };
112
-
113
- fs.writeFileSync(
114
- path.join(projectDir, 'package.json'),
115
- JSON.stringify(packageJson, null, 2)
116
- );
117
-
118
- // Create sample app.js
119
- const appJs = `const { create_window, start, expose } = require('ewvjs');
120
-
121
- expose('greet', (name) => {
122
- return \`Hello, \${name}! This is from Node.js šŸš€\`;
123
- });
124
-
125
- expose('getSystemInfo', () => {
126
- return {
127
- platform: process.platform,
128
- arch: process.arch,
129
- nodeVersion: process.version,
130
- uptime: process.uptime()
131
- };
132
- });
133
-
134
- // Create main window
135
- const window = create_window('Hello ewvjs', \`
136
- <!DOCTYPE html>
137
- <html>
138
- <head>
139
- <meta charset="UTF-8">
140
- <title>Hello ewvjs</title>
141
- <style>
142
- * {
143
- margin: 0;
144
- padding: 0;
145
- box-sizing: border-box;
146
- }
147
-
148
- body {
149
- font-family: sans-serif;
150
- color: white;
151
- display: flex;
152
- align-items: center;
153
- justify-content: center;
154
- min-height: 100vh;
155
- padding: 20px;
156
- }
157
-
158
- .container {
159
- text-align: center;
160
- max-width: 600px;
161
- }
162
-
163
- h1 {
164
- font-size: 3em;
165
- margin-bottom: 20px;
166
- text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
167
- }
168
-
169
- p {
170
- font-size: 1.2em;
171
- margin-bottom: 30px;
172
- opacity: 0.9;
173
- }
174
-
175
- input {
176
- width: 100%;
177
- padding: 15px;
178
- font-size: 16px;
179
- border: none;
180
- margin-bottom: 15px;
181
- background: rgba(255, 255, 255, 0.9);
182
- color: #333;
183
- }
184
-
185
- button {
186
- background: white;
187
- color: #000000;
188
- border: none;
189
- padding: 15px 30px;
190
- font-size: 18px;
191
- font-weight: bold;
192
- cursor: pointer;
193
- transition: all 0.3s ease;
194
- margin: 5px;
195
- }
196
-
197
- button:hover {
198
- transform: translateY(-2px);
199
- box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
200
- }
201
-
202
- button:active {
203
- transform: translateY(0);
204
- }
205
-
206
- .result {
207
- margin-top: 20px;
208
- padding: 20px;
209
- background: rgba(255, 255, 255, 0.15);
210
- min-height: 60px;
211
- display: flex;
212
- align-items: center;
213
- justify-content: center;
214
- }
215
-
216
- .info {
217
- text-align: left;
218
- font-size: 0.9em;
219
- line-height: 1.6;
220
- }
221
- </style>
222
- </head>
223
- <body>
224
- <div class="container">
225
- <h1>šŸš€ Hello ewvjs!</h1>
226
- <p>A lightweight WebView2 application for Windows</p>
227
-
228
- <input type="text" id="nameInput" placeholder="Enter your name..." value="World">
229
-
230
- <div>
231
- <button onclick="sayHello()">Greet Me</button>
232
- <button onclick="showSystemInfo()">System Info</button>
233
- </div>
234
-
235
- <div class="result" id="result">
236
- Click a button to see the result...
237
- </div>
238
- </div>
239
-
240
- <script>
241
- async function sayHello() {
242
- const name = document.getElementById('nameInput').value || 'World';
243
- const result = await window.ewvjs.api.greet(name);
244
- document.getElementById('result').innerHTML = '<strong>' + result + '</strong>';
245
- }
246
-
247
- async function showSystemInfo() {
248
- const info = await window.ewvjs.api.getSystemInfo();
249
- document.getElementById('result').innerHTML =
250
- '<div class="info">' +
251
- '<strong>System Information:</strong><br>' +
252
- 'Platform: ' + info.platform + '<br>' +
253
- 'Architecture: ' + info.arch + '<br>' +
254
- 'Node.js: ' + info.nodeVersion + '<br>' +
255
- 'Uptime: ' + Math.floor(info.uptime) + ' seconds' +
256
- '</div>';
257
- }
258
- </script>
259
- </body>
260
- </html>
261
- \`, {
262
- width: 800,
263
- height: 600,
264
- vibrancy: true,
265
- debug: true
266
- });
267
-
268
- window.run();
269
-
270
- // Start the event loop
271
- start();
272
- `;
273
-
274
- fs.writeFileSync(path.join(projectDir, 'app.js'), appJs);
275
-
276
- // Create README
277
- const readme = `# ${name}
278
-
279
- A ewvjs application.
280
-
281
- ## Getting Started
282
-
283
- 1. Install dependencies:
284
- \`\`\`bash
285
- npm install
286
- \`\`\`
287
-
288
- 2. Run the application:
289
- \`\`\`bash
290
- npm start
291
- \`\`\`
292
-
293
- 3. Package the application:
294
- \`\`\`bash
295
- npm run package
296
- \`\`\`
297
-
298
- ## Project Structure
299
-
300
- - \`app.js\` - Main application entry point
301
- - \`assets/\` - Static assets (images, fonts, etc.)
302
- - \`package.json\` - Project configuration
303
-
304
- ## Documentation
305
-
306
- Visit [ewvjs documentation](https://github.com/your-repo/ewvjs) for more information.
307
- `;
308
-
309
- fs.writeFileSync(path.join(projectDir, 'README.md'), readme);
310
-
311
- console.log('āœ… Project created successfully!\n');
312
- console.log('Next steps:');
313
- console.log(` cd ${name}`);
314
- console.log(' npm install');
315
- console.log(' npm start\n');
316
- });
317
-
318
- program.parse();
package/lib/assets.js DELETED
@@ -1,129 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const archiver = require('archiver');
4
-
5
- /**
6
- * Bundle assets directory
7
- * @param {string} assetsDir - Source assets directory
8
- * @param {string} outputDir - Destination directory
9
- * @returns {Promise<void>}
10
- */
11
- async function bundleAssets(assetsDir, outputDir) {
12
- if (!fs.existsSync(assetsDir)) {
13
- throw new Error(`Assets directory not found: ${assetsDir}`);
14
- }
15
-
16
- // Create output directory
17
- if (!fs.existsSync(outputDir)) {
18
- fs.mkdirSync(outputDir, { recursive: true });
19
- }
20
-
21
- // Copy assets directory
22
- await copyDirectory(assetsDir, outputDir);
23
-
24
- // Get stats
25
- const stats = getDirectoryStats(outputDir);
26
- console.log(` Copied ${stats.files} files (${formatBytes(stats.size)})`);
27
- }
28
-
29
- /**
30
- * Copy directory recursively
31
- * @param {string} src - Source directory
32
- * @param {string} dest - Destination directory
33
- */
34
- async function copyDirectory(src, dest) {
35
- if (!fs.existsSync(dest)) {
36
- fs.mkdirSync(dest, { recursive: true });
37
- }
38
-
39
- const entries = fs.readdirSync(src, { withFileTypes: true });
40
-
41
- for (const entry of entries) {
42
- const srcPath = path.join(src, entry.name);
43
- const destPath = path.join(dest, entry.name);
44
-
45
- if (entry.isDirectory()) {
46
- await copyDirectory(srcPath, destPath);
47
- } else {
48
- fs.copyFileSync(srcPath, destPath);
49
- }
50
- }
51
- }
52
-
53
- /**
54
- * Create a zip archive of assets (alternative to direct copy)
55
- * @param {string} assetsDir - Source assets directory
56
- * @param {string} outputPath - Output zip file path
57
- * @returns {Promise<void>}
58
- */
59
- async function createAssetsArchive(assetsDir, outputPath) {
60
- return new Promise((resolve, reject) => {
61
- const output = fs.createWriteStream(outputPath);
62
- const archive = archiver('zip', {
63
- zlib: { level: 9 } // Maximum compression
64
- });
65
-
66
- output.on('close', () => {
67
- console.log(` Created archive: ${formatBytes(archive.pointer())}`);
68
- resolve();
69
- });
70
-
71
- archive.on('error', (err) => {
72
- reject(err);
73
- });
74
-
75
- archive.pipe(output);
76
- archive.directory(assetsDir, false);
77
- archive.finalize();
78
- });
79
- }
80
-
81
- /**
82
- * Get directory statistics
83
- * @param {string} dirPath - Directory path
84
- * @returns {{files: number, size: number}}
85
- */
86
- function getDirectoryStats(dirPath) {
87
- let fileCount = 0;
88
- let totalSize = 0;
89
-
90
- function traverse(dir) {
91
- const entries = fs.readdirSync(dir, { withFileTypes: true });
92
-
93
- for (const entry of entries) {
94
- const fullPath = path.join(dir, entry.name);
95
-
96
- if (entry.isDirectory()) {
97
- traverse(fullPath);
98
- } else {
99
- fileCount++;
100
- totalSize += fs.statSync(fullPath).size;
101
- }
102
- }
103
- }
104
-
105
- traverse(dirPath);
106
- return { files: fileCount, size: totalSize };
107
- }
108
-
109
- /**
110
- * Format bytes to human-readable string
111
- * @param {number} bytes - Number of bytes
112
- * @returns {string}
113
- */
114
- function formatBytes(bytes) {
115
- if (bytes === 0) return '0 Bytes';
116
-
117
- const k = 1024;
118
- const sizes = ['Bytes', 'KB', 'MB', 'GB'];
119
- const i = Math.floor(Math.log(bytes) / Math.log(k));
120
-
121
- return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
122
- }
123
-
124
- module.exports = {
125
- bundleAssets,
126
- createAssetsArchive,
127
- copyDirectory,
128
- formatBytes
129
- };
package/lib/icon.js DELETED
@@ -1,150 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const NtExecutable = require('resedit').NtExecutable;
4
- const NtExecutableResource = require('resedit').NtExecutableResource;
5
- const Resource = require('resedit').Resource;
6
-
7
- /**
8
- * Set icon and metadata for Windows executable
9
- * @param {string} exePath - Path to the executable
10
- * @param {string} iconPath - Path to the .ico file
11
- * @param {string} appName - Application name
12
- * @param {Object} options - Additional metadata options
13
- * @returns {Promise<void>}
14
- */
15
- async function setIcon(exePath, iconPath, appName, options = {}) {
16
- try {
17
- // Read the executable
18
- const exeBuffer = fs.readFileSync(exePath);
19
- const exe = NtExecutable.from(exeBuffer);
20
- const res = NtExecutableResource.from(exe);
21
-
22
- // Read the icon file
23
- if (iconPath && fs.existsSync(iconPath)) {
24
- const iconBuffer = fs.readFileSync(iconPath);
25
-
26
- // Parse icon data
27
- const iconFile = Resource.IconFile.from(iconBuffer);
28
-
29
- // Replace icon in executable
30
- Resource.IconGroupEntry.replaceIconsForResource(
31
- res.entries,
32
- 1, // Icon group ID
33
- 1033, // Language (English - United States)
34
- iconFile.icons.map((icon) => icon.data)
35
- );
36
-
37
- console.log(` Applied icon: ${path.basename(iconPath)}`);
38
- }
39
-
40
- // Set version info
41
- const viList = Resource.VersionInfo.fromEntries(res.entries);
42
- const vi = viList[0] || Resource.VersionInfo.createEmpty();
43
-
44
- const {
45
- version = '1.0.0.0',
46
- companyName = '',
47
- fileDescription = appName,
48
- copyright = `Copyright Ā© ${new Date().getFullYear()}`,
49
- productName = appName,
50
- internalName = appName.replace(/\s+/g, ''),
51
- } = options;
52
-
53
- // Parse version string
54
- const [major = 1, minor = 0, patch = 0, build = 0] = version.split('.').map(Number);
55
-
56
- // Set version numbers
57
- vi.setFileVersion(major, minor, patch, build, 1033);
58
- vi.setProductVersion(major, minor, patch, build, 1033);
59
-
60
- // Set string values
61
- vi.setStringValues(
62
- { lang: 1033, codepage: 1200 },
63
- {
64
- ProductName: productName,
65
- FileDescription: fileDescription,
66
- CompanyName: companyName,
67
- LegalCopyright: copyright,
68
- FileVersion: version,
69
- ProductVersion: version,
70
- InternalName: internalName,
71
- OriginalFilename: path.basename(exePath)
72
- }
73
- );
74
-
75
- vi.outputToResourceEntries(res.entries);
76
-
77
- // Write back to executable
78
- res.outputResource(exe);
79
- const newBuffer = exe.generate();
80
- fs.writeFileSync(exePath, Buffer.from(newBuffer));
81
-
82
- console.log(` Applied metadata: ${appName} v${version}`);
83
- } catch (error) {
84
- console.warn(` ⚠ Warning: Could not set icon/metadata: ${error.message}`);
85
- console.warn(' The executable was created but icon/metadata may be missing.');
86
- }
87
- }
88
-
89
- /**
90
- * Validate icon file
91
- * @param {string} iconPath - Path to icon file
92
- * @returns {boolean}
93
- */
94
- function validateIcon(iconPath) {
95
- if (!fs.existsSync(iconPath)) {
96
- throw new Error(`Icon file not found: ${iconPath}`);
97
- }
98
-
99
- if (!iconPath.toLowerCase().endsWith('.ico')) {
100
- throw new Error('Icon file must be in .ico format');
101
- }
102
-
103
- const stats = fs.statSync(iconPath);
104
- if (stats.size === 0) {
105
- throw new Error('Icon file is empty');
106
- }
107
-
108
- if (stats.size > 1024 * 1024) {
109
- console.warn('Warning: Icon file is larger than 1MB, consider optimizing it');
110
- }
111
-
112
- return true;
113
- }
114
-
115
- /**
116
- * Extract icon from executable
117
- * @param {string} exePath - Path to executable
118
- * @param {string} outputPath - Output path for icon file
119
- * @returns {Promise<void>}
120
- */
121
- async function extractIcon(exePath, outputPath) {
122
- try {
123
- const exeBuffer = fs.readFileSync(exePath);
124
- const exe = NtExecutable.from(exeBuffer);
125
- const res = NtExecutableResource.from(exe);
126
-
127
- // Find icon group
128
- const iconGroups = Resource.IconGroupEntry.fromEntries(res.entries);
129
-
130
- if (iconGroups.length === 0) {
131
- throw new Error('No icon found in executable');
132
- }
133
-
134
- // Get first icon group
135
- const iconGroup = iconGroups[0];
136
- const iconFile = Resource.IconFile.from(iconGroup, res.entries);
137
-
138
- // Write icon file
139
- fs.writeFileSync(outputPath, Buffer.from(iconFile.data));
140
- console.log(`Extracted icon to: ${outputPath}`);
141
- } catch (error) {
142
- throw new Error(`Failed to extract icon: ${error.message}`);
143
- }
144
- }
145
-
146
- module.exports = {
147
- setIcon,
148
- validateIcon,
149
- extractIcon
150
- };