ember-tribe 2.6.6 → 2.6.7
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.
|
@@ -109,7 +109,7 @@ function parseHbsFile(filePath) {
|
|
|
109
109
|
const helpers = [...helpersSet];
|
|
110
110
|
|
|
111
111
|
const modifiersSet = new Set(
|
|
112
|
-
[...src.matchAll(/\{\{([\w-]+-modifier|
|
|
112
|
+
[...src.matchAll(/\{\{([\w-]+-modifier|tooltip|[\w-]+)\s/g)]
|
|
113
113
|
.map(([, name]) => name)
|
|
114
114
|
.filter((n) => !helpers.includes(n) && !builtinHelpers.has(n))
|
|
115
115
|
);
|
|
@@ -199,6 +199,65 @@ function buildTypes(routes, components) {
|
|
|
199
199
|
return [...typeMap.entries()].map(([slug, used_in]) => ({ slug, used_in }));
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
function compactJSON(value, indent = 2) {
|
|
203
|
+
function isLeafArray(arr) {
|
|
204
|
+
if (!Array.isArray(arr) || arr.length === 0) return false;
|
|
205
|
+
return arr.every((item) => {
|
|
206
|
+
if (typeof item === 'string') return true;
|
|
207
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
208
|
+
const keys = Object.keys(item);
|
|
209
|
+
return keys.length === 1 && typeof item[keys[0]] === 'string';
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function serialize(val, depth) {
|
|
216
|
+
const pad = ' '.repeat(indent * depth);
|
|
217
|
+
const childPad = ' '.repeat(indent * (depth + 1));
|
|
218
|
+
|
|
219
|
+
if (val === null) return 'null';
|
|
220
|
+
if (typeof val !== 'object') return JSON.stringify(val);
|
|
221
|
+
|
|
222
|
+
if (Array.isArray(val)) {
|
|
223
|
+
if (val.length === 0) return '[]';
|
|
224
|
+
if (isLeafArray(val)) {
|
|
225
|
+
const items = val.map((item) => {
|
|
226
|
+
if (typeof item === 'string') return JSON.stringify(item);
|
|
227
|
+
const k = Object.keys(item)[0];
|
|
228
|
+
return `{ ${JSON.stringify(k)}: ${JSON.stringify(item[k])} }`;
|
|
229
|
+
});
|
|
230
|
+
return '[' + items.join(', ') + ']';
|
|
231
|
+
}
|
|
232
|
+
const items = val.map((item) => childPad + serialize(item, depth + 1));
|
|
233
|
+
return '[\n' + items.join(',\n') + '\n' + pad + ']';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const keys = Object.keys(val);
|
|
237
|
+
if (keys.length === 0) return '{}';
|
|
238
|
+
const entries = keys.map((k) => childPad + JSON.stringify(k) + ': ' + serialize(val[k], depth + 1));
|
|
239
|
+
return '{\n' + entries.join(',\n') + '\n' + pad + '}';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return serialize(value, 0);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function stripEmpty(obj) {
|
|
246
|
+
if (Array.isArray(obj)) {
|
|
247
|
+
return obj.map(stripEmpty);
|
|
248
|
+
}
|
|
249
|
+
if (obj !== null && typeof obj === 'object') {
|
|
250
|
+
const out = {};
|
|
251
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
252
|
+
if (Array.isArray(v) && v.length === 0) continue;
|
|
253
|
+
if (v !== null && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) continue;
|
|
254
|
+
out[k] = stripEmpty(v);
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
return obj;
|
|
259
|
+
}
|
|
260
|
+
|
|
202
261
|
function mergeByKey(existing, scanned, key) {
|
|
203
262
|
const existingMap = new Map(existing.map((e) => [e[key], e]));
|
|
204
263
|
const scannedMap = new Map(scanned.map((s) => [s[key], s]));
|
|
@@ -217,11 +276,11 @@ function mergeByKey(existing, scanned, key) {
|
|
|
217
276
|
const outputFile = path.join(configDir, 'storylang.json');
|
|
218
277
|
|
|
219
278
|
if (!fs.existsSync(appDir)) {
|
|
220
|
-
console.error(`Could not find app/ directory at ${appDir}. Make sure you are running from the
|
|
279
|
+
console.error(`Could not find app/ directory at ${appDir}. Make sure you are running from the folder of your Ember project.`);
|
|
221
280
|
process.exit(1);
|
|
222
281
|
}
|
|
223
282
|
|
|
224
|
-
console.log('
|
|
283
|
+
console.log('Storylang — scanning project files…\n');
|
|
225
284
|
|
|
226
285
|
const components = buildComponents(appDir);
|
|
227
286
|
const routes = buildRoutes(appDir);
|
|
@@ -245,7 +304,7 @@ function mergeByKey(existing, scanned, key) {
|
|
|
245
304
|
};
|
|
246
305
|
|
|
247
306
|
if (!fs.existsSync(configDir)) fs.mkdirSync(configDir, { recursive: true });
|
|
248
|
-
fs.writeFileSync(outputFile,
|
|
307
|
+
fs.writeFileSync(outputFile, compactJSON(stripEmpty(merged)) + '\n', 'utf8');
|
|
249
308
|
|
|
250
309
|
console.log(`✅ config/storylang.json updated`);
|
|
251
310
|
console.log(` routes: ${routes.length}`);
|