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