@fedify/init 2.4.0-dev.1873 → 2.4.0-dev.1889

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.
package/dist/ask/dir.js CHANGED
@@ -33,7 +33,7 @@ const askDir = (cwd) => input({
33
33
  });
34
34
  const askIfNonEmpty = async (dir) => {
35
35
  if (await isDirectoryEmpty(dir)) return true;
36
- if (await askNonEmpty(dir)) return await moveDirToTrash(dir);
36
+ if (await askNonEmpty(dir)) return await moveOrDeleteDir(dir);
37
37
  return false;
38
38
  };
39
39
  const askNonEmpty = (dir) => toggle.default({
@@ -41,31 +41,57 @@ const askNonEmpty = (dir) => toggle.default({
41
41
  Do you want to use it anyway?`,
42
42
  default: false
43
43
  });
44
- const moveDirToTrash = (dir) => pipe(dir, askMoveToTrash, when(identity, moveToTrash(dir)));
45
- const askMoveToTrash = (dir) => toggle.default({
44
+ const moveOrDeleteDir = (dir) => pipe(dir, buildMoveOrDelete, (action) => pipe(action.confirm, when(identity, runAction(action.command, action.error))));
45
+ const buildMoveOrDelete = (dir) => pipe(getOsType(), detectSupportedAction, (fn) => {
46
+ return {
47
+ confirm: fn.confirmAction(dir),
48
+ command: fn.actionPlan.command(dir),
49
+ error: errorMessages[fn.actionPlan.mode](dir)
50
+ };
51
+ });
52
+ const detectSupportedAction = (os) => {
53
+ const actionPlan = trashOrDeleteCommands[os] ?? trashOrDeleteCommands.linux;
54
+ return {
55
+ confirmAction: actionPlan.mode === "trash" ? moveToTrashConfirm : deletePermanentlyConfirm,
56
+ actionPlan
57
+ };
58
+ };
59
+ const moveToTrashConfirm = (dir) => toggle.default({
46
60
  message: `Do you want to move the contents of "${dir}" to the trash?
47
61
  If you choose "No", you should choose another directory.`,
48
62
  default: false
49
63
  });
50
- const moveToTrash = (dir) => () => pipe(getOsType(), getTrashCommand, (fn) => fn(dir), (cmd) => $`${cmd}`.spawn(), () => true).catch((e) => {
64
+ const deletePermanentlyConfirm = (dir) => toggle.default({
65
+ message: `Do you really want to delete all contents of "${dir}" PERMANENTLY?
66
+ If you choose "No", you should choose another directory.`,
67
+ default: false
68
+ });
69
+ const runAction = (command, error) => () => pipe(command, (cmd) => $`${cmd}`.spawn(), () => true).catch((e) => {
51
70
  logger.error(e);
52
- printError(message`Failed to move ${dir} to trash.
53
- Please move it manually.`);
71
+ printError(error);
54
72
  return false;
55
73
  });
56
- const getTrashCommand = (os) => trashCommands[os] ?? trashCommands.linux;
57
- const trashCommands = {
58
- darwin: (dir) => ["trash", dir],
59
- win32: (dir) => [
60
- "powershell",
61
- "-Command",
62
- getPowershellTrashCommand(dir)
63
- ],
64
- linux: (dir) => [
65
- "rm",
66
- "-rf",
67
- dir
68
- ]
74
+ const trashOrDeleteCommands = {
75
+ darwin: {
76
+ mode: "trash",
77
+ command: (dir) => ["trash", dir]
78
+ },
79
+ win32: {
80
+ mode: "trash",
81
+ command: (dir) => [
82
+ "powershell",
83
+ "-Command",
84
+ getPowershellTrashCommand(dir)
85
+ ]
86
+ },
87
+ linux: {
88
+ mode: "permanent",
89
+ command: (dir) => [
90
+ "rm",
91
+ "-rf",
92
+ dir
93
+ ]
94
+ }
69
95
  };
70
96
  const getPowershellTrashCommand = (dir) => [
71
97
  "Add-Type",
@@ -77,5 +103,11 @@ const getPowershellTrashCommand = (dir) => [
77
103
  "'OnlyErrorDialogs',",
78
104
  "'SendToRecycleBin')"
79
105
  ].join(" ");
106
+ const errorMessages = {
107
+ "trash": (dir) => message`Failed to move ${dir} to trash.
108
+ Please move it manually.`,
109
+ "permanent": (dir) => message`Failed to delete ${dir} permanently.
110
+ Please remove it manually.`
111
+ };
80
112
  //#endregion
81
113
  export { fillDir as default };
package/dist/deno.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region deno.json
2
- var version = "2.4.0-dev.1873+f79eae3d";
2
+ var version = "2.4.0-dev.1889+70cfc7ff";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/init",
3
- "version": "2.4.0-dev.1873+f79eae3d",
3
+ "version": "2.4.0-dev.1889+70cfc7ff",
4
4
  "description": "Project initializer for Fedify",
5
5
  "keywords": [
6
6
  "fedify",
@@ -57,6 +57,7 @@
57
57
  "jsonc-parser": "^3.3.1"
58
58
  },
59
59
  "devDependencies": {
60
+ "@std/assert": "npm:@jsr/std__assert@^1.0.13",
60
61
  "@types/node": "^22.17.0",
61
62
  "tsdown": "^0.22.0",
62
63
  "typescript": "^6.0.0"