@fedify/init 2.0.25 → 2.0.26-dev.1875

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,6 +1,6 @@
1
1
  import { colors, printMessage } from "../utils.js";
2
- import { text } from "@optique/core";
3
2
  import { flow } from "es-toolkit";
3
+ import { text } from "@optique/core";
4
4
  //#region src/action/notice.ts
5
5
  function drawDinosaur() {
6
6
  const d = flow(colors.bgBlue, colors.black);
package/dist/ask/dir.js CHANGED
@@ -28,7 +28,7 @@ const askDir = (cwd) => input({
28
28
  });
29
29
  const askIfNonEmpty = async (dir) => {
30
30
  if (await isDirectoryEmpty(dir)) return true;
31
- if (await askNonEmpty(dir)) return await moveDirToTrash(dir);
31
+ if (await askNonEmpty(dir)) return await moveOrDeleteDir(dir);
32
32
  return false;
33
33
  };
34
34
  const askNonEmpty = (dir) => toggle.default({
@@ -36,31 +36,57 @@ const askNonEmpty = (dir) => toggle.default({
36
36
  Do you want to use it anyway?`,
37
37
  default: false
38
38
  });
39
- const moveDirToTrash = (dir) => pipe(dir, askMoveToTrash, when(identity, moveToTrash(dir)));
40
- const askMoveToTrash = (dir) => toggle.default({
39
+ const moveOrDeleteDir = (dir) => pipe(dir, buildMoveOrDelete, (action) => pipe(action.confirm, when(identity, runAction(action.command, action.error))));
40
+ const buildMoveOrDelete = (dir) => pipe(getOsType(), detectSupportedAction, (fn) => {
41
+ return {
42
+ confirm: fn.confirmAction(dir),
43
+ command: fn.actionPlan.command(dir),
44
+ error: errorMessages[fn.actionPlan.mode](dir)
45
+ };
46
+ });
47
+ const detectSupportedAction = (os) => {
48
+ const actionPlan = trashOrDeleteCommands[os] ?? trashOrDeleteCommands.linux;
49
+ return {
50
+ confirmAction: actionPlan.mode === "trash" ? moveToTrashConfirm : deletePermanentlyConfirm,
51
+ actionPlan
52
+ };
53
+ };
54
+ const moveToTrashConfirm = (dir) => toggle.default({
41
55
  message: `Do you want to move the contents of "${dir}" to the trash?
42
56
  If you choose "No", you should choose another directory.`,
43
57
  default: false
44
58
  });
45
- const moveToTrash = (dir) => () => pipe(getOsType(), getTrashCommand, (fn) => fn(dir), (cmd) => runSubCommand(cmd, { stdio: "ignore" }), () => true).catch((e) => {
59
+ const deletePermanentlyConfirm = (dir) => toggle.default({
60
+ message: `Do you really want to delete all contents of "${dir}" PERMANENTLY?
61
+ If you choose "No", you should choose another directory.`,
62
+ default: false
63
+ });
64
+ const runAction = (command, error) => () => pipe(command, (cmd) => runSubCommand(cmd, { stdio: "ignore" }), () => true).catch((e) => {
46
65
  logger.error(e);
47
- printError(message`Failed to move ${dir} to trash.
48
- Please move it manually.`);
66
+ printError(error);
49
67
  return false;
50
68
  });
51
- const getTrashCommand = (os) => trashCommands[os] ?? trashCommands.linux;
52
- const trashCommands = {
53
- darwin: (dir) => ["trash", dir],
54
- win32: (dir) => [
55
- "powershell",
56
- "-Command",
57
- getPowershellTrashCommand(dir)
58
- ],
59
- linux: (dir) => [
60
- "rm",
61
- "-rf",
62
- dir
63
- ]
69
+ const trashOrDeleteCommands = {
70
+ darwin: {
71
+ mode: "trash",
72
+ command: (dir) => ["trash", dir]
73
+ },
74
+ win32: {
75
+ mode: "trash",
76
+ command: (dir) => [
77
+ "powershell",
78
+ "-Command",
79
+ getPowershellTrashCommand(dir)
80
+ ]
81
+ },
82
+ linux: {
83
+ mode: "permanent",
84
+ command: (dir) => [
85
+ "rm",
86
+ "-rf",
87
+ dir
88
+ ]
89
+ }
64
90
  };
65
91
  const getPowershellTrashCommand = (dir) => [
66
92
  "Add-Type",
@@ -72,5 +98,11 @@ const getPowershellTrashCommand = (dir) => [
72
98
  "'OnlyErrorDialogs',",
73
99
  "'SendToRecycleBin')"
74
100
  ].join(" ");
101
+ const errorMessages = {
102
+ "trash": (dir) => message`Failed to move ${dir} to trash.
103
+ Please move it manually.`,
104
+ "permanent": (dir) => message`Failed to delete ${dir} permanently.
105
+ Please remove it manually.`
106
+ };
75
107
  //#endregion
76
108
  export { fillDir as default };
package/dist/deno.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region deno.json
2
- var version = "2.0.25";
2
+ var version = "2.0.26-dev.1875+623710b2";
3
3
  //#endregion
4
4
  export { version };
package/dist/lib.js CHANGED
@@ -1,14 +1,14 @@
1
- import { isNotFoundError, runSubCommand } from "./utils.js";
2
1
  import { version } from "./deno.js";
3
2
  import kv_default from "./json/kv.js";
4
3
  import mq_default from "./json/mq.js";
5
4
  import pm_default from "./json/pm.js";
6
5
  import rt_default from "./json/rt.js";
6
+ import { isNotFoundError, runSubCommand } from "./utils.js";
7
7
  import { entries, evolve, fromEntries, isObject, map, negate, pipe, throwIf } from "@fxts/core";
8
8
  import process from "node:process";
9
9
  import { commandLine, message } from "@optique/core/message";
10
- import { toMerged } from "es-toolkit";
11
10
  import { getLogger } from "@logtape/logtape";
11
+ import { toMerged } from "es-toolkit";
12
12
  import { readFileSync } from "node:fs";
13
13
  import { mkdir, readdir, writeFile } from "node:fs/promises";
14
14
  import { dirname, join as join$1 } from "node:path";
@@ -1,12 +1,12 @@
1
- import { CommandError, printErrorMessage, printMessage, product, runSubCommand } from "../utils.js";
2
1
  import pm_default from "../json/pm.js";
2
+ import { CommandError, printErrorMessage, printMessage, product, runSubCommand } from "../utils.js";
3
3
  import { kvStores, messageQueues } from "../lib.js";
4
4
  import webFrameworks from "../webframeworks.js";
5
5
  import { filter, isEmpty, pipe, toArray } from "@fxts/core";
6
6
  import process from "node:process";
7
- import { values } from "@optique/core";
8
7
  import { appendFile, mkdir } from "node:fs/promises";
9
8
  import { join as join$1, sep } from "node:path";
9
+ import { values } from "@optique/core";
10
10
  //#region src/test/create.ts
11
11
  const BANNED_PMS = ["bun", "yarn"];
12
12
  const createTestApp = (testDirPrefix, dry) => async (options) => {
@@ -2,10 +2,10 @@ import { printErrorMessage, printMessage, runSubCommand } from "../utils.js";
2
2
  import { getDevCommand } from "../lib.js";
3
3
  import webFrameworks from "../webframeworks.js";
4
4
  import process from "node:process";
5
- import { values } from "@optique/core";
6
- import { spawn } from "node:child_process";
7
5
  import { createWriteStream } from "node:fs";
8
6
  import { join, sep } from "node:path";
7
+ import { values } from "@optique/core";
8
+ import { spawn } from "node:child_process";
9
9
  import { isEmpty } from "@fxts/core/index.js";
10
10
  //#region src/test/lookup.ts
11
11
  const HANDLE = "john";
package/dist/test/run.js CHANGED
@@ -2,8 +2,8 @@ import { printMessage } from "../utils.js";
2
2
  import createTestApp, { filterOptions, generateTestCases } from "./create.js";
3
3
  import runServerAndLookupUser from "./lookup.js";
4
4
  import { always, filter, map, pipe, tap, unless } from "@fxts/core";
5
- import { optionNames } from "@optique/core";
6
5
  import { join as join$1 } from "node:path";
6
+ import { optionNames } from "@optique/core";
7
7
  //#region src/test/run.ts
8
8
  const runTests = (dry) => ({ testDirPrefix, dryRun, hydRun, ...options }) => pipe(options, printStartMessage(dry), generateTestCases, filter(filterOptions), map(createTestApp(join$1(testDirPrefix, getMid(dryRun, hydRun, dry)), dry)), Array.fromAsync, unless(always(dry), runServerAndLookupUser));
9
9
  const printStartMessage = (dry) => tap(() => printMessage`\n
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { message } from "@optique/core";
2
1
  import { toMerged } from "es-toolkit";
2
+ import { message } from "@optique/core";
3
3
  import { spawn } from "node:child_process";
4
4
 
5
5
  //#region src/utils.d.ts
package/dist/utils.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { isObject } from "@fxts/core";
2
2
  import process from "node:process";
3
3
  import { print, printError } from "@optique/run";
4
+ import { flow, toMerged } from "es-toolkit";
4
5
  import { message } from "@optique/core";
5
6
  import { Chalk } from "chalk";
6
- import { flow, toMerged } from "es-toolkit";
7
7
  import { spawn } from "node:child_process";
8
8
  const colors = new Chalk(process.stdout.isTTY && !("NO_COLOR" in process.env && process.env.NO_COLOR !== "") ? {} : { level: 0 });
9
9
  const isPromise = (value) => value instanceof Promise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/init",
3
- "version": "2.0.25",
3
+ "version": "2.0.26-dev.1875+623710b2",
4
4
  "description": "Project initializer for Fedify",
5
5
  "keywords": [
6
6
  "fedify",