rw-elements-tools 1.2.1 → 1.3.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/bin/cli.js +20 -14
- package/build-properties.js +16 -7
- package/build-shared-hooks.js +22 -23
- package/package.json +9 -2
package/bin/cli.js
CHANGED
|
@@ -37,6 +37,7 @@ function parseArgs(args) {
|
|
|
37
37
|
watch: false,
|
|
38
38
|
help: false,
|
|
39
39
|
version: false,
|
|
40
|
+
minify: true, // Minify by default
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -48,6 +49,8 @@ function parseArgs(args) {
|
|
|
48
49
|
result.version = true;
|
|
49
50
|
} else if (arg === '--watch' || arg === '-w') {
|
|
50
51
|
result.watch = true;
|
|
52
|
+
} else if (arg === '--no-minify') {
|
|
53
|
+
result.minify = false;
|
|
51
54
|
} else if (arg === '--packs') {
|
|
52
55
|
result.packs = args[++i];
|
|
53
56
|
} else if (arg.startsWith('--packs=')) {
|
|
@@ -78,6 +81,7 @@ Commands:
|
|
|
78
81
|
Options:
|
|
79
82
|
--packs <dir> Override the packs directory (default: ./packs)
|
|
80
83
|
--watch, -w Watch for changes
|
|
84
|
+
--no-minify Disable minification (output is minified by default)
|
|
81
85
|
--help, -h Show this help message
|
|
82
86
|
--version, -v Show version number
|
|
83
87
|
|
|
@@ -116,32 +120,34 @@ async function showVersion() {
|
|
|
116
120
|
/**
|
|
117
121
|
* Run the properties build
|
|
118
122
|
*/
|
|
119
|
-
async function buildProperties(config, watch = false) {
|
|
120
|
-
console.log(`[rw-build] Building properties${watch ? ' (watch mode)' : ''}...`);
|
|
123
|
+
async function buildProperties(config, watch = false, minify = true) {
|
|
124
|
+
console.log(`[rw-build] Building properties${watch ? ' (watch mode)' : ''}${minify ? '' : ' (no minify)'}...`);
|
|
121
125
|
console.log(`[rw-build] Packs directory: ${config.packsDir}`);
|
|
122
126
|
|
|
127
|
+
const buildConfig = { ...config, minify };
|
|
123
128
|
const buildModule = await import('../build-properties.js');
|
|
124
129
|
|
|
125
130
|
if (watch) {
|
|
126
|
-
await buildModule.startWatch(
|
|
131
|
+
await buildModule.startWatch(buildConfig);
|
|
127
132
|
} else {
|
|
128
|
-
await buildModule.buildProperties(
|
|
133
|
+
await buildModule.buildProperties(buildConfig);
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
/**
|
|
133
138
|
* Run the hooks build
|
|
134
139
|
*/
|
|
135
|
-
async function buildHooks(config, watch = false) {
|
|
136
|
-
console.log(`[rw-build] Building hooks${watch ? ' (watch mode)' : ''}...`);
|
|
140
|
+
async function buildHooks(config, watch = false, minify = true) {
|
|
141
|
+
console.log(`[rw-build] Building hooks${watch ? ' (watch mode)' : ''}${minify ? '' : ' (no minify)'}...`);
|
|
137
142
|
console.log(`[rw-build] Packs directory: ${config.packsDir}`);
|
|
138
143
|
|
|
144
|
+
const buildConfig = { ...config, minify };
|
|
139
145
|
const buildModule = await import('../build-shared-hooks.js');
|
|
140
146
|
|
|
141
147
|
if (watch) {
|
|
142
|
-
await buildModule.startWatch(
|
|
148
|
+
await buildModule.startWatch(buildConfig);
|
|
143
149
|
} else {
|
|
144
|
-
await buildModule.buildAll(
|
|
150
|
+
await buildModule.buildAll(buildConfig);
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
|
|
@@ -174,11 +180,11 @@ async function main() {
|
|
|
174
180
|
try {
|
|
175
181
|
switch (args.command) {
|
|
176
182
|
case 'properties':
|
|
177
|
-
await buildProperties(config, args.watch);
|
|
183
|
+
await buildProperties(config, args.watch, args.minify);
|
|
178
184
|
break;
|
|
179
185
|
|
|
180
186
|
case 'hooks':
|
|
181
|
-
await buildHooks(config, args.watch);
|
|
187
|
+
await buildHooks(config, args.watch, args.minify);
|
|
182
188
|
break;
|
|
183
189
|
|
|
184
190
|
case 'all':
|
|
@@ -186,13 +192,13 @@ async function main() {
|
|
|
186
192
|
// In watch mode, start both watchers concurrently
|
|
187
193
|
// They will both run indefinitely, watching for changes
|
|
188
194
|
await Promise.all([
|
|
189
|
-
buildProperties(config, true),
|
|
190
|
-
buildHooks(config, true),
|
|
195
|
+
buildProperties(config, true, args.minify),
|
|
196
|
+
buildHooks(config, true, args.minify),
|
|
191
197
|
]);
|
|
192
198
|
} else {
|
|
193
199
|
// One-time build: run sequentially
|
|
194
|
-
await buildProperties(config, false);
|
|
195
|
-
await buildHooks(config, false);
|
|
200
|
+
await buildProperties(config, false, args.minify);
|
|
201
|
+
await buildHooks(config, false, args.minify);
|
|
196
202
|
}
|
|
197
203
|
break;
|
|
198
204
|
|
package/build-properties.js
CHANGED
|
@@ -495,8 +495,9 @@ function setupAdvancedGroup(config) {
|
|
|
495
495
|
* Reads and processes a properties.config.json file, generating properties.json.
|
|
496
496
|
*
|
|
497
497
|
* @param {string} configPath - Path to the properties.config.json file.
|
|
498
|
+
* @param {boolean} [minify=true] - Whether to minify the output JSON.
|
|
498
499
|
*/
|
|
499
|
-
async function processConfigFile(configPath) {
|
|
500
|
+
async function processConfigFile(configPath, minify = true) {
|
|
500
501
|
try {
|
|
501
502
|
const fileDir = path.dirname(configPath);
|
|
502
503
|
const configContent = await fs.readFile(configPath, "utf8");
|
|
@@ -511,9 +512,12 @@ async function processConfigFile(configPath) {
|
|
|
511
512
|
properties: group.properties.flatMap(processProperty),
|
|
512
513
|
}));
|
|
513
514
|
|
|
514
|
-
// Write the processed config
|
|
515
|
+
// Write the processed config (minified by default)
|
|
515
516
|
const outputPath = path.join(fileDir, "properties.json");
|
|
516
|
-
|
|
517
|
+
const jsonOutput = minify
|
|
518
|
+
? JSON.stringify(config)
|
|
519
|
+
: JSON.stringify(config, null, 2);
|
|
520
|
+
await fs.writeFile(outputPath, jsonOutput);
|
|
517
521
|
} catch (error) {
|
|
518
522
|
console.error(`Error processing file ${configPath}:`, error);
|
|
519
523
|
}
|
|
@@ -543,8 +547,9 @@ async function processDirectoryIfConfigExists(dirPath) {
|
|
|
543
547
|
* Finds all directories matching a glob pattern and processes their configs.
|
|
544
548
|
*
|
|
545
549
|
* @param {string} packsDir - The packs directory to search.
|
|
550
|
+
* @param {boolean} [minify=true] - Whether to minify the output JSON.
|
|
546
551
|
*/
|
|
547
|
-
async function processAllConfigs(packsDir) {
|
|
552
|
+
async function processAllConfigs(packsDir, minify = true) {
|
|
548
553
|
try {
|
|
549
554
|
const pattern = path.join(packsDir, "**/*.elementsdevpack/components/com.**/**");
|
|
550
555
|
const directories = globSync(pattern, { absolute: true });
|
|
@@ -556,7 +561,7 @@ async function processAllConfigs(packsDir) {
|
|
|
556
561
|
const configPath = path.join(dir, "properties.config.json");
|
|
557
562
|
try {
|
|
558
563
|
await fs.access(configPath);
|
|
559
|
-
await processConfigFile(configPath);
|
|
564
|
+
await processConfigFile(configPath, minify);
|
|
560
565
|
processed++;
|
|
561
566
|
} catch {
|
|
562
567
|
// Config file doesn't exist, skip silently
|
|
@@ -579,10 +584,12 @@ async function processAllConfigs(packsDir) {
|
|
|
579
584
|
*
|
|
580
585
|
* @param {Object} config - Configuration object from resolveConfig()
|
|
581
586
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
587
|
+
* @param {boolean} [config.minify=true] - Whether to minify the output JSON
|
|
582
588
|
*/
|
|
583
589
|
export async function buildProperties(config) {
|
|
590
|
+
const minify = config.minify !== false; // Default to true
|
|
584
591
|
console.log(`[properties] Building properties...`);
|
|
585
|
-
await processAllConfigs(config.packsDir);
|
|
592
|
+
await processAllConfigs(config.packsDir, minify);
|
|
586
593
|
console.log(`[properties] Build complete`);
|
|
587
594
|
}
|
|
588
595
|
|
|
@@ -590,6 +597,7 @@ export async function buildProperties(config) {
|
|
|
590
597
|
* Starts watch mode for continuous building of properties
|
|
591
598
|
* @param {Object} config - Configuration object
|
|
592
599
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
600
|
+
* @param {boolean} [config.minify=true] - Whether to minify the output JSON
|
|
593
601
|
*/
|
|
594
602
|
export async function startWatch(config) {
|
|
595
603
|
const packsDir = config.packsDir;
|
|
@@ -635,8 +643,9 @@ export async function startWatch(config) {
|
|
|
635
643
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
636
644
|
// Direct execution: use ./packs relative to current working directory
|
|
637
645
|
const WATCH = process.argv.includes('--watch') || process.argv.includes('-w');
|
|
646
|
+
const NO_MINIFY = process.argv.includes('--no-minify');
|
|
638
647
|
const defaultPacksDir = path.resolve(process.cwd(), "packs");
|
|
639
|
-
const config = { packsDir: defaultPacksDir };
|
|
648
|
+
const config = { packsDir: defaultPacksDir, minify: !NO_MINIFY };
|
|
640
649
|
|
|
641
650
|
(async () => {
|
|
642
651
|
try {
|
package/build-shared-hooks.js
CHANGED
|
@@ -101,8 +101,9 @@ async function findHookSources(startDir) {
|
|
|
101
101
|
* @param {string[]} sharedFiles - Array of shared hook file paths
|
|
102
102
|
* @param {string} sourcePath - Path to the hooks.source.js file
|
|
103
103
|
* @param {string} projectRoot - Project root for relative path display
|
|
104
|
+
* @param {boolean} [minify=true] - Whether to fully minify the output
|
|
104
105
|
*/
|
|
105
|
-
async function buildOne(sharedFiles, sourcePath, projectRoot) {
|
|
106
|
+
async function buildOne(sharedFiles, sourcePath, projectRoot, minify = true) {
|
|
106
107
|
const componentDir = path.dirname(sourcePath);
|
|
107
108
|
const outputPath = path.join(componentDir, OUTPUT_FILENAME);
|
|
108
109
|
|
|
@@ -115,41 +116,34 @@ async function buildOne(sharedFiles, sourcePath, projectRoot) {
|
|
|
115
116
|
|
|
116
117
|
// Read the component source
|
|
117
118
|
let componentContent = await fs.promises.readFile(sourcePath, 'utf8');
|
|
119
|
+
const hasExportLine = /exports\.transformHook\s*=/.test(componentContent);
|
|
118
120
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
+
// Ensure the expected CommonJS export is present exactly once
|
|
122
|
+
if (!hasExportLine) {
|
|
123
|
+
componentContent = `${componentContent.trim()}\nexports.transformHook = transformHook;`;
|
|
124
|
+
}
|
|
121
125
|
|
|
122
|
-
// Concatenate everything
|
|
123
|
-
// esbuild will keep transformHook and anything it references, drop the rest
|
|
126
|
+
// Concatenate everything
|
|
124
127
|
const combinedSource = `
|
|
125
128
|
${sharedPieces.join('\n\n')}
|
|
126
129
|
|
|
127
130
|
${componentContent}
|
|
128
|
-
|
|
129
|
-
export { transformHook };
|
|
130
131
|
`;
|
|
131
132
|
|
|
132
|
-
//
|
|
133
|
-
// minifySyntax: true enables dead code elimination
|
|
134
|
-
// We keep identifiers and whitespace for readable output
|
|
133
|
+
// Minify whitespace only (keep identifier names); enable syntax minification for small size
|
|
135
134
|
const result = await transform(combinedSource, {
|
|
136
135
|
loader: 'js',
|
|
137
136
|
target: 'es2018',
|
|
138
|
-
minifySyntax:
|
|
139
|
-
minifyWhitespace:
|
|
140
|
-
minifyIdentifiers: false,
|
|
141
|
-
format: '
|
|
137
|
+
minifySyntax: minify,
|
|
138
|
+
minifyWhitespace: minify,
|
|
139
|
+
minifyIdentifiers: false,
|
|
140
|
+
format: 'cjs',
|
|
142
141
|
legalComments: 'none',
|
|
143
142
|
});
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// Replace ESM export with CommonJS-style assignment
|
|
148
|
-
code = code.replace(/export\s*\{\s*transformHook\s*(as\s+\w+)?\s*\}\s*;?\s*$/m, 'exports.transformHook = transformHook;');
|
|
149
|
-
|
|
150
|
-
const banner = `// AUTO-GENERATED: do not edit. Edit hooks.source.js instead.\n`;
|
|
144
|
+
const banner = minify ? '' : `// AUTO-GENERATED: do not edit. Edit hooks.source.js instead.\n`;
|
|
151
145
|
|
|
152
|
-
await fs.promises.writeFile(outputPath, banner + code, 'utf8');
|
|
146
|
+
await fs.promises.writeFile(outputPath, banner + result.code, 'utf8');
|
|
153
147
|
|
|
154
148
|
console.log(`[hooks] Wrote ${path.relative(projectRoot, outputPath)}`);
|
|
155
149
|
}
|
|
@@ -159,10 +153,12 @@ export { transformHook };
|
|
|
159
153
|
* @param {Object} config - Configuration object
|
|
160
154
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
161
155
|
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
156
|
+
* @param {boolean} [config.minify=true] - Whether to fully minify the output
|
|
162
157
|
*/
|
|
163
158
|
export async function buildAll(config) {
|
|
164
159
|
const packsDir = config.packsDir;
|
|
165
160
|
const projectRoot = config.projectRoot || path.dirname(packsDir);
|
|
161
|
+
const minify = config.minify !== false; // Default to true
|
|
166
162
|
|
|
167
163
|
const sharedFiles = await listSharedFiles();
|
|
168
164
|
const sources = await findHookSources(packsDir);
|
|
@@ -170,7 +166,7 @@ export async function buildAll(config) {
|
|
|
170
166
|
console.log(`[hooks] Building ${sources.length} component hook(s); shared files: ${sharedFiles.length}`);
|
|
171
167
|
|
|
172
168
|
for (const sourcePath of sources) {
|
|
173
|
-
await buildOne(sharedFiles, sourcePath, projectRoot);
|
|
169
|
+
await buildOne(sharedFiles, sourcePath, projectRoot, minify);
|
|
174
170
|
}
|
|
175
171
|
|
|
176
172
|
console.log(`[hooks] Build complete`);
|
|
@@ -181,6 +177,7 @@ export async function buildAll(config) {
|
|
|
181
177
|
* @param {Object} config - Configuration object
|
|
182
178
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
183
179
|
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
180
|
+
* @param {boolean} [config.minify=true] - Whether to fully minify the output
|
|
184
181
|
*/
|
|
185
182
|
export async function startWatch(config) {
|
|
186
183
|
const packsDir = config.packsDir;
|
|
@@ -233,10 +230,12 @@ export async function startWatch(config) {
|
|
|
233
230
|
if (process.argv[1] === __filename) {
|
|
234
231
|
// Direct execution: use ./packs relative to current working directory
|
|
235
232
|
const WATCH = process.argv.includes('--watch') || process.argv.includes('-w');
|
|
233
|
+
const NO_MINIFY = process.argv.includes('--no-minify');
|
|
236
234
|
const defaultPacksDir = path.resolve(process.cwd(), 'packs');
|
|
237
235
|
const config = {
|
|
238
236
|
packsDir: defaultPacksDir,
|
|
239
|
-
projectRoot: process.cwd()
|
|
237
|
+
projectRoot: process.cwd(),
|
|
238
|
+
minify: !NO_MINIFY
|
|
240
239
|
};
|
|
241
240
|
|
|
242
241
|
(async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rw-elements-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Build tools for RapidWeaver Elements packs - generates properties.json and hooks.js files",
|
|
5
5
|
"author": "Elements Platform",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,6 +50,13 @@
|
|
|
50
50
|
"lodash": "^4.17.21"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prepublishOnly": "echo 'Ready to publish rw-elements-tools'"
|
|
53
|
+
"prepublishOnly": "echo 'Ready to publish rw-elements-tools'",
|
|
54
|
+
"docs:generate": "node scripts/generate-docs.js",
|
|
55
|
+
"docs:publish": "node scripts/publish-docs.js",
|
|
56
|
+
"docs": "npm run docs:generate && npm run docs:publish"
|
|
57
|
+
},
|
|
58
|
+
"rw-elements-tools": {
|
|
59
|
+
"docsRepoPath": "/Users/ben/Developer/rapidweaver-elements-docs-api",
|
|
60
|
+
"docsTargetDir": "development-resources/build-tools"
|
|
54
61
|
}
|
|
55
62
|
}
|