create-zapwebp 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +37 -2
- package/bin/create-zapwebp.js +47 -0
- package/package.json +33 -4
- package/src/index.js +235 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eldrex Delos Reyes Bula
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `create-zapwebp`
|
|
2
|
+
|
|
3
|
+
Scaffold production-ready Zapwebp plugins, storage adapters, custom transformations, and metadata handlers in seconds.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm create zapwebp@latest
|
|
9
|
+
# or
|
|
10
|
+
pnpm create zapwebp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or specify template and name non-interactively:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm create zapwebp my-plugin --type format
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Available Archetype Templates
|
|
20
|
+
|
|
21
|
+
| Archetype | Flag | Description |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `format` | `--type format` | Community format expansion handler (`zapwebp-format-*`) with sniffer, decoder, and alpha validation. |
|
|
24
|
+
| `storage` | `--type storage` | Cloud storage upload adapter (`@zapwebp/storage-*`) with pre-upload conversion and cascade deletion. |
|
|
25
|
+
| `transform` | `--type transform` | Image manipulation plugin (`@zapwebp/transform-*`) operating on raw in-memory RGBA pixel buffers. |
|
|
26
|
+
| `meta` | `--type meta` | Custom metadata sanitizer (`zapwebp-meta-*`) with chunk extraction and preservation predicates. |
|
|
27
|
+
|
|
28
|
+
## What's Included in Generated Projects
|
|
29
|
+
|
|
30
|
+
- Dual CommonJS and ESM packaging (`tsup` / Node.js native).
|
|
31
|
+
- Integration test harnesses using `@zapwebp/plugin-sdk`.
|
|
32
|
+
- Complete TypeScript declaration definitions (`.d.ts`).
|
|
33
|
+
- Ready-to-publish `.npmignore`, `README.md`, and GitHub Actions CI workflow.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT © Zapwebp
|
|
2
38
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const readline = require('node:readline/promises');
|
|
5
|
+
const { stdin: input, stdout: output } = require('node:process');
|
|
6
|
+
const { scaffoldProject, ARCHETYPES } = require('../src');
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
let archetype = args[0];
|
|
11
|
+
let name = args[1];
|
|
12
|
+
|
|
13
|
+
if (!archetype || !name) {
|
|
14
|
+
const rl = readline.createInterface({ input, output });
|
|
15
|
+
try {
|
|
16
|
+
if (!archetype) {
|
|
17
|
+
output.write('⚡ Welcome to create-zapwebp!\n');
|
|
18
|
+
output.write(`Available archetypes: ${ARCHETYPES.join(', ')}\n`);
|
|
19
|
+
archetype = (await rl.question('? What do you want to build? (format|storage|plugin|cli|metadata): ')).trim();
|
|
20
|
+
}
|
|
21
|
+
if (!name) {
|
|
22
|
+
name = (await rl.question('? What is the plugin or format name?: ')).trim();
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
rl.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!archetype || !name) {
|
|
30
|
+
console.error('Error: Archetype and name are required.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const result = await scaffoldProject({ archetype, name, targetDir: process.cwd() });
|
|
36
|
+
console.log(`\n✅ Successfully scaffolded project at ${result.targetDir}`);
|
|
37
|
+
console.log(`Generated ${result.files.length} files:\n ${result.files.join('\n ')}\n`);
|
|
38
|
+
console.log('Next steps:');
|
|
39
|
+
console.log(` cd zapwebp-${archetype}-${name}`);
|
|
40
|
+
console.log(' pnpm install && pnpm test\n');
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(`\n❌ Scaffolding failed: ${err.message}\n`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-zapwebp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Scaffold working Zapwebp format plugins, storage adapters, build plugins, and custom CLIs.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"create-zapwebp": "bin/create-zapwebp.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "src/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"templates",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node --test"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://zapwebp.vercel.app",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/Zapwebp/create-zapwebp.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Zapwebp/create-zapwebp/issues"
|
|
33
|
+
},
|
|
34
|
+
"author": "Eldrex Delos Reyes Bula <eldrexdelosreyesbula@gmail.com>"
|
|
35
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const ARCHETYPES = ['format', 'storage', 'plugin', 'cli', 'metadata', 'transform'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generates scaffolding for a Zapwebp ecosystem project.
|
|
10
|
+
* @param {object} options
|
|
11
|
+
* @param {string} options.targetDir
|
|
12
|
+
* @param {'format'|'storage'|'plugin'|'cli'|'metadata'} options.archetype
|
|
13
|
+
* @param {string} options.name
|
|
14
|
+
* @param {string} [options.author='Zapwebp Developer']
|
|
15
|
+
* @returns {Promise<{ targetDir: string, files: string[] }>}
|
|
16
|
+
*/
|
|
17
|
+
async function scaffoldProject(options) {
|
|
18
|
+
const { targetDir, archetype, name, author = 'Zapwebp Developer' } = options;
|
|
19
|
+
if (!name || typeof name !== 'string') {
|
|
20
|
+
throw new Error('Project name is required.');
|
|
21
|
+
}
|
|
22
|
+
if (!ARCHETYPES.includes(archetype)) {
|
|
23
|
+
throw new Error(`Invalid archetype "${archetype}". Supported: ${ARCHETYPES.join(', ')}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const resolvedDir = path.resolve(targetDir || process.cwd(), `zapwebp-${archetype}-${name}`);
|
|
27
|
+
await fs.mkdir(resolvedDir, { recursive: true });
|
|
28
|
+
await fs.mkdir(path.join(resolvedDir, 'src'), { recursive: true });
|
|
29
|
+
await fs.mkdir(path.join(resolvedDir, 'test'), { recursive: true });
|
|
30
|
+
await fs.mkdir(path.join(resolvedDir, '.github', 'workflows'), { recursive: true });
|
|
31
|
+
|
|
32
|
+
const files = [];
|
|
33
|
+
|
|
34
|
+
// 1. package.json
|
|
35
|
+
const pkgJson = {
|
|
36
|
+
name: `zapwebp-${archetype}-${name}`,
|
|
37
|
+
version: '1.0.0',
|
|
38
|
+
description: `Zapwebp ${archetype} plugin for ${name}.`,
|
|
39
|
+
main: 'src/index.js',
|
|
40
|
+
scripts: {
|
|
41
|
+
test: 'node --test',
|
|
42
|
+
},
|
|
43
|
+
dependencies: {
|
|
44
|
+
'@zapwebp/plugin-sdk': '^1.1.0',
|
|
45
|
+
},
|
|
46
|
+
engines: {
|
|
47
|
+
node: '>=20',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
await fs.writeFile(path.join(resolvedDir, 'package.json'), JSON.stringify(pkgJson, null, 2) + '\n');
|
|
51
|
+
files.push('package.json');
|
|
52
|
+
|
|
53
|
+
// 2. src/index.js
|
|
54
|
+
let srcContent = '';
|
|
55
|
+
if (archetype === 'format') {
|
|
56
|
+
srcContent = `'use strict';
|
|
57
|
+
|
|
58
|
+
const { safeDecode, createMockRawImage } = require('@zapwebp/plugin-sdk');
|
|
59
|
+
|
|
60
|
+
/** @type {import('@zapwebp/plugin-sdk').FormatHandler} */
|
|
61
|
+
const handler = {
|
|
62
|
+
name: '${name}',
|
|
63
|
+
mimeTypes: Object.freeze(['image/${name}']),
|
|
64
|
+
extensions: Object.freeze(['.${name}']),
|
|
65
|
+
supportsAlpha: true,
|
|
66
|
+
|
|
67
|
+
detect(bytes) {
|
|
68
|
+
if (!bytes || bytes.length < 4) return false;
|
|
69
|
+
return true; // Match header signature
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async decode(bytes) {
|
|
73
|
+
// Decodes bytes to RGBA RawImage
|
|
74
|
+
return createMockRawImage(100, 100);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
async encode(image, options) {
|
|
78
|
+
return Buffer.alloc(0);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = handler;
|
|
83
|
+
`;
|
|
84
|
+
} else if (archetype === 'storage') {
|
|
85
|
+
srcContent = `'use strict';
|
|
86
|
+
|
|
87
|
+
const { validateStorageWrite } = require('@zapwebp/plugin-sdk');
|
|
88
|
+
|
|
89
|
+
class StorageAdapter {
|
|
90
|
+
constructor(config = {}) {
|
|
91
|
+
this.name = '${name}';
|
|
92
|
+
this.config = config;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async read(sourcePath) {
|
|
96
|
+
return Buffer.alloc(0);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async write(destinationPath, data) {
|
|
100
|
+
validateStorageWrite(destinationPath, data);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async delete(destinationPath) {
|
|
104
|
+
// Delete implementation
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { StorageAdapter };
|
|
109
|
+
`;
|
|
110
|
+
} else if (archetype === 'metadata') {
|
|
111
|
+
srcContent = `'use strict';
|
|
112
|
+
|
|
113
|
+
/** @type {import('@zapwebp/plugin-sdk').MetadataHandler} */
|
|
114
|
+
const handler = {
|
|
115
|
+
name: '${name}',
|
|
116
|
+
async inspect(bytes) {
|
|
117
|
+
return [];
|
|
118
|
+
},
|
|
119
|
+
async strip(bytes) {
|
|
120
|
+
return bytes;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports = handler;
|
|
125
|
+
`;
|
|
126
|
+
} else if (archetype === 'transform') {
|
|
127
|
+
srcContent = `'use strict';
|
|
128
|
+
|
|
129
|
+
const { defineTransform } = require('@zapwebp/plugin-sdk');
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Creates a ${name} TransformStep.
|
|
133
|
+
* @param {object} [options]
|
|
134
|
+
* @returns {import('@zapwebp/plugin-sdk').TransformStep}
|
|
135
|
+
*/
|
|
136
|
+
function ${name}Transform(options = {}) {
|
|
137
|
+
return defineTransform({
|
|
138
|
+
name: '${name}',
|
|
139
|
+
metadata: options,
|
|
140
|
+
async apply(image) {
|
|
141
|
+
// image is a RawImage: { data: Uint8ClampedArray, width: number, height: number }
|
|
142
|
+
// Return a transformed RawImage
|
|
143
|
+
return image;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
${name}Transform,
|
|
150
|
+
};
|
|
151
|
+
`;
|
|
152
|
+
} else {
|
|
153
|
+
srcContent = `'use strict';
|
|
154
|
+
|
|
155
|
+
const { definePlugin } = require('@zapwebp/plugin-sdk');
|
|
156
|
+
|
|
157
|
+
const plugin = definePlugin({
|
|
158
|
+
name: 'zapwebp-${archetype}-${name}',
|
|
159
|
+
version: '1.0.0',
|
|
160
|
+
hooks: {
|
|
161
|
+
beforeConvert(ctx) {
|
|
162
|
+
return ctx;
|
|
163
|
+
},
|
|
164
|
+
afterConvert(ctx, outputs) {
|
|
165
|
+
return outputs;
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
module.exports = plugin;
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
await fs.writeFile(path.join(resolvedDir, 'src', 'index.js'), srcContent);
|
|
174
|
+
files.push('src/index.js');
|
|
175
|
+
|
|
176
|
+
// 3. test/index.test.js
|
|
177
|
+
const testContent = `'use strict';
|
|
178
|
+
|
|
179
|
+
const test = require('node:test');
|
|
180
|
+
const assert = require('node:assert/strict');
|
|
181
|
+
const mod = require('../src');
|
|
182
|
+
|
|
183
|
+
test('Scaffolded module loads and exports expected API', () => {
|
|
184
|
+
assert.ok(mod);
|
|
185
|
+
});
|
|
186
|
+
`;
|
|
187
|
+
await fs.writeFile(path.join(resolvedDir, 'test', 'index.test.js'), testContent);
|
|
188
|
+
files.push('test/index.test.js');
|
|
189
|
+
|
|
190
|
+
// 4. .github/workflows/test.yml
|
|
191
|
+
const ciContent = `name: Test
|
|
192
|
+
|
|
193
|
+
on: [push, pull_request]
|
|
194
|
+
|
|
195
|
+
jobs:
|
|
196
|
+
test:
|
|
197
|
+
runs-on: ubuntu-latest
|
|
198
|
+
steps:
|
|
199
|
+
- uses: actions/checkout@v4
|
|
200
|
+
- uses: actions/setup-node@v4
|
|
201
|
+
with:
|
|
202
|
+
node-version: 22
|
|
203
|
+
- run: npm install
|
|
204
|
+
- run: npm test
|
|
205
|
+
`;
|
|
206
|
+
await fs.writeFile(path.join(resolvedDir, '.github', 'workflows', 'test.yml'), ciContent);
|
|
207
|
+
files.push('.github/workflows/test.yml');
|
|
208
|
+
|
|
209
|
+
// 5. README.md
|
|
210
|
+
const readmeContent = `# zapwebp-${archetype}-${name}
|
|
211
|
+
|
|
212
|
+
> Zapwebp ${archetype} plugin for ${name} by ${author}.
|
|
213
|
+
|
|
214
|
+
## Installation
|
|
215
|
+
|
|
216
|
+
\`\`\`bash
|
|
217
|
+
npm install zapwebp-${archetype}-${name}
|
|
218
|
+
\`\`\`
|
|
219
|
+
|
|
220
|
+
## Testing
|
|
221
|
+
|
|
222
|
+
\`\`\`bash
|
|
223
|
+
npm test
|
|
224
|
+
\`\`\`
|
|
225
|
+
`;
|
|
226
|
+
await fs.writeFile(path.join(resolvedDir, 'README.md'), readmeContent);
|
|
227
|
+
files.push('README.md');
|
|
228
|
+
|
|
229
|
+
return { targetDir: resolvedDir, files };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
scaffoldProject,
|
|
234
|
+
ARCHETYPES,
|
|
235
|
+
};
|