screw-up 0.12.0 → 0.14.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 +21 -7
  3. package/dist/analyzer.d.ts +13 -1
  4. package/dist/analyzer.d.ts.map +1 -1
  5. package/dist/cli-internal.d.ts +30 -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 +36 -13
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +10 -1
  14. package/dist/index.js +36 -13
  15. package/dist/index.js.map +1 -1
  16. package/dist/{internal-Di0s8LQa.cjs → internal-BHSe5LIZ.cjs} +349 -322
  17. package/dist/internal-BHSe5LIZ.cjs.map +1 -0
  18. package/dist/{internal-BaMzTKS2.js → internal-BgCvktPU.js} +351 -324
  19. package/dist/internal-BgCvktPU.js.map +1 -0
  20. package/dist/internal.d.ts +64 -14
  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-D9nXAoK9.cjs +20 -0
  29. package/dist/packageMetadata-D9nXAoK9.cjs.map +1 -0
  30. package/dist/packageMetadata-Dsxn2dKN.js +20 -0
  31. package/dist/packageMetadata-Dsxn2dKN.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 -765
  40. package/dist/cli.cjs.map +0 -1
  41. package/dist/cli.js +0 -764
  42. package/dist/cli.js.map +0 -1
  43. package/dist/internal-BaMzTKS2.js.map +0 -1
  44. package/dist/internal-Di0s8LQa.cjs.map +0 -1
package/dist/cli.js DELETED
@@ -1,764 +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, f as findWorkspaceRoot, c as collectWorkspaceSiblings, b as replacePeerDependenciesWildcards } from "./internal-BaMzTKS2.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, replacePeerDepsWildcards = true, peerDepsVersionPrefix = "^") => {
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
- let { packageJson: resolvedPackageJson, sourceMap } = result;
338
- if (resolvedPackageJson == null ? void 0 : resolvedPackageJson.private) {
339
- return void 0;
340
- }
341
- if (replacePeerDepsWildcards) {
342
- const workspaceRoot = await findWorkspaceRoot(targetDir);
343
- if (workspaceRoot) {
344
- const siblings = await collectWorkspaceSiblings(workspaceRoot);
345
- if (siblings.size > 0) {
346
- resolvedPackageJson = replacePeerDependenciesWildcards(
347
- resolvedPackageJson,
348
- siblings,
349
- peerDepsVersionPrefix
350
- );
351
- }
352
- }
353
- }
354
- let finalReadmeReplacementPath = readmeReplacementPath;
355
- if (!finalReadmeReplacementPath && (resolvedPackageJson == null ? void 0 : resolvedPackageJson.readme)) {
356
- const readmeSourceDir = (_a = sourceMap.get("readme")) != null ? _a : targetDir;
357
- const packageReadmePath = resolve(readmeSourceDir, resolvedPackageJson.readme);
358
- if (existsSync(packageReadmePath)) {
359
- finalReadmeReplacementPath = packageReadmePath;
360
- }
361
- }
362
- if (finalReadmeReplacementPath && !existsSync(finalReadmeReplacementPath)) {
363
- throw new Error(`README replacement file not found: ${finalReadmeReplacementPath}`);
364
- }
365
- 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`;
366
- if (!existsSync(outputDir)) {
367
- await mkdir(outputDir, { recursive: true });
368
- }
369
- const packer = createTarPacker(
370
- createPackEntryGenerator(targetDir, resolvedPackageJson, finalReadmeReplacementPath),
371
- "gzip"
372
- );
373
- const outputFile = resolve(outputDir, outputFileName);
374
- await storeReaderToFile(packer, outputFile);
375
- return resolvedPackageJson;
376
- };
377
- const getComputedPackageJsonObject = async (targetDir, checkWorkingDirectoryStatus, inheritableFields) => {
378
- if (!existsSync(targetDir)) {
379
- return void 0;
380
- }
381
- const result = await resolveRawPackageJsonObject(
382
- targetDir,
383
- checkWorkingDirectoryStatus,
384
- inheritableFields
385
- );
386
- return result.packageJson;
387
- };
388
- const parseArgs = (argv) => {
389
- const args = argv.slice(2);
390
- const result = {
391
- positional: [],
392
- options: {}
393
- };
394
- if (args.length === 0) {
395
- return result;
396
- }
397
- if (args[0].startsWith("-")) {
398
- let i2 = 0;
399
- while (i2 < args.length) {
400
- const arg = args[i2];
401
- if (arg.startsWith("--")) {
402
- const optionName = arg.slice(2);
403
- const nextArg = args[i2 + 1];
404
- if (nextArg !== void 0 && !nextArg.startsWith("-")) {
405
- result.options[optionName] = nextArg;
406
- i2 += 2;
407
- } else {
408
- result.options[optionName] = true;
409
- i2 += 1;
410
- }
411
- } else if (arg.startsWith("-")) {
412
- const optionName = arg.slice(1);
413
- result.options[optionName] = true;
414
- i2 += 1;
415
- } else {
416
- result.positional.push(arg);
417
- i2 += 1;
418
- }
419
- }
420
- return result;
421
- }
422
- result.command = args[0];
423
- let i = 1;
424
- while (i < args.length) {
425
- const arg = args[i];
426
- if (arg.startsWith("--")) {
427
- const optionName = arg.slice(2);
428
- const nextArg = args[i + 1];
429
- if (nextArg !== void 0 && !nextArg.startsWith("-")) {
430
- result.options[optionName] = nextArg;
431
- i += 2;
432
- } else {
433
- result.options[optionName] = true;
434
- i += 1;
435
- }
436
- } else if (arg.startsWith("-")) {
437
- const optionName = arg.slice(1);
438
- result.options[optionName] = true;
439
- i += 1;
440
- } else {
441
- result.positional.push(arg);
442
- i += 1;
443
- }
444
- }
445
- return result;
446
- };
447
- const defaultInheritableFields = /* @__PURE__ */ new Set([
448
- "version",
449
- "description",
450
- "author",
451
- "license",
452
- "repository",
453
- "keywords",
454
- "homepage",
455
- "bugs",
456
- "readme"
457
- ]);
458
- const parseInheritableFields = (inheritableFieldsOption) => {
459
- if (typeof inheritableFieldsOption !== "string") {
460
- return defaultInheritableFields;
461
- }
462
- if (!inheritableFieldsOption.trim()) {
463
- return /* @__PURE__ */ new Set();
464
- }
465
- return new Set(inheritableFieldsOption.split(",").map((field) => field.trim()).filter((field) => field.length > 0));
466
- };
467
- const showHelp = () => {
468
- console.log(`screw-up - Easy package metadata inserter CLI [${void 0}]
469
- Copyright (c) ${"Kouji Matsui (@kekyo@mi.kekyo.net)"}
470
- Repository: ${"https://github.com/kekyo/screw-up.git"}
471
- License: ${"MIT"}
472
-
473
- Usage: screw-up <command> [options]
474
-
475
- Commands:
476
- pack [directory] Pack the project into a tar archive
477
- publish [directory|package.tgz] Publish the project
478
- dump [directory] Dump computed package.json as JSON
479
-
480
- Options:
481
- -h, --help Show help
482
-
483
- Pack Options:
484
- --pack-destination <path> Directory to write the tarball
485
- --readme <path> Replace README.md with specified file
486
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent (default: version,description,author,license,repository,keywords,homepage,bugs,readme)
487
- --no-wds Do not check working directory status to increase version
488
- --no-replace-peer-deps Disable replacing "*" in peerDependencies with actual versions
489
- --peer-deps-prefix <prefix> Version prefix for replaced peerDependencies (default: "^")
490
-
491
- Publish Options:
492
- All npm publish options are supported (e.g., --dry-run, --tag, --access, --registry)
493
-
494
- Examples:
495
- screw-up pack # Pack current directory
496
- screw-up pack ./my-project # Pack specific directory
497
- screw-up pack --pack-destination ./dist # Pack to specific output directory
498
- screw-up pack --readme ./README_pack.md # Pack with custom README
499
- screw-up publish # Publish current directory
500
- screw-up publish ./my-project # Publish specific directory
501
- screw-up publish package.tgz # Publish existing tarball
502
- screw-up publish --dry-run --tag beta # Publish with npm options
503
- `);
504
- };
505
- const showPackHelp = () => {
506
- console.log(`Usage: screw-up pack [options] [directory]
507
-
508
- Pack the project into a tar archive
509
-
510
- Arguments:
511
- directory Directory to pack (default: current directory)
512
-
513
- Options:
514
- --pack-destination <path> Directory to write the tarball
515
- --readme <path> Replace README.md with specified file
516
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent
517
- --no-wds Do not check working directory status to increase version
518
- --no-replace-peer-deps Disable replacing "*" in peerDependencies with actual versions
519
- --peer-deps-prefix <prefix> Version prefix for replaced peerDependencies (default: "^")
520
- -h, --help Show help for pack command
521
- `);
522
- };
523
- const showPublishHelp = () => {
524
- console.log(`Usage: screw-up publish [options] [directory|package.tgz]
525
-
526
- Publish the project
527
-
528
- Arguments:
529
- directory|package.tgz Directory to pack and publish, or existing tarball to publish
530
-
531
- Options:
532
- All npm publish options are supported, including:
533
- --dry-run Perform a dry run
534
- --tag <tag> Tag for the published version
535
- --access <access> Access level (public or restricted)
536
- --registry <registry> Registry URL
537
- -h, --help Show help for publish command
538
-
539
- Examples:
540
- screw-up publish # Publish current directory
541
- screw-up publish ./my-project # Publish specific directory
542
- screw-up publish package.tgz # Publish existing tarball
543
- screw-up publish --dry-run --tag beta # Publish with options
544
- `);
545
- };
546
- const packCommand = async (args) => {
547
- var _a;
548
- if (args.options.help || args.options.h) {
549
- showPackHelp();
550
- return;
551
- }
552
- const directory = args.positional[0];
553
- const packDestination = args.options["pack-destination"];
554
- const readmeOption = args.options["readme"];
555
- const inheritableFieldsOption = args.options["inheritable-fields"];
556
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
557
- const replacePeerDepsWildcards = !args.options["no-replace-peer-deps"];
558
- const peerDepsVersionPrefix = (_a = args.options["peer-deps-prefix"]) != null ? _a : "^";
559
- const targetDir = resolve(directory != null ? directory : process.cwd());
560
- const outputDir = packDestination ? resolve(packDestination) : process.cwd();
561
- const readmeReplacementPath = readmeOption ? resolve(readmeOption) : void 0;
562
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
563
- console.log(`[screw-up/cli]: pack: Creating archive of ${targetDir}...`);
564
- try {
565
- const metadata = await packAssets(
566
- targetDir,
567
- outputDir,
568
- checkWorkingDirectoryStatus,
569
- inheritableFields,
570
- readmeReplacementPath,
571
- replacePeerDepsWildcards,
572
- peerDepsVersionPrefix
573
- );
574
- if (metadata) {
575
- console.log(`[screw-up/cli]: pack: Archive created successfully: ${outputDir}`);
576
- } else {
577
- console.error(`[screw-up/cli]: pack: Unable to find any files to pack: ${targetDir}`);
578
- process.exit(1);
579
- }
580
- } catch (error) {
581
- console.error("[screw-up/cli]: pack: Failed to create archive:", error);
582
- process.exit(1);
583
- }
584
- };
585
- const publishCommand = async (args) => {
586
- var _a;
587
- if (args.options.help || args.options.h) {
588
- showPublishHelp();
589
- return;
590
- }
591
- const runNpmPublish = async (tarballPath, npmOptions2) => {
592
- console.log(`[screw-up/cli]: publish: Publishing ${tarballPath} to npm...`);
593
- const publishArgs = ["publish", tarballPath, ...npmOptions2];
594
- if (process.env.SCREW_UP_TEST_MODE === "true") {
595
- console.log(`[screw-up/cli]: TEST_MODE: Would execute: npm ${publishArgs.join(" ")}`);
596
- console.log(`[screw-up/cli]: TEST_MODE: Tarball path: ${tarballPath}`);
597
- console.log(`[screw-up/cli]: TEST_MODE: Options: ${npmOptions2.join(" ")}`);
598
- console.log(`[screw-up/cli]: publish: Successfully published ${tarballPath}`);
599
- return;
600
- }
601
- const npmProcess = spawn("npm", publishArgs, { stdio: "inherit" });
602
- return new Promise((resolve2, reject) => {
603
- npmProcess.on("close", (code) => {
604
- if (code === 0) {
605
- console.log(`[screw-up/cli]: publish: Successfully published ${tarballPath}`);
606
- resolve2();
607
- } else {
608
- reject(new Error(`npm publish failed with exit code ${code}`));
609
- }
610
- });
611
- npmProcess.on("error", reject);
612
- });
613
- };
614
- const path = args.positional[0];
615
- const inheritableFieldsOption = args.options["inheritable-fields"];
616
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
617
- const replacePeerDepsWildcards = !args.options["no-replace-peer-deps"];
618
- const peerDepsVersionPrefix = (_a = args.options["peer-deps-prefix"]) != null ? _a : "^";
619
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
620
- const npmOptions = [];
621
- Object.entries(args.options).forEach(([key, value]) => {
622
- if (key === "help" || key === "h" || key === "no-wds" || key === "inheritable-fields" || key === "no-replace-peer-deps" || key === "peer-deps-prefix") return;
623
- if (value === true) {
624
- npmOptions.push(`--${key}`);
625
- } else {
626
- npmOptions.push(`--${key}`, value);
627
- }
628
- });
629
- try {
630
- if (!path) {
631
- const targetDir = process.cwd();
632
- const outputDir = await mkdtemp("screw-up-publish-");
633
- console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
634
- try {
635
- const metadata = await packAssets(
636
- targetDir,
637
- outputDir,
638
- checkWorkingDirectoryStatus,
639
- inheritableFields,
640
- void 0,
641
- replacePeerDepsWildcards,
642
- peerDepsVersionPrefix
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 if (existsSync(path)) {
656
- const pathStat = await stat(path);
657
- if (pathStat.isFile() && (path.endsWith(".tgz") || path.endsWith(".tar.gz"))) {
658
- await runNpmPublish(resolve(path), npmOptions);
659
- } else if (pathStat.isDirectory()) {
660
- const targetDir = resolve(path);
661
- const outputDir = await mkdtemp("screw-up-publish-");
662
- console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
663
- try {
664
- const metadata = await packAssets(
665
- targetDir,
666
- outputDir,
667
- checkWorkingDirectoryStatus,
668
- inheritableFields,
669
- void 0,
670
- replacePeerDepsWildcards,
671
- peerDepsVersionPrefix
672
- );
673
- if (metadata) {
674
- const archiveName = `${metadata.name}-${metadata.version}.tgz`;
675
- const archivePath = join(outputDir, archiveName);
676
- await runNpmPublish(archivePath, npmOptions);
677
- } else {
678
- console.error(`[screw-up/cli]: publish: Unable to find any files to pack: ${targetDir}`);
679
- process.exit(1);
680
- }
681
- } finally {
682
- await rm(outputDir, { recursive: true, force: true });
683
- }
684
- } else {
685
- console.error(`[screw-up/cli]: publish: Invalid path - must be a directory or .tgz/.tar.gz file: ${path}`);
686
- process.exit(1);
687
- }
688
- } else {
689
- console.error(`[screw-up/cli]: publish: Path does not exist: ${path}`);
690
- process.exit(1);
691
- }
692
- } catch (error) {
693
- console.error("[screw-up/cli]: publish: Failed to publish:", error);
694
- process.exit(1);
695
- }
696
- };
697
- const showDumpHelp = () => {
698
- console.log(`Usage: screw-up dump [options] [directory]
699
-
700
- Dump computed package.json as JSON
701
-
702
- Arguments:
703
- directory Directory to dump package.json from (default: current directory)
704
-
705
- Options:
706
- --inheritable-fields <list> Comma-separated list of fields to inherit from parent
707
- --no-wds Do not check working directory status to increase version
708
- -h, --help Show help for dump command
709
- `);
710
- };
711
- const dumpCommand = async (args) => {
712
- if (args.options.help || args.options.h) {
713
- showDumpHelp();
714
- return;
715
- }
716
- const directory = args.positional[0];
717
- const inheritableFieldsOption = args.options["inheritable-fields"];
718
- const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
719
- const inheritableFields = parseInheritableFields(inheritableFieldsOption);
720
- const targetDir = resolve(directory != null ? directory : process.cwd());
721
- try {
722
- const computedPackageJson = await getComputedPackageJsonObject(
723
- targetDir,
724
- checkWorkingDirectoryStatus,
725
- inheritableFields
726
- );
727
- if (computedPackageJson) {
728
- console.log(JSON.stringify(computedPackageJson, null, 2));
729
- } else {
730
- console.error(`[screw-up/cli]: dump: Unable to read package.json from: ${targetDir}`);
731
- process.exit(1);
732
- }
733
- } catch (error) {
734
- console.error("[screw-up/cli]: dump: Failed to dump package.json:", error);
735
- process.exit(1);
736
- }
737
- };
738
- const main = async () => {
739
- const args = parseArgs(process.argv);
740
- if (args.options.help || args.options.h || !args.command || args.command === "help" || args.command === "--help") {
741
- showHelp();
742
- return;
743
- }
744
- switch (args.command) {
745
- case "pack":
746
- await packCommand(args);
747
- break;
748
- case "publish":
749
- await publishCommand(args);
750
- break;
751
- case "dump":
752
- await dumpCommand(args);
753
- break;
754
- default:
755
- console.error(`Unknown command: ${args.command}`);
756
- console.error('Run "screw-up --help" for usage information.');
757
- process.exit(1);
758
- }
759
- };
760
- main().catch((error) => {
761
- console.error("CLI error:", error);
762
- process.exit(1);
763
- });
764
- //# sourceMappingURL=cli.js.map