screw-up 1.8.0 → 1.9.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.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { Logger } from './internal.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
package/dist/cli.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { Logger } from './internal.js';
@@ -1,18 +1,18 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  export declare const name = "screw-up";
12
- export declare const version = "1.8.0";
12
+ export declare const version = "1.9.0";
13
13
  export declare const description = "Simply package metadata inserter on Vite plugin";
14
14
  export declare const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
15
15
  export declare const license = "MIT";
16
16
  export declare const repository_url = "https://github.com/kekyo/screw-up.git";
17
- export declare const git_commit_hash = "da96533e5128033ff7a45d59b1cee39e0e819533";
17
+ export declare const git_commit_hash = "55707baccdf2d4d14a40310e88ad41531c1a8ff0";
18
18
  //# sourceMappingURL=packageMetadata.d.ts.map
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { TagInfo, Version } from './analyzer';
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.9.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
  "use strict";
11
11
  const fs = require("fs/promises");
12
12
  const fs$1 = require("fs");
13
13
  const path = require("path");
14
- const packageMetadata = require("./packageMetadata-BwTlrgAe.cjs");
14
+ const packageMetadata = require("./packageMetadata-BA-kOu7C.cjs");
15
15
  /*!
16
16
  * name: async-primitives
17
17
  * version: 1.2.0
@@ -203,8 +203,9 @@ const insertBannerHeader = (content, banner) => {
203
203
  const sanitizeKey = (key) => {
204
204
  return key.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
205
205
  };
206
- const generateMetadataFile = (metadata, outputKeys) => {
206
+ const generateMetadataFileContent = (metadata, outputKeys) => {
207
207
  const lines = [];
208
+ const exportedIdentifiers = [];
208
209
  lines.push("// This file is auto-generated by screw-up plugin");
209
210
  lines.push("// Do not edit manually");
210
211
  lines.push("");
@@ -214,12 +215,13 @@ const generateMetadataFile = (metadata, outputKeys) => {
214
215
  const sanitizedKey = sanitizeKey(key);
215
216
  const escapedValue = JSON.stringify(value);
216
217
  lines.push(`export const ${sanitizedKey} = ${escapedValue};`);
218
+ exportedIdentifiers.push(sanitizedKey);
217
219
  }
218
220
  }
219
221
  lines.push("");
220
- return lines.join("\n");
222
+ return { content: lines.join("\n"), exportedIdentifiers };
221
223
  };
222
- const generateMetadataTypeFile = (outputKeys) => {
224
+ const generateMetadataTypeFileContent = (outputKeys) => {
223
225
  const lines = [];
224
226
  lines.push("// This file is auto-generated by screw-up plugin");
225
227
  lines.push("// Do not edit manually");
@@ -260,7 +262,7 @@ const screwUp = (options = {}) => {
260
262
  insertMetadataBanner = true
261
263
  } = options;
262
264
  const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
263
- const resolvedOutputMetadataFileTypePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
265
+ const resolvedOutputMetadataTypeFilePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
264
266
  const generateMetadataSourceLocker = createMutex();
265
267
  const loggerPrefix = `${packageMetadata.name}-vite`;
266
268
  let logger = packageMetadata.createConsoleLogger(loggerPrefix);
@@ -291,7 +293,28 @@ const screwUp = (options = {}) => {
291
293
  return false;
292
294
  }
293
295
  };
294
- const generateMetadataSourceFile = async () => {
296
+ const ensureMetadataGitignore = async (metadataSourcePath) => {
297
+ const metadataDirectory = path.dirname(metadataSourcePath);
298
+ const gitignorePath = path.join(metadataDirectory, ".gitignore");
299
+ if (fs$1.existsSync(gitignorePath)) {
300
+ return false;
301
+ }
302
+ try {
303
+ await fs.mkdir(metadataDirectory, { recursive: true });
304
+ const metadataFileName = path.basename(metadataSourcePath);
305
+ const gitignoreContent = `# Auto-generated by screw-up plugin
306
+ ${metadataFileName}
307
+ `;
308
+ await fs.writeFile(gitignorePath, gitignoreContent);
309
+ return true;
310
+ } catch (error) {
311
+ logger.warn(
312
+ `Failed to write .gitignore for metadata source: ${gitignorePath}: ${error}`
313
+ );
314
+ return false;
315
+ }
316
+ };
317
+ const generateMetadataSourceFiles = async () => {
295
318
  const result = await packageMetadata.resolvePackageMetadata(
296
319
  projectRoot,
297
320
  fetchGitMetadata,
@@ -301,25 +324,49 @@ const screwUp = (options = {}) => {
301
324
  metadata = result.metadata;
302
325
  banner = generateBanner(metadata, outputKeys);
303
326
  if (outputMetadataFile) {
304
- const metadataSourceContent = generateMetadataFile(
305
- metadata,
306
- outputMetadataKeys
307
- );
327
+ const { content: metadataSourceContent, exportedIdentifiers } = generateMetadataFileContent(metadata, outputMetadataKeys);
308
328
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
309
- return await writeFileIfChanged(
329
+ const metadataWritten = await writeFileIfChanged(
310
330
  metadataSourcePath,
311
331
  metadataSourceContent,
312
332
  "metadata source file"
313
333
  );
334
+ const metadataTypeContent = generateMetadataTypeFileContent(exportedIdentifiers);
335
+ const metadataTypePath = path.join(
336
+ projectRoot,
337
+ resolvedOutputMetadataTypeFilePath
338
+ );
339
+ const metadataTypeWritten = await writeFileIfChanged(
340
+ metadataTypePath,
341
+ metadataTypeContent,
342
+ "metadata type definition file"
343
+ );
344
+ if (fs$1.existsSync(metadataSourcePath)) {
345
+ const gitignoreWritten = await ensureMetadataGitignore(metadataSourcePath);
346
+ if (gitignoreWritten) {
347
+ logger.info(
348
+ `generateMetadataSourceFile: .gitignore is generated: ${path.join(
349
+ path.dirname(outputMetadataFilePath),
350
+ ".gitignore"
351
+ )}`
352
+ );
353
+ }
354
+ }
355
+ if (metadataTypeWritten) {
356
+ logger.info(
357
+ `generateMetadataSourceFile: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
358
+ );
359
+ }
360
+ return metadataWritten || metadataTypeWritten;
314
361
  }
315
362
  return false;
316
363
  };
317
- const generateMetadataTypeDefinitionFile = async () => {
364
+ const generateMetadataTypeDefinitionFileFromKeys = async (keys) => {
318
365
  if (outputMetadataFile) {
319
- const metadataTypeContent = generateMetadataTypeFile(outputMetadataKeys);
366
+ const metadataTypeContent = generateMetadataTypeFileContent(keys);
320
367
  const metadataTypePath = path.join(
321
368
  projectRoot,
322
- resolvedOutputMetadataFileTypePath
369
+ resolvedOutputMetadataTypeFilePath
323
370
  );
324
371
  return await writeFileIfChanged(
325
372
  metadataTypePath,
@@ -329,17 +376,17 @@ const screwUp = (options = {}) => {
329
376
  }
330
377
  return false;
331
378
  };
332
- const generateDummyMetadataFile = async () => {
379
+ const generateMetadataFileFromKeys = async (keys) => {
333
380
  if (outputMetadataFile) {
334
381
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
335
382
  if (!fs$1.existsSync(metadataSourcePath)) {
336
383
  const dummyMetadata = {};
337
- outputMetadataKeys.forEach((key) => {
384
+ keys.forEach((key) => {
338
385
  dummyMetadata[key] = "[Require first build]";
339
386
  });
340
- const dummyContent = generateMetadataFile(
387
+ const { content: dummyContent } = generateMetadataFileContent(
341
388
  dummyMetadata,
342
- outputMetadataKeys
389
+ keys
343
390
  );
344
391
  return await writeFileIfChanged(
345
392
  metadataSourcePath,
@@ -359,12 +406,12 @@ const screwUp = (options = {}) => {
359
406
  applyToEnvironment: async (penv) => {
360
407
  logger.info(`${packageMetadata.version}-${packageMetadata.git_commit_hash}: Started.`);
361
408
  projectRoot = penv.config.root;
362
- if (projectRoot && await generateMetadataTypeDefinitionFile()) {
409
+ if (projectRoot && await generateMetadataTypeDefinitionFileFromKeys(outputMetadataKeys)) {
363
410
  logger.info(
364
- `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataFileTypePath}`
411
+ `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
365
412
  );
366
413
  }
367
- if (projectRoot && await generateDummyMetadataFile()) {
414
+ if (projectRoot && await generateMetadataFileFromKeys(outputMetadataKeys)) {
368
415
  logger.info(
369
416
  `applyToEnvironment: Dummy metadata source file is generated: ${outputMetadataFilePath}`
370
417
  );
@@ -386,7 +433,7 @@ const screwUp = (options = {}) => {
386
433
  checkWorkingDirectoryStatus,
387
434
  logger
388
435
  );
389
- if (await generateMetadataSourceFile()) {
436
+ if (await generateMetadataSourceFiles()) {
390
437
  logger.info(
391
438
  `configResolved: Metadata source file is generated: ${outputMetadataFilePath}`
392
439
  );
@@ -408,7 +455,7 @@ const screwUp = (options = {}) => {
408
455
  `configureServer: Excluded from watcher: ${outputMetadataFilePath}`
409
456
  );
410
457
  }
411
- if (await generateMetadataSourceFile()) {
458
+ if (await generateMetadataSourceFiles()) {
412
459
  logger.info(
413
460
  `configureServer: Metadata source file is generated: ${outputMetadataFilePath}`
414
461
  );
@@ -423,7 +470,7 @@ const screwUp = (options = {}) => {
423
470
  const l = await generateMetadataSourceLocker.lock();
424
471
  try {
425
472
  logger.debug(`buildStart: Started.`);
426
- if (await generateMetadataSourceFile()) {
473
+ if (await generateMetadataSourceFiles()) {
427
474
  logger.info(
428
475
  `buildStart: Metadata source file is generated: ${outputMetadataFilePath}`
429
476
  );