git-stack-cli 1.0.3 → 1.0.4

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.
@@ -26826,7 +26826,7 @@ function Url(props) {
26826
26826
  }
26827
26827
 
26828
26828
  function is_command_available(command) {
26829
- const PATH = process.env["PATH"];
26829
+ const PATH = process.env.PATH;
26830
26830
  invariant(PATH, "PATH env must exist");
26831
26831
  const path_list = PATH.split(path.delimiter);
26832
26832
  for (const dir of path_list) {
@@ -28680,7 +28680,7 @@ function RebaseCheck(props) {
28680
28680
  patch({ status });
28681
28681
  }
28682
28682
  catch (err) {
28683
- actions.error("Unable to check for rebase.");
28683
+ actions.error("Must be run from within a git repository.");
28684
28684
  if (err instanceof Error) {
28685
28685
  if (actions.isDebug()) {
28686
28686
  actions.error(err.message);
@@ -34080,7 +34080,7 @@ async function command() {
34080
34080
  .wrap(null)
34081
34081
  // disallow unknown options
34082
34082
  .strict()
34083
- .version("1.0.3" )
34083
+ .version("1.0.4" )
34084
34084
  .showHidden("show-hidden", "Show hidden options via `git stack help --show-hidden`")
34085
34085
  .help("help", "Show usage via `git stack help`").argv);
34086
34086
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-stack-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",
@@ -23,9 +23,10 @@
23
23
  "scripts": {
24
24
  "dev": "npm run build -- --watch",
25
25
  "build": "rollup -c rollup.config.mjs",
26
- "build:standalone": "bun run scripts/prepare-standalone.ts",
27
- "release:brew": "bun run scripts/release-brew.ts",
26
+ "build:standalone": "bun run scripts/build-standalone.ts",
28
27
  "release:npm": "bun run scripts/release-npm.ts",
28
+ "release:github": "bun run scripts/release-github.ts",
29
+ "release:brew": "bun run scripts/release-brew.ts",
29
30
  "lint:check": "eslint . --cache",
30
31
  "lint": "npm run lint:check -- --fix",
31
32
  "prettier:check": "prettier ./src --check --cache",
@@ -5,13 +5,23 @@ import * as file from "~/core/file";
5
5
  import { spawn } from "~/core/spawn";
6
6
 
7
7
  // get paths relative to this script
8
- const SCRIPT_DIR = path.dirname(new URL(import.meta.url).pathname);
8
+ const SCRIPT_DIR = import.meta.dir;
9
9
  const PROJECT_DIR = path.join(SCRIPT_DIR, "..");
10
10
  const NODE_MODULES_BIN = path.join(PROJECT_DIR, "node_modules", ".bin");
11
11
  const DIST_DIR = path.join(PROJECT_DIR, "dist");
12
12
  const CJS_DIR = path.join(DIST_DIR, "cjs");
13
13
  const STANDALONE_DIR = path.join(DIST_DIR, "standalone");
14
14
 
15
+ const ARG_LIST = process.argv.slice(2);
16
+ const [maybe_target] = ARG_LIST;
17
+
18
+ let TARGET = "node18-linux-x64,node18-macos-x64,node18-win-x64";
19
+ if (maybe_target) {
20
+ TARGET = maybe_target;
21
+ }
22
+
23
+ console.debug(`Building for target [${TARGET}]`);
24
+
15
25
  // clear entire dist output directory
16
26
  await fs.rmdir(DIST_DIR, { recursive: true });
17
27
  await fs.mkdir(DIST_DIR, { recursive: true });
@@ -43,7 +53,7 @@ await file.write_json(
43
53
 
44
54
  process.chdir(PROJECT_DIR);
45
55
 
46
- Bun.env["NODE_ENV"] = "production";
56
+ process.env.NODE_ENV = "production";
47
57
 
48
58
  // run typescript build to generate module output
49
59
  await spawn("npm run build");
@@ -56,4 +66,8 @@ await fs.cp(
56
66
  process.chdir(STANDALONE_DIR);
57
67
 
58
68
  // run pkg to build standalone executable
59
- await spawn(`${path.join(NODE_MODULES_BIN, "pkg")} package.json`);
69
+ await spawn([
70
+ path.join(NODE_MODULES_BIN, "pkg"),
71
+ "package.json",
72
+ `--targets=${TARGET}`,
73
+ ]);
@@ -0,0 +1,21 @@
1
+ import { spawn } from "~/core/spawn";
2
+
3
+ // https://github.com/magus/git-stack-cli/releases/download/0.8.9/git-stack-cli-linux
4
+ export async function create_asset(filepath: string, options: Options) {
5
+ const sha256_cmd = await spawn.sync(`shasum -a 256 ${filepath}`);
6
+ const match = sha256_cmd.stdout.match(/(?<sha256>[^\s]+)/i);
7
+
8
+ if (!match?.groups) {
9
+ throw new Error(`unable to get sha256 for ${filepath}`);
10
+ }
11
+
12
+ const sha256 = match.groups.sha256;
13
+
14
+ const url = `https://github.com/magus/git-stack-cli/releases/download/${options.version}/${filepath}`;
15
+
16
+ return { filepath, sha256, url };
17
+ }
18
+
19
+ type Options = {
20
+ version: string;
21
+ };
@@ -30,3 +30,7 @@ export async function exists(filepath: string) {
30
30
  return false;
31
31
  }
32
32
  }
33
+
34
+ export async function rm(filepath: string) {
35
+ await fs.rm(filepath);
36
+ }
@@ -1,9 +1,11 @@
1
- export async function spawn(cmd: string) {
1
+ export async function spawn(unsafe_cmd: CommandLike) {
2
+ const cmd = get_cmd(unsafe_cmd);
3
+
2
4
  console.debug();
3
- console.debug("[spawn]", cmd);
5
+ console.debug("[spawn]", cmd.str);
4
6
 
5
7
  const env = process.env;
6
- const proc = await Bun.spawn(cmd.split(" "), {
8
+ const proc = await Bun.spawn(cmd.parts, {
7
9
  env,
8
10
  stdout: "inherit",
9
11
  stderr: "inherit",
@@ -12,30 +14,49 @@ export async function spawn(cmd: string) {
12
14
  await proc.exited;
13
15
 
14
16
  if (proc.exitCode) {
15
- console.error(`(${proc.exitCode})`, cmd);
17
+ console.error(`(${proc.exitCode})`, cmd.str);
16
18
 
17
19
  if (!process.env.GS_NO_CHECK) {
18
20
  process.exit(proc.exitCode);
19
21
  }
20
22
  }
21
23
 
22
- console.debug("[end]", cmd);
24
+ console.debug("[end]", cmd.str);
23
25
 
24
26
  return { proc };
25
27
  }
26
28
 
27
- spawn.sync = async function spawnSync(cmd: string) {
29
+ spawn.sync = async function spawnSync(unsafe_cmd: CommandLike) {
30
+ const cmd = get_cmd(unsafe_cmd);
31
+
28
32
  console.debug();
29
- console.debug("[spawn.sync]", cmd);
33
+ console.debug("[spawn.sync]", cmd.str);
30
34
 
31
35
  const env = process.env;
32
- const proc = await Bun.spawnSync(cmd.split(" "), { env });
36
+ const proc = await Bun.spawnSync(cmd.parts, { env });
33
37
 
34
38
  const stdout = String(proc.stdout).trim();
35
39
  const stderr = String(proc.stderr).trim();
36
40
 
37
- console.debug("[end]", cmd);
41
+ console.debug("[end]", cmd.str);
38
42
  console.debug({ stdout, stderr });
39
43
 
40
44
  return { proc, stdout, stderr };
41
45
  };
46
+
47
+ type CommandLike = string | Array<string>;
48
+
49
+ function get_cmd(unsafe_cmd: CommandLike) {
50
+ let str;
51
+ let parts;
52
+
53
+ if (Array.isArray(unsafe_cmd)) {
54
+ parts = unsafe_cmd;
55
+ str = unsafe_cmd.join(" ");
56
+ } else {
57
+ parts = unsafe_cmd.split(" ");
58
+ str = unsafe_cmd;
59
+ }
60
+
61
+ return { parts, str };
62
+ }
@@ -1,7 +1,7 @@
1
1
  // simply check for flag set by `scripts/release-npm`
2
2
  // ensure we are publishing through the custom script
3
3
 
4
- if (!process.env["GS_RELEASE_NPM"]) {
4
+ if (!process.env.GS_RELEASE_NPM) {
5
5
  console.error("Must publish using `npm run release:npm`");
6
6
  console.error();
7
7
  process.exit(10);
@@ -1,15 +1,11 @@
1
1
  import path from "node:path";
2
2
 
3
+ import { create_asset } from "~/core/create_asset";
3
4
  import * as file from "~/core/file";
4
5
  import { spawn } from "~/core/spawn";
5
6
 
6
- // cli args
7
- const args = process.argv.slice(2);
8
- const NO_CHECK = args.includes("--no-check");
9
- const COMMIT = args.includes("--commit");
10
-
11
7
  // get paths relative to this script
12
- const SCRIPT_DIR = path.dirname(new URL(import.meta.url).pathname);
8
+ const SCRIPT_DIR = import.meta.dir;
13
9
  const PROJECT_DIR = path.join(SCRIPT_DIR, "..");
14
10
  const DIST_DIR = path.join(PROJECT_DIR, "dist");
15
11
  const STANDALONE_DIR = path.join(DIST_DIR, "standalone");
@@ -23,9 +19,9 @@ const version = package_json.version;
23
19
 
24
20
  process.chdir(STANDALONE_DIR);
25
21
 
26
- const linux_asset = await create_asset("git-stack-cli-linux");
27
- const macos_asset = await create_asset("git-stack-cli-macos");
28
- const win_asset = await create_asset("git-stack-cli-win.exe");
22
+ const linux_asset = await create_asset("git-stack-cli-linux", { version });
23
+ const macos_asset = await create_asset("git-stack-cli-macos", { version });
24
+ const win_asset = await create_asset("git-stack-cli-win.exe", { version });
29
25
 
30
26
  console.debug({ linux_asset, macos_asset, win_asset });
31
27
 
@@ -36,70 +32,38 @@ process.chdir(HOMEBREW_DIR);
36
32
  let formula = await file.read_text("git-stack.rb.template");
37
33
 
38
34
  formula = formula.replace(re_token("version"), version);
39
- formula = formula.replace(re_token("mac_bin"), macos_asset.name);
35
+ formula = formula.replace(re_token("mac_bin"), macos_asset.filepath);
40
36
  formula = formula.replace(re_token("mac_sha256"), macos_asset.sha256);
41
- formula = formula.replace(re_token("linux_bin"), linux_asset.name);
37
+ formula = formula.replace(re_token("linux_bin"), linux_asset.filepath);
42
38
  formula = formula.replace(re_token("linux_sha256"), linux_asset.sha256);
43
39
 
44
40
  await file.write_text("git-stack.rb", formula);
45
41
 
46
- if (COMMIT) {
47
- await spawn.sync(`git commit -a -m ${version}`);
48
- await spawn.sync(`git push`);
49
- }
42
+ await spawn.sync(`git commit -a -m ${version}`);
43
+ await spawn.sync(`git push`);
50
44
 
51
45
  process.chdir(PROJECT_DIR);
52
46
 
53
47
  await spawn(`npm i`);
54
48
 
55
- if (COMMIT) {
56
- await spawn.sync(`git commit -a -m ${version}`);
57
- await spawn.sync(`git push`);
58
- }
49
+ await spawn.sync(`git commit -a -m ${version}`);
50
+ await spawn.sync(`git push`);
59
51
 
60
52
  // -a: create tag on last commit
61
53
  // -m: message
62
- if (COMMIT) {
63
- await spawn.sync(`git tag -a ${version} -m ${version}`);
64
- await spawn.sync(`git push origin ${version}`);
54
+ await spawn.sync(`git tag -a ${version} -m ${version}`);
55
+ await spawn.sync(`git push origin ${version}`);
65
56
 
66
- await spawn.sync(
67
- `gh release create ${version} -t ${version} --generate-notes`
68
- );
57
+ await spawn.sync(`gh release create ${version} -t ${version} --generate-notes`);
69
58
 
70
- process.chdir(STANDALONE_DIR);
59
+ process.chdir(STANDALONE_DIR);
71
60
 
72
- await spawn.sync(`gh release upload ${version} ${linux_asset.name}`);
73
- await spawn.sync(`gh release upload ${version} ${macos_asset.name}`);
74
- await spawn.sync(`gh release upload ${version} ${win_asset.name}`);
75
- }
61
+ await spawn.sync(`gh release upload ${version} ${linux_asset.filepath}`);
62
+ await spawn.sync(`gh release upload ${version} ${macos_asset.filepath}`);
63
+ await spawn.sync(`gh release upload ${version} ${win_asset.filepath}`);
76
64
 
77
65
  console.debug();
78
66
  console.debug("✅", "published", version);
79
- console.debug(" COMMIT", COMMIT);
80
- console.debug(" NO_CHECK", NO_CHECK);
81
- console.debug();
82
- console.debug(" https://github.com/magus/git-stack-cli/releases");
83
- console.debug();
84
-
85
- console.debug();
86
- console.debug("Don't forget to run `npm publish` to update the NPM registry!");
87
67
  console.debug();
88
- console.debug(" npm publish");
68
+ console.debug("https://github.com/magus/homebrew-git-stack");
89
69
  console.debug();
90
-
91
- // https://github.com/magus/git-stack-cli/releases/download/0.8.9/git-stack-cli-linux
92
- async function create_asset(name: string) {
93
- const sha256_cmd = await spawn.sync(`shasum -a 256 ${name}`);
94
- const match = sha256_cmd.stdout.match(/(?<sha256>[^\s]+)/i);
95
-
96
- if (!match?.groups) {
97
- throw new Error(`unable to get sha256 for ${name}`);
98
- }
99
-
100
- const sha256 = match.groups.sha256;
101
-
102
- const url = `https://github.com/magus/git-stack-cli/releases/download/${version}/${name}`;
103
-
104
- return { name, sha256, url };
105
- }
@@ -0,0 +1,34 @@
1
+ import path from "node:path";
2
+
3
+ import { create_asset } from "~/core/create_asset";
4
+ import * as file from "~/core/file";
5
+ import { spawn } from "~/core/spawn";
6
+
7
+ // get paths relative to this script
8
+ const SCRIPT_DIR = import.meta.dir;
9
+ const PROJECT_DIR = path.join(SCRIPT_DIR, "..");
10
+
11
+ const package_json = await file.read_json(
12
+ path.join(PROJECT_DIR, "package.json")
13
+ );
14
+
15
+ const version = package_json.version;
16
+
17
+ await spawn("npm pack");
18
+
19
+ // prettier-ignore
20
+ const tarball_asset = (
21
+ await create_asset(`git-stack-cli-${version}.tgz`, { version })
22
+ );
23
+
24
+ await spawn.sync(`gh release create ${version} -t ${version} --generate-notes`);
25
+
26
+ await spawn.sync(`gh release upload ${version} ${tarball_asset.filepath}`);
27
+
28
+ await file.rm(tarball_asset.filepath);
29
+
30
+ console.debug();
31
+ console.debug("✅", "published", version);
32
+ console.debug();
33
+ console.debug("https://github.com/magus/git-stack-cli/releases");
34
+ console.debug();
@@ -7,7 +7,7 @@ import { spawn } from "~/core/spawn";
7
7
  process.env.NODE_ENV = "production";
8
8
 
9
9
  // get paths relative to this script
10
- const SCRIPT_DIR = path.dirname(new URL(import.meta.url).pathname);
10
+ const SCRIPT_DIR = import.meta.dir;
11
11
  const PROJECT_DIR = path.join(SCRIPT_DIR, "..");
12
12
  const DIST_DIR = path.join(PROJECT_DIR, "dist");
13
13
 
@@ -49,7 +49,7 @@ for (const filepath of package_json.files) {
49
49
  }
50
50
  }
51
51
 
52
- process.env["GS_RELEASE_NPM"] = "true";
52
+ process.env.GS_RELEASE_NPM = "true";
53
53
  console.info("Publishing to NPM requires a one-time password");
54
54
  const otp = await input("Enter OTP: ");
55
55
  await spawn(`npm publish --otp=${otp}`);
@@ -67,7 +67,7 @@ await spawn.sync(`git push origin ${version}`);
67
67
  console.debug();
68
68
  console.debug("✅", "published", version);
69
69
  console.debug();
70
- console.debug(" https://github.com/magus/git-stack-cli/releases");
70
+ console.debug("https://www.npmjs.com/package/git-stack-cli");
71
71
  console.debug();
72
72
 
73
73
  // // https://github.com/magus/git-stack-cli/releases/download/0.8.9/git-stack-cli-linux
@@ -82,7 +82,7 @@ export function RebaseCheck(props: Props) {
82
82
  const status = is_rebase ? "prompt" : "done";
83
83
  patch({ status });
84
84
  } catch (err) {
85
- actions.error("Unable to check for rebase.");
85
+ actions.error("Must be run from within a git repository.");
86
86
 
87
87
  if (err instanceof Error) {
88
88
  if (actions.isDebug()) {
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { invariant } from "~/core/invariant";
5
5
 
6
6
  export function is_command_available(command: string) {
7
- const PATH = process.env["PATH"];
7
+ const PATH = process.env.PATH;
8
8
 
9
9
  invariant(PATH, "PATH env must exist");
10
10