screw-up 0.11.0 → 0.13.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -4
  3. package/dist/analyzer.d.ts +13 -1
  4. package/dist/analyzer.d.ts.map +1 -1
  5. package/dist/cli-internal.d.ts +32 -7
  6. package/dist/cli-internal.d.ts.map +1 -1
  7. package/dist/cli.d.ts +12 -2
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/generated/packageMetadata.d.ts +18 -0
  10. package/dist/generated/packageMetadata.d.ts.map +1 -0
  11. package/dist/index.cjs +20 -3
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +10 -1
  14. package/dist/index.js +20 -3
  15. package/dist/index.js.map +1 -1
  16. package/dist/{internal--D7IlmDn.cjs → internal-BHSe5LIZ.cjs} +424 -320
  17. package/dist/internal-BHSe5LIZ.cjs.map +1 -0
  18. package/dist/{internal-D-ECO0sh.js → internal-BgCvktPU.js} +425 -321
  19. package/dist/internal-BgCvktPU.js.map +1 -0
  20. package/dist/internal.d.ts +82 -10
  21. package/dist/internal.d.ts.map +1 -1
  22. package/dist/main.cjs +1166 -0
  23. package/dist/main.cjs.map +1 -0
  24. package/dist/main.d.ts +13 -0
  25. package/dist/main.d.ts.map +1 -0
  26. package/dist/main.js +1165 -0
  27. package/dist/main.js.map +1 -0
  28. package/dist/packageMetadata-DLfWvbn3.cjs +20 -0
  29. package/dist/packageMetadata-DLfWvbn3.cjs.map +1 -0
  30. package/dist/packageMetadata-Dm-0ihYZ.js +20 -0
  31. package/dist/packageMetadata-Dm-0ihYZ.js.map +1 -0
  32. package/dist/types.d.ts +15 -0
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/vite-plugin.d.ts +10 -1
  35. package/dist/vite-plugin.d.ts.map +1 -1
  36. package/images/screw-up-120.png +0 -0
  37. package/package.json +13 -14
  38. package/README_pack.md +0 -63
  39. package/dist/cli.cjs +0 -736
  40. package/dist/cli.cjs.map +0 -1
  41. package/dist/cli.js +0 -735
  42. package/dist/cli.js.map +0 -1
  43. package/dist/internal--D7IlmDn.cjs.map +0 -1
  44. package/dist/internal-D-ECO0sh.js.map +0 -1
package/dist/cli.cjs DELETED
@@ -1,736 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- const path = require("path");
4
- const fs = require("fs");
5
- const promises = require("fs/promises");
6
- const child_process = require("child_process");
7
- const glob = require("glob");
8
- const stream = require("stream");
9
- const zlib = require("zlib");
10
- const internal = require("./internal--D7IlmDn.cjs");
11
- /*!
12
- * name: tar-vern
13
- * version: 0.3.0
14
- * description: Tape archiver library for Typescript
15
- * author: Kouji Matsui (@kekyo@mi.kekyo.net)
16
- * license: MIT
17
- * repository.url: https://github.com/kekyo/tar-vern.git
18
- */
19
- const getUName = (candidateName, candidateId, reflectStat) => {
20
- return "root";
21
- };
22
- const getBuffer = (data) => {
23
- return Buffer.isBuffer(data) ? data : Buffer.from(data, "utf8");
24
- };
25
- const createFileItem = async (path2, content, options) => {
26
- var _a, _b, _c, _d, _e, _f;
27
- const mode = (_a = options == null ? void 0 : options.mode) != null ? _a : 420;
28
- const uid = (_b = options == null ? void 0 : options.uid) != null ? _b : 0;
29
- const gid = (_c = options == null ? void 0 : options.gid) != null ? _c : 0;
30
- const date = (_d = options == null ? void 0 : options.date) != null ? _d : /* @__PURE__ */ new Date();
31
- const uname = (_e = options == null ? void 0 : options.uname) != null ? _e : "root";
32
- const gname = (_f = options == null ? void 0 : options.gname) != null ? _f : "root";
33
- return {
34
- kind: "file",
35
- path: path2,
36
- mode,
37
- uname,
38
- gname,
39
- uid,
40
- gid,
41
- date,
42
- content
43
- };
44
- };
45
- const createReadableFileItem = async (path2, readable, options) => {
46
- var _a, _b, _c, _d, _e, _f;
47
- const mode = (_a = options == null ? void 0 : options.mode) != null ? _a : 420;
48
- const uid = (_b = options == null ? void 0 : options.uid) != null ? _b : 0;
49
- const gid = (_c = options == null ? void 0 : options.gid) != null ? _c : 0;
50
- const date = (_d = options == null ? void 0 : options.date) != null ? _d : /* @__PURE__ */ new Date();
51
- const uname = (_e = options == null ? void 0 : options.uname) != null ? _e : "root";
52
- const gname = (_f = options == null ? void 0 : options.gname) != null ? _f : "root";
53
- let length = options == null ? void 0 : options.length;
54
- if (!length) {
55
- const chunks = [];
56
- length = 0;
57
- for await (const chunk of readable) {
58
- const buffer = getBuffer(chunk);
59
- chunks.push(buffer);
60
- length += buffer.length;
61
- }
62
- return {
63
- kind: "file",
64
- path: path2,
65
- mode,
66
- uname,
67
- gname,
68
- uid,
69
- gid,
70
- date,
71
- content: {
72
- kind: "readable",
73
- length,
74
- readable: stream.Readable.from(chunks)
75
- }
76
- };
77
- } else {
78
- return {
79
- kind: "file",
80
- path: path2,
81
- mode,
82
- uname,
83
- gname,
84
- uid,
85
- gid,
86
- date,
87
- content: {
88
- kind: "readable",
89
- length,
90
- readable
91
- }
92
- };
93
- }
94
- };
95
- const createReadFileItem = async (path2, filePath, reflectStat, options) => {
96
- const stats = await promises.stat(filePath);
97
- const reader = fs.createReadStream(filePath);
98
- const mode = stats.mode;
99
- const uid = stats.uid;
100
- const gid = stats.gid;
101
- const date = stats.mtime;
102
- const uname = getUName(options == null ? void 0 : options.uname, stats.uid);
103
- const gname = getUName(options == null ? void 0 : options.gname, stats.gid);
104
- return await createReadableFileItem(path2, reader, {
105
- length: stats.size,
106
- mode,
107
- uname,
108
- gname,
109
- uid,
110
- gid,
111
- date
112
- });
113
- };
114
- const storeReaderToFile = (reader, path2) => {
115
- const writer = fs.createWriteStream(path2);
116
- reader.pipe(writer);
117
- return new Promise((res, rej) => {
118
- writer.on("finish", res);
119
- writer.on("error", rej);
120
- reader.on("error", rej);
121
- });
122
- };
123
- const utf8ByteLength = (str) => {
124
- return Buffer.byteLength(str, "utf8");
125
- };
126
- const truncateUtf8Safe = (str, maxBytes) => {
127
- let total = 0;
128
- let i = 0;
129
- while (i < str.length) {
130
- const codePoint = str.codePointAt(i);
131
- const char = String.fromCodePoint(codePoint);
132
- const charBytes = Buffer.byteLength(char, "utf8");
133
- if (total + charBytes > maxBytes) break;
134
- total += charBytes;
135
- i += char.length;
136
- }
137
- return str.slice(0, i);
138
- };
139
- const MAX_NAME = 100;
140
- const MAX_PREFIX = 155;
141
- const splitPath = (path2) => {
142
- var _a;
143
- if (utf8ByteLength(path2) <= MAX_NAME) {
144
- return { prefix: "", name: path2 };
145
- }
146
- const parts = path2.split("/");
147
- let name = (_a = parts.pop()) != null ? _a : "";
148
- let prefix = parts.join("/");
149
- if (utf8ByteLength(name) > MAX_NAME) {
150
- name = truncateUtf8Safe(name, MAX_NAME);
151
- }
152
- while (utf8ByteLength(prefix) > MAX_PREFIX) {
153
- prefix = truncateUtf8Safe(prefix, MAX_PREFIX);
154
- }
155
- return { prefix, name };
156
- };
157
- const getOctalBytes = (value, length) => {
158
- const str = value.toString(8).padStart(length - 1, "0") + "\0";
159
- return Buffer.from(str, "ascii");
160
- };
161
- const getPaddedBytes = (buffer) => {
162
- const extra = buffer.length % 512;
163
- if (extra === 0) {
164
- return buffer;
165
- } else {
166
- return Buffer.concat([buffer, Buffer.alloc(512 - extra, 0)]);
167
- }
168
- };
169
- const terminatorBytes = Buffer.alloc(1024, 0);
170
- const createTarHeader = (type, path2, size, mode, uname, gname, uid, gid, date) => {
171
- const buffer = Buffer.alloc(512, 0);
172
- const { name, prefix } = splitPath(path2);
173
- buffer.write(name, 0, 100, "utf8");
174
- getOctalBytes(mode & 4095, 8).copy(buffer, 100);
175
- getOctalBytes(uid, 8).copy(buffer, 108);
176
- getOctalBytes(gid, 8).copy(buffer, 116);
177
- getOctalBytes(size, 12).copy(buffer, 124);
178
- getOctalBytes(Math.floor(date.getTime() / 1e3), 12).copy(buffer, 136);
179
- Buffer.from(" ", "ascii").copy(buffer, 148);
180
- if (type === "file") {
181
- buffer.write("0", 156, 1, "ascii");
182
- } else {
183
- buffer.write("5", 156, 1, "ascii");
184
- }
185
- buffer.write("ustar\0", 257, 6, "ascii");
186
- buffer.write("00", 263, 2, "ascii");
187
- buffer.write(uname, 265, 32, "utf8");
188
- buffer.write(gname, 297, 32, "utf8");
189
- buffer.write(prefix, 345, 155, "utf8");
190
- let sum = 0;
191
- for (let i = 0; i < 512; i++) {
192
- sum += buffer[i];
193
- }
194
- getOctalBytes(sum, 8).copy(buffer, 148);
195
- return buffer;
196
- };
197
- const createTarPacker = (entryItemGenerator, compressionType, signal) => {
198
- const entryItemIterator = async function* () {
199
- for await (const entryItem of entryItemGenerator) {
200
- switch (entryItem.kind) {
201
- case "file": {
202
- const entryItemContent = entryItem.content;
203
- if (typeof entryItemContent === "string" || Buffer.isBuffer(entryItemContent)) {
204
- const contentBytes = getBuffer(entryItemContent);
205
- const tarHeaderBytes = createTarHeader(
206
- "file",
207
- entryItem.path,
208
- contentBytes.length,
209
- entryItem.mode,
210
- entryItem.uname,
211
- entryItem.gname,
212
- entryItem.uid,
213
- entryItem.gid,
214
- entryItem.date
215
- );
216
- yield tarHeaderBytes;
217
- const totalPaddedContentBytes = getPaddedBytes(contentBytes);
218
- yield totalPaddedContentBytes;
219
- } else {
220
- const tarHeaderBytes = createTarHeader(
221
- "file",
222
- entryItem.path,
223
- entryItemContent.length,
224
- entryItem.mode,
225
- entryItem.uname,
226
- entryItem.gname,
227
- entryItem.uid,
228
- entryItem.gid,
229
- entryItem.date
230
- );
231
- yield tarHeaderBytes;
232
- let position = 0;
233
- switch (entryItemContent.kind) {
234
- case "generator": {
235
- for await (const contentBytes of entryItemContent.generator) {
236
- yield contentBytes;
237
- position += contentBytes.length;
238
- }
239
- break;
240
- }
241
- case "readable": {
242
- for await (const content of entryItemContent.readable) {
243
- const contentBytes = getBuffer(content);
244
- yield contentBytes;
245
- position += contentBytes.length;
246
- }
247
- break;
248
- }
249
- }
250
- if (position % 512 !== 0) {
251
- yield Buffer.alloc(512 - position % 512, 0);
252
- }
253
- }
254
- break;
255
- }
256
- case "directory": {
257
- const tarHeaderBytes = createTarHeader(
258
- "directory",
259
- entryItem.path,
260
- 0,
261
- entryItem.mode,
262
- entryItem.uname,
263
- entryItem.gname,
264
- entryItem.uid,
265
- entryItem.gid,
266
- entryItem.date
267
- );
268
- yield tarHeaderBytes;
269
- break;
270
- }
271
- }
272
- }
273
- yield terminatorBytes;
274
- };
275
- const ct = compressionType;
276
- switch (ct) {
277
- case "none": {
278
- return stream.Readable.from(entryItemIterator());
279
- }
280
- case "gzip": {
281
- const gzipStream = zlib.createGzip({ level: 9 });
282
- const entryItemStream = stream.Readable.from(entryItemIterator());
283
- entryItemStream.pipe(gzipStream);
284
- return gzipStream;
285
- }
286
- }
287
- };
288
- const createPackEntryGenerator = async function* (targetDir, resolvedPackageJson, readmeReplacementPath) {
289
- var _a;
290
- const packageJsonContent = JSON.stringify(resolvedPackageJson, null, 2);
291
- yield await createFileItem("package/package.json", packageJsonContent);
292
- const distributionFileGlobs = (_a = resolvedPackageJson == null ? void 0 : resolvedPackageJson.files) != null ? _a : ["**/*"];
293
- const packingFilePaths = (await Promise.all(
294
- distributionFileGlobs.map(async (pattern) => {
295
- const fullPath = path.resolve(targetDir, pattern);
296
- try {
297
- if (fs.existsSync(fullPath) && (await promises.lstat(fullPath)).isDirectory()) {
298
- return await glob.glob(`${pattern}/**/*`, { cwd: targetDir });
299
- }
300
- return await glob.glob(pattern, { cwd: targetDir });
301
- } catch (error) {
302
- return await glob.glob(pattern, { cwd: targetDir });
303
- }
304
- })
305
- )).flat();
306
- for (const packingFilePath of packingFilePaths) {
307
- if (packingFilePath !== "package.json") {
308
- const fullPath = path.resolve(targetDir, packingFilePath);
309
- const stat = await promises.lstat(fullPath);
310
- if (stat.isFile()) {
311
- if (packingFilePath === "README.md" && readmeReplacementPath) {
312
- yield await createReadFileItem("package/README.md", readmeReplacementPath);
313
- } else {
314
- yield await createReadFileItem(`package/${packingFilePath}`, fullPath);
315
- }
316
- }
317
- }
318
- }
319
- if (readmeReplacementPath && !packingFilePaths.includes("README.md")) {
320
- yield await createReadFileItem("package/README.md", readmeReplacementPath);
321
- }
322
- };
323
- const packAssets = async (targetDir, outputDir, checkWorkingDirectoryStatus, inheritableFields, readmeReplacementPath) => {
324
- var _a, _b, _c, _d;
325
- if (!fs.existsSync(targetDir)) {
326
- return void 0;
327
- }
328
- let result;
329
- try {
330
- result = await internal.resolveRawPackageJsonObject(
331
- targetDir,
332
- checkWorkingDirectoryStatus,
333
- inheritableFields
334
- );
335
- } catch (error) {
336
- return void 0;
337
- }
338
- const { packageJson: resolvedPackageJson, sourceMap } = result;
339
- if (resolvedPackageJson == null ? void 0 : resolvedPackageJson.private) {
340
- return void 0;
341
- }
342
- let finalReadmeReplacementPath = readmeReplacementPath;
343
- if (!finalReadmeReplacementPath && (resolvedPackageJson == null ? void 0 : resolvedPackageJson.readme)) {
344
- const readmeSourceDir = (_a = sourceMap.get("readme")) != null ? _a : targetDir;
345
- const packageReadmePath = path.resolve(readmeSourceDir, resolvedPackageJson.readme);
346
- if (fs.existsSync(packageReadmePath)) {
347
- finalReadmeReplacementPath = packageReadmePath;
348
- }
349
- }
350
- if (finalReadmeReplacementPath && !fs.existsSync(finalReadmeReplacementPath)) {
351
- throw new Error(`README replacement file not found: ${finalReadmeReplacementPath}`);
352
- }
353
- const outputFileName = `${(_c = (_b = resolvedPackageJson == null ? void 0 : resolvedPackageJson.name) == null ? void 0 : _b.replace("/", "-")) != null ? _c : "package"}-${(_d = resolvedPackageJson == null ? void 0 : resolvedPackageJson.version) != null ? _d : "0.0.0"}.tgz`;
354
- if (!fs.existsSync(outputDir)) {
355
- await promises.mkdir(outputDir, { recursive: true });
356
- }
357
- const packer = createTarPacker(
358
- createPackEntryGenerator(targetDir, resolvedPackageJson, finalReadmeReplacementPath),
359
- "gzip"
360
- );
361
- const outputFile = path.resolve(outputDir, outputFileName);
362
- await storeReaderToFile(packer, outputFile);
363
- return resolvedPackageJson;
364
- };
365
- const getComputedPackageJsonObject = async (targetDir, checkWorkingDirectoryStatus, inheritableFields) => {
366
- if (!fs.existsSync(targetDir)) {
367
- return void 0;
368
- }
369
- const result = await internal.resolveRawPackageJsonObject(
370
- targetDir,
371
- checkWorkingDirectoryStatus,
372
- inheritableFields
373
- );
374
- return result.packageJson;
375
- };
376
- const parseArgs = (argv) => {
377
- const args = argv.slice(2);
378
- const result = {
379
- positional: [],
380
- options: {}
381
- };
382
- if (args.length === 0) {
383
- return result;
384
- }
385
- if (args[0].startsWith("-")) {
386
- let i2 = 0;
387
- while (i2 < args.length) {
388
- const arg = args[i2];
389
- if (arg.startsWith("--")) {
390
- const optionName = arg.slice(2);
391
- const nextArg = args[i2 + 1];
392
- if (nextArg !== void 0 && !nextArg.startsWith("-")) {
393
- result.options[optionName] = nextArg;
394
- i2 += 2;
395
- } else {
396
- result.options[optionName] = true;
397
- i2 += 1;
398
- }
399
- } else if (arg.startsWith("-")) {
400
- const optionName = arg.slice(1);
401
- result.options[optionName] = true;
402
- i2 += 1;
403
- } else {
404
- result.positional.push(arg);
405
- i2 += 1;
406
- }
407
- }
408
- return result;
409
- }
410
- result.command = args[0];
411
- let i = 1;
412
- while (i < args.length) {
413
- const arg = args[i];
414
- if (arg.startsWith("--")) {
415
- const optionName = arg.slice(2);
416
- const nextArg = args[i + 1];
417
- if (nextArg !== void 0 && !nextArg.startsWith("-")) {
418
- result.options[optionName] = nextArg;
419
- i += 2;
420
- } else {
421
- result.options[optionName] = true;
422
- i += 1;
423
- }
424
- } else if (arg.startsWith("-")) {
425
- const optionName = arg.slice(1);
426
- result.options[optionName] = true;
427
- i += 1;
428
- } else {
429
- result.positional.push(arg);
430
- i += 1;
431
- }
432
- }
433
- return result;
434
- };
435
- const defaultInheritableFields = /* @__PURE__ */ new Set([
436
- "version",
437
- "description",
438
- "author",
439
- "license",
440
- "repository",
441
- "keywords",
442
- "homepage",
443
- "bugs",
444
- "readme"
445
- ]);
446
- const parseInheritableFields = (inheritableFieldsOption) => {
447
- if (typeof inheritableFieldsOption !== "string") {
448
- return defaultInheritableFields;
449
- }
450
- if (!inheritableFieldsOption.trim()) {
451
- return /* @__PURE__ */ new Set();
452
- }
453
- return new Set(inheritableFieldsOption.split(",").map((field) => field.trim()).filter((field) => field.length > 0));
454
- };
455
- const showHelp = () => {
456
- console.log(`screw-up - Easy package metadata inserter CLI [${void 0}]
457
- Copyright (c) ${"Kouji Matsui (@kekyo@mi.kekyo.net)"}
458
- Repository: ${"https://github.com/kekyo/screw-up.git"}
459
- License: ${"MIT"}
460
-
461
- Usage: screw-up <command> [options]
462
-
463
- Commands:
464
- pack [directory] Pack the project into a tar archive
465
- publish [directory|package.tgz] Publish the project
466
- dump [directory] Dump computed package.json as JSON
467
-
468
- Options:
469
- -h, --help Show help
470
-
471
- Pack Options:
472
- --pack-destination <path> Directory to write the tarball
473
- --readme <path> Replace README.md with specified file
474
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent (default: version,description,author,license,repository,keywords,homepage,bugs,readme)
475
- --no-wds Do not check working directory status to increase version
476
-
477
- Publish Options:
478
- All npm publish options are supported (e.g., --dry-run, --tag, --access, --registry)
479
-
480
- Examples:
481
- screw-up pack # Pack current directory
482
- screw-up pack ./my-project # Pack specific directory
483
- screw-up pack --pack-destination ./dist # Pack to specific output directory
484
- screw-up pack --readme ./README_pack.md # Pack with custom README
485
- screw-up publish # Publish current directory
486
- screw-up publish ./my-project # Publish specific directory
487
- screw-up publish package.tgz # Publish existing tarball
488
- screw-up publish --dry-run --tag beta # Publish with npm options
489
- `);
490
- };
491
- const showPackHelp = () => {
492
- console.log(`Usage: screw-up pack [options] [directory]
493
-
494
- Pack the project into a tar archive
495
-
496
- Arguments:
497
- directory Directory to pack (default: current directory)
498
-
499
- Options:
500
- --pack-destination <path> Directory to write the tarball
501
- --readme <path> Replace README.md with specified file
502
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent
503
- --no-wds Do not check working directory status to increase version
504
- -h, --help Show help for pack command
505
- `);
506
- };
507
- const showPublishHelp = () => {
508
- console.log(`Usage: screw-up publish [options] [directory|package.tgz]
509
-
510
- Publish the project
511
-
512
- Arguments:
513
- directory|package.tgz Directory to pack and publish, or existing tarball to publish
514
-
515
- Options:
516
- All npm publish options are supported, including:
517
- --dry-run Perform a dry run
518
- --tag <tag> Tag for the published version
519
- --access <access> Access level (public or restricted)
520
- --registry <registry> Registry URL
521
- -h, --help Show help for publish command
522
-
523
- Examples:
524
- screw-up publish # Publish current directory
525
- screw-up publish ./my-project # Publish specific directory
526
- screw-up publish package.tgz # Publish existing tarball
527
- screw-up publish --dry-run --tag beta # Publish with options
528
- `);
529
- };
530
- const packCommand = async (args) => {
531
- if (args.options.help || args.options.h) {
532
- showPackHelp();
533
- return;
534
- }
535
- const directory = args.positional[0];
536
- const packDestination = args.options["pack-destination"];
537
- const readmeOption = args.options["readme"];
538
- const inheritableFieldsOption = args.options["inheritable-fields"];
539
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
540
- const targetDir = path.resolve(directory != null ? directory : process.cwd());
541
- const outputDir = packDestination ? path.resolve(packDestination) : process.cwd();
542
- const readmeReplacementPath = readmeOption ? path.resolve(readmeOption) : void 0;
543
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
544
- console.log(`[screw-up/cli]: pack: Creating archive of ${targetDir}...`);
545
- try {
546
- const metadata = await packAssets(
547
- targetDir,
548
- outputDir,
549
- checkWorkingDirectoryStatus,
550
- inheritableFields,
551
- readmeReplacementPath
552
- );
553
- if (metadata) {
554
- console.log(`[screw-up/cli]: pack: Archive created successfully: ${outputDir}`);
555
- } else {
556
- console.error(`[screw-up/cli]: pack: Unable to find any files to pack: ${targetDir}`);
557
- process.exit(1);
558
- }
559
- } catch (error) {
560
- console.error("[screw-up/cli]: pack: Failed to create archive:", error);
561
- process.exit(1);
562
- }
563
- };
564
- const publishCommand = async (args) => {
565
- if (args.options.help || args.options.h) {
566
- showPublishHelp();
567
- return;
568
- }
569
- const runNpmPublish = async (tarballPath, npmOptions2) => {
570
- console.log(`[screw-up/cli]: publish: Publishing ${tarballPath} to npm...`);
571
- const publishArgs = ["publish", tarballPath, ...npmOptions2];
572
- if (process.env.SCREW_UP_TEST_MODE === "true") {
573
- console.log(`[screw-up/cli]: TEST_MODE: Would execute: npm ${publishArgs.join(" ")}`);
574
- console.log(`[screw-up/cli]: TEST_MODE: Tarball path: ${tarballPath}`);
575
- console.log(`[screw-up/cli]: TEST_MODE: Options: ${npmOptions2.join(" ")}`);
576
- console.log(`[screw-up/cli]: publish: Successfully published ${tarballPath}`);
577
- return;
578
- }
579
- const npmProcess = child_process.spawn("npm", publishArgs, { stdio: "inherit" });
580
- return new Promise((resolve2, reject) => {
581
- npmProcess.on("close", (code) => {
582
- if (code === 0) {
583
- console.log(`[screw-up/cli]: publish: Successfully published ${tarballPath}`);
584
- resolve2();
585
- } else {
586
- reject(new Error(`npm publish failed with exit code ${code}`));
587
- }
588
- });
589
- npmProcess.on("error", reject);
590
- });
591
- };
592
- const path$1 = args.positional[0];
593
- const inheritableFieldsOption = args.options["inheritable-fields"];
594
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
595
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
596
- const npmOptions = [];
597
- Object.entries(args.options).forEach(([key, value]) => {
598
- if (key === "help" || key === "h" || key === "no-wds" || key === "inheritable-fields") return;
599
- if (value === true) {
600
- npmOptions.push(`--${key}`);
601
- } else {
602
- npmOptions.push(`--${key}`, value);
603
- }
604
- });
605
- try {
606
- if (!path$1) {
607
- const targetDir = process.cwd();
608
- const outputDir = await promises.mkdtemp("screw-up-publish-");
609
- console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
610
- try {
611
- const metadata = await packAssets(
612
- targetDir,
613
- outputDir,
614
- checkWorkingDirectoryStatus,
615
- inheritableFields,
616
- void 0
617
- );
618
- if (metadata) {
619
- const archiveName = `${metadata.name}-${metadata.version}.tgz`;
620
- const archivePath = path.join(outputDir, archiveName);
621
- await runNpmPublish(archivePath, npmOptions);
622
- } else {
623
- console.error(`[screw-up/cli]: publish: Unable to find any files to pack: ${targetDir}`);
624
- process.exit(1);
625
- }
626
- } finally {
627
- await promises.rm(outputDir, { recursive: true, force: true });
628
- }
629
- } else if (fs.existsSync(path$1)) {
630
- const pathStat = await promises.stat(path$1);
631
- if (pathStat.isFile() && (path$1.endsWith(".tgz") || path$1.endsWith(".tar.gz"))) {
632
- await runNpmPublish(path.resolve(path$1), npmOptions);
633
- } else if (pathStat.isDirectory()) {
634
- const targetDir = path.resolve(path$1);
635
- const outputDir = await promises.mkdtemp("screw-up-publish-");
636
- console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
637
- try {
638
- const metadata = await packAssets(
639
- targetDir,
640
- outputDir,
641
- checkWorkingDirectoryStatus,
642
- inheritableFields,
643
- void 0
644
- );
645
- if (metadata) {
646
- const archiveName = `${metadata.name}-${metadata.version}.tgz`;
647
- const archivePath = path.join(outputDir, archiveName);
648
- await runNpmPublish(archivePath, npmOptions);
649
- } else {
650
- console.error(`[screw-up/cli]: publish: Unable to find any files to pack: ${targetDir}`);
651
- process.exit(1);
652
- }
653
- } finally {
654
- await promises.rm(outputDir, { recursive: true, force: true });
655
- }
656
- } else {
657
- console.error(`[screw-up/cli]: publish: Invalid path - must be a directory or .tgz/.tar.gz file: ${path$1}`);
658
- process.exit(1);
659
- }
660
- } else {
661
- console.error(`[screw-up/cli]: publish: Path does not exist: ${path$1}`);
662
- process.exit(1);
663
- }
664
- } catch (error) {
665
- console.error("[screw-up/cli]: publish: Failed to publish:", error);
666
- process.exit(1);
667
- }
668
- };
669
- const showDumpHelp = () => {
670
- console.log(`Usage: screw-up dump [options] [directory]
671
-
672
- Dump computed package.json as JSON
673
-
674
- Arguments:
675
- directory Directory to dump package.json from (default: current directory)
676
-
677
- Options:
678
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent
679
- --no-wds Do not check working directory status to increase version
680
- -h, --help Show help for dump command
681
- `);
682
- };
683
- const dumpCommand = async (args) => {
684
- if (args.options.help || args.options.h) {
685
- showDumpHelp();
686
- return;
687
- }
688
- const directory = args.positional[0];
689
- const inheritableFieldsOption = args.options["inheritable-fields"];
690
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
691
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
692
- const targetDir = path.resolve(directory != null ? directory : process.cwd());
693
- try {
694
- const computedPackageJson = await getComputedPackageJsonObject(
695
- targetDir,
696
- checkWorkingDirectoryStatus,
697
- inheritableFields
698
- );
699
- if (computedPackageJson) {
700
- console.log(JSON.stringify(computedPackageJson, null, 2));
701
- } else {
702
- console.error(`[screw-up/cli]: dump: Unable to read package.json from: ${targetDir}`);
703
- process.exit(1);
704
- }
705
- } catch (error) {
706
- console.error("[screw-up/cli]: dump: Failed to dump package.json:", error);
707
- process.exit(1);
708
- }
709
- };
710
- const main = async () => {
711
- const args = parseArgs(process.argv);
712
- if (args.options.help || args.options.h || !args.command || args.command === "help" || args.command === "--help") {
713
- showHelp();
714
- return;
715
- }
716
- switch (args.command) {
717
- case "pack":
718
- await packCommand(args);
719
- break;
720
- case "publish":
721
- await publishCommand(args);
722
- break;
723
- case "dump":
724
- await dumpCommand(args);
725
- break;
726
- default:
727
- console.error(`Unknown command: ${args.command}`);
728
- console.error('Run "screw-up --help" for usage information.');
729
- process.exit(1);
730
- }
731
- };
732
- main().catch((error) => {
733
- console.error("CLI error:", error);
734
- process.exit(1);
735
- });
736
- //# sourceMappingURL=cli.cjs.map