dirfly 0.5.0 → 0.7.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 (2) hide show
  1. package/dist/index.js +46 -51
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,53 +1,48 @@
1
1
  #!/usr/bin/env node
2
- (() => {
3
- var import_node_module = __require("node:module");
4
- var __create = Object.create;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __defProp = Object.defineProperty;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __toESM = (mod, isNodeMode, target) => {
10
- target = mod != null ? __create(__getProtoOf(mod)) : {};
11
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
12
- for (let key of __getOwnPropNames(mod))
13
- if (!__hasOwnProp.call(to, key))
14
- __defProp(to, key, {
15
- get: () => mod[key],
16
- enumerable: true
17
- });
18
- return to;
19
- };
20
- var __require = /* @__PURE__ */ import_node_module.createRequire(import.meta.url);
21
2
 
22
- // index.ts
23
- var import_node_util = __require("node:util");
24
- var import_node_path = __toESM(__require("node:path"));
25
- var import_node_fs = __require("node:fs");
26
- var import_node_child_process = __require("node:child_process");
27
- var { positionals } = import_node_util.parseArgs({ allowPositionals: true });
28
- var serverUrlIdx = positionals.findIndex((it) => it.startsWith("svn+ssh://"));
29
- if (serverUrlIdx === -1)
30
- throw new Error("缺少svn服务地址,仅支持协议: svn+ssh://");
31
- var serverUrl = positionals[serverUrlIdx];
32
- var localDir = import_node_path.default.resolve(positionals[serverUrlIdx - 1] || process.cwd());
33
- if (!import_node_fs.existsSync(localDir))
34
- throw new Error(`本地路径不存在: ${localDir}`);
35
- var serverDir = positionals[serverUrlIdx + 1] || import_node_path.basename(localDir);
36
- process.chdir(localDir);
37
- var gitignore = ".gitignore";
38
- if (!import_node_fs.existsSync(gitignore))
39
- throw new Error(`请先创建${import_node_path.default.resolve(gitignore)},如 svn commit . -m "批量更新"`);
40
- if (import_node_fs.existsSync(".svn"))
41
- throw new Error('当前目录已经被初始化过了,可以直接提交,如 `svn commit . -m "批量更新"`');
42
- var serverFullUrl = `${serverUrl}/${serverDir}`;
43
- console.log(`准备导入: ${localDir} → ${serverFullUrl}`);
44
- var cmds = [
45
- `svn import -m "导入临时占位文件" ${gitignore} ${serverFullUrl}/${gitignore}`,
46
- `svn checkout "${serverFullUrl}" .`,
47
- `svn propset svn:ignore -F ./.gitignore ./`,
48
- `svn resolve --accept working ./.gitignore`,
49
- `svn add --force . `,
50
- `svn commit -m "新增项目${serverDir}"`
51
- ];
52
- cmds.forEach((cmd) => import_node_child_process.execSync(cmd));
53
- })();
3
+ // index.ts
4
+ import { parseArgs } from "node:util";
5
+ import path, { basename } from "node:path";
6
+ import { existsSync } from "node:fs";
7
+ import { spawnSync } from "node:child_process";
8
+ var { positionals } = parseArgs({ allowPositionals: true });
9
+ var serverUrlIdx = positionals.findIndex((it) => it.startsWith("svn+ssh://"));
10
+ if (serverUrlIdx === -1)
11
+ throw new Error("缺少svn服务地址,仅支持协议: svn+ssh://");
12
+ var serverUrl = positionals[serverUrlIdx];
13
+ var localDir = path.resolve(positionals[serverUrlIdx - 1] || process.cwd());
14
+ if (!existsSync(localDir))
15
+ throw new Error(`本地路径不存在: ${localDir}`);
16
+ var serverDir = positionals[serverUrlIdx + 1] || basename(localDir);
17
+ process.chdir(localDir);
18
+ var gitignore = ".gitignore";
19
+ if (!existsSync(gitignore))
20
+ throw new Error(`请先创建${path.resolve(gitignore)},如 svn commit . -m "批量更新"`);
21
+ if (existsSync(".svn"))
22
+ throw new Error('当前目录已经被初始化过了,可以直接提交,如 `svn commit . -m "批量更新"`');
23
+ var serverFullUrl = `${serverUrl}/${serverDir}`;
24
+ console.log(`准备导入: ${localDir} → ${serverFullUrl}`);
25
+ var cmds = [
26
+ `svn import -m "导入临时占位文件" ${gitignore} ${serverFullUrl}/${gitignore}`,
27
+ `svn checkout ${serverFullUrl} .`,
28
+ `svn propset svn:ignore -F ./.gitignore ./`,
29
+ `svn resolve --accept working ./.gitignore`,
30
+ `svn add --force . `,
31
+ `svn commit -m "新增项目${serverDir}"`
32
+ ];
33
+ cmds.forEach((cmd) => {
34
+ const res = crossSpawnExec(cmd, { stdio: "inherit" });
35
+ if (res.status) {
36
+ process.exit(0);
37
+ }
38
+ });
39
+ function crossSpawnExec(cmd, options) {
40
+ let [bin, ...params] = cmd.trim().split(/\s+/);
41
+ if (!bin)
42
+ throw new Error("执行命令有误");
43
+ if (process.platform === "win32") {
44
+ params.unshift("-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", bin);
45
+ bin = "powershell.exe";
46
+ }
47
+ return spawnSync(bin, params, { stdio: "inherit", ...options });
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirfly",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "用于将本地目录同步到指定`SVN`仓库。",
5
5
  "keywords": [
6
6
  "directory",
@@ -18,7 +18,7 @@
18
18
  "dirfly": "./dist/index.js"
19
19
  },
20
20
  "scripts": {
21
- "bld": "bun build ./index.ts --outdir ./dist --target node --format iife ",
21
+ "bld": "bun build ./index.ts --outdir ./dist --target node ",
22
22
  "pub": "npm run bld && npm publish --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$token "
23
23
  },
24
24
  "files": [