rw-elements-tools 1.2.0 → 1.3.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/bin/cli.js +20 -14
- package/build-properties.js +19 -10
- package/build-shared-hooks.js +17 -9
- 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
|
@@ -306,7 +306,7 @@ function processNestedGlobalControls(control) {
|
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
308
|
* Processes 'use' key references in a property, replacing them with
|
|
309
|
-
* the referenced Property definition from
|
|
309
|
+
* the referenced Property definition from properties/.
|
|
310
310
|
*
|
|
311
311
|
* @param {Object|Array} property - The property object or array to process.
|
|
312
312
|
* @returns {Object|Array} The property with 'use' keys resolved.
|
|
@@ -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;
|
|
@@ -633,10 +641,11 @@ export async function startWatch(config) {
|
|
|
633
641
|
|
|
634
642
|
// Allow direct execution for backwards compatibility
|
|
635
643
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
636
|
-
// Direct execution: use
|
|
644
|
+
// Direct execution: use ./packs relative to current working directory
|
|
637
645
|
const WATCH = process.argv.includes('--watch') || process.argv.includes('-w');
|
|
638
|
-
const
|
|
639
|
-
const
|
|
646
|
+
const NO_MINIFY = process.argv.includes('--no-minify');
|
|
647
|
+
const defaultPacksDir = path.resolve(process.cwd(), "packs");
|
|
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
|
|
|
@@ -131,13 +132,13 @@ export { transformHook };
|
|
|
131
132
|
|
|
132
133
|
// Use esbuild transform with DCE
|
|
133
134
|
// minifySyntax: true enables dead code elimination
|
|
134
|
-
//
|
|
135
|
+
// When minify=true, also minify whitespace and identifiers
|
|
135
136
|
const result = await transform(combinedSource, {
|
|
136
137
|
loader: 'js',
|
|
137
138
|
target: 'es2018',
|
|
138
|
-
minifySyntax: true,
|
|
139
|
-
minifyWhitespace:
|
|
140
|
-
minifyIdentifiers:
|
|
139
|
+
minifySyntax: true, // Always enable DCE
|
|
140
|
+
minifyWhitespace: minify, // Minify whitespace when minify=true
|
|
141
|
+
minifyIdentifiers: minify, // Minify variable names when minify=true
|
|
141
142
|
format: 'esm',
|
|
142
143
|
legalComments: 'none',
|
|
143
144
|
});
|
|
@@ -147,7 +148,8 @@ export { transformHook };
|
|
|
147
148
|
// Replace ESM export with CommonJS-style assignment
|
|
148
149
|
code = code.replace(/export\s*\{\s*transformHook\s*(as\s+\w+)?\s*\}\s*;?\s*$/m, 'exports.transformHook = transformHook;');
|
|
149
150
|
|
|
150
|
-
|
|
151
|
+
// Only add banner in non-minified mode to save bytes
|
|
152
|
+
const banner = minify ? '' : `// AUTO-GENERATED: do not edit. Edit hooks.source.js instead.\n`;
|
|
151
153
|
|
|
152
154
|
await fs.promises.writeFile(outputPath, banner + code, 'utf8');
|
|
153
155
|
|
|
@@ -159,10 +161,12 @@ export { transformHook };
|
|
|
159
161
|
* @param {Object} config - Configuration object
|
|
160
162
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
161
163
|
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
164
|
+
* @param {boolean} [config.minify=true] - Whether to fully minify the output
|
|
162
165
|
*/
|
|
163
166
|
export async function buildAll(config) {
|
|
164
167
|
const packsDir = config.packsDir;
|
|
165
168
|
const projectRoot = config.projectRoot || path.dirname(packsDir);
|
|
169
|
+
const minify = config.minify !== false; // Default to true
|
|
166
170
|
|
|
167
171
|
const sharedFiles = await listSharedFiles();
|
|
168
172
|
const sources = await findHookSources(packsDir);
|
|
@@ -170,7 +174,7 @@ export async function buildAll(config) {
|
|
|
170
174
|
console.log(`[hooks] Building ${sources.length} component hook(s); shared files: ${sharedFiles.length}`);
|
|
171
175
|
|
|
172
176
|
for (const sourcePath of sources) {
|
|
173
|
-
await buildOne(sharedFiles, sourcePath, projectRoot);
|
|
177
|
+
await buildOne(sharedFiles, sourcePath, projectRoot, minify);
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
console.log(`[hooks] Build complete`);
|
|
@@ -181,6 +185,7 @@ export async function buildAll(config) {
|
|
|
181
185
|
* @param {Object} config - Configuration object
|
|
182
186
|
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
183
187
|
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
188
|
+
* @param {boolean} [config.minify=true] - Whether to fully minify the output
|
|
184
189
|
*/
|
|
185
190
|
export async function startWatch(config) {
|
|
186
191
|
const packsDir = config.packsDir;
|
|
@@ -231,11 +236,14 @@ export async function startWatch(config) {
|
|
|
231
236
|
|
|
232
237
|
// Allow direct execution for backwards compatibility
|
|
233
238
|
if (process.argv[1] === __filename) {
|
|
239
|
+
// Direct execution: use ./packs relative to current working directory
|
|
234
240
|
const WATCH = process.argv.includes('--watch') || process.argv.includes('-w');
|
|
235
|
-
const
|
|
241
|
+
const NO_MINIFY = process.argv.includes('--no-minify');
|
|
242
|
+
const defaultPacksDir = path.resolve(process.cwd(), 'packs');
|
|
236
243
|
const config = {
|
|
237
244
|
packsDir: defaultPacksDir,
|
|
238
|
-
projectRoot:
|
|
245
|
+
projectRoot: process.cwd(),
|
|
246
|
+
minify: !NO_MINIFY
|
|
239
247
|
};
|
|
240
248
|
|
|
241
249
|
(async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rw-elements-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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
|
}
|