@rpcbase/cli 0.46.0 → 0.48.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.
package/bin.js CHANGED
@@ -8,7 +8,7 @@ require("dotenv").config({path: path.join(process.cwd(), "./.env")})
8
8
  const yargs = require("yargs/yargs")
9
9
  const {hideBin} = require("yargs/helpers")
10
10
 
11
- const increment_pkg = require("./src/increment-pkg")
11
+ const increment_pkg = require("./src/versions/increment-pkg")
12
12
  const print_versions = require("./src/print_versions")
13
13
  const start_command = require("./src/start_command")
14
14
  const sync_dotenv = require("./src/sync-dotenv")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/cli",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
@@ -0,0 +1,5 @@
1
+ /* @flow */
2
+
3
+ const sanitize_str = (str) => str.toLowerCase().replace(/[^a-z0-9]/g, "")
4
+
5
+ module.exports = sanitize_str
@@ -0,0 +1,26 @@
1
+ /* @flow */
2
+ const {Octokit} = require("octokit")
3
+ const colors = require("picocolors")
4
+
5
+ const get_gh_token = require("./get_gh_token")
6
+
7
+
8
+ const get_gh_client = () => {
9
+ const gh_token = get_gh_token()
10
+
11
+ if (!gh_token) return
12
+
13
+ const octokit = new Octokit({
14
+ auth: gh_token
15
+ })
16
+
17
+ if (!octokit) {
18
+ console.log(colors.bold(colors.yellow("rb increment-pkg:")), "unable to get a github client, do you have a token in .npmrc or .github_token ?")
19
+ process.exit(0)
20
+ return
21
+ }
22
+
23
+ return octokit
24
+ }
25
+
26
+ module.exports = get_gh_client
@@ -3,52 +3,38 @@ const fs = require("fs")
3
3
  const path = require("path")
4
4
  const {execSync} = require("child_process")
5
5
 
6
- const colors = require("picocolors")
7
6
  const Promise = require("bluebird")
8
7
  const semver = require("semver")
9
- const {Octokit} = require("octokit")
10
8
 
11
- const get_gh_token = require("./get_gh_token")
9
+ const sanitize_str = require("../helpers/sanitize_str")
12
10
 
11
+ const get_gh_client = require("./get_gh_client")
13
12
 
14
- const get_gh_client = () => {
15
- const gh_token = get_gh_token()
13
+ const octokit = get_gh_client()
16
14
 
17
- if (!gh_token) return
18
-
19
- const octokit = new Octokit({
20
- auth: gh_token
21
- })
22
-
23
- return octokit
24
- }
25
-
26
-
27
- const get_latest_live_version = async(pack_dir) => {
28
- const octokit = get_gh_client()
29
-
30
- if (!octokit) {
31
- console.log(colors.bold(colors.yellow("rb increment-pkg:")), "unable to get a github client, do you have a token in .npmrc or .github_token ?")
32
- process.exit(0)
33
- return
34
- }
35
15
 
16
+ const resolve_repo = () => {
36
17
  const origin_url = execSync("git remote get-url origin").toString().trim()
37
18
  const owner = path.dirname(origin_url).split(":").pop()
38
19
  const repo = path.basename(origin_url).replace(/\.git$/, "")
39
20
 
40
- const remote_path = `pkg/${pack_dir}/package.json`
21
+ const branch_name = execSync("git branch --show-current").toString().trim()
22
+
23
+ return {repo, owner, branch_name}
24
+ }
25
+
41
26
 
27
+ const get_latest_branch_version = async({owner, repo, remote_path, branch_name}) => {
42
28
  let res
43
29
  try {
44
30
  res = await octokit.request("GET /repos/{owner}/{repo}/contents/{path}", {
45
31
  owner,
46
32
  repo,
47
33
  path: remote_path,
34
+ ref: branch_name,
48
35
  })
49
36
  } catch (err) {
50
37
  if (err.response.status === 404) {
51
- console.log(`${owner}/${repo}/${remote_path} remote package not found, skipping version bump`)
52
38
  return
53
39
  } else {
54
40
  console.log(err)
@@ -57,9 +43,9 @@ const get_latest_live_version = async(pack_dir) => {
57
43
 
58
44
  const file_contents = Buffer.from(res.data.content, "base64").toString()
59
45
  const pack_obj = JSON.parse(file_contents)
60
- const live_version = pack_obj.version
46
+ const branch_version = pack_obj.version
61
47
 
62
- return live_version
48
+ return branch_version
63
49
  }
64
50
 
65
51
 
@@ -82,6 +68,8 @@ const increment_pkg = async(args) => {
82
68
  }
83
69
  })
84
70
 
71
+ const {repo, owner, branch_name} = resolve_repo()
72
+
85
73
  const process_package = async(pack_dir) => {
86
74
  const local_pack_path = path.join(packages_dir, `./${pack_dir}/package.json`)
87
75
  const local_pack = JSON.parse(fs.readFileSync(local_pack_path))
@@ -92,31 +80,52 @@ const increment_pkg = async(args) => {
92
80
  return
93
81
  }
94
82
 
95
- const live_version = await get_latest_live_version(pack_dir)
96
-
97
- if (!semver.valid(live_version)) {
98
- console.log("warning:", "live version not valid, got:", JSON.stringify(live_version), "skipping")
99
- return
100
- }
101
-
102
83
  if (!semver.valid(local_version)) {
103
84
  console.log("error:", "local version not valid, got:", JSON.stringify(local_version), "skipping")
104
- process.exit(1)
105
85
  return
106
86
  }
107
87
 
108
- // if local_version == live_version -> bump
109
- if (live_version && semver.eq(local_version, live_version)) {
110
- const new_version = semver.inc(local_version, "minor")
88
+ // get remote + next version
89
+ const remote_path = `pkg/${pack_dir}/package.json`
90
+
91
+ const master_version = await get_latest_branch_version({
92
+ owner,
93
+ repo,
94
+ remote_path,
95
+ branch_name: "master"
96
+ })
97
+
98
+ if (!master_version || !semver.valid(master_version)) {
99
+ console.log("error:", "remote master version not valid, got:", JSON.stringify(master_version), "skipping")
100
+ return
101
+ }
111
102
 
112
- console.log("bumped", local_pack.name, "to", new_version)
103
+ const bumped_version = semver.inc(master_version, "minor")
113
104
 
114
- local_pack.version = new_version
105
+ if (semver.lt(local_version, bumped_version)) {
106
+ local_pack.version = bumped_version,
115
107
  fs.writeFileSync(local_pack_path, JSON.stringify(local_pack, null, 2) + "\n")
116
-
117
- // add to git index, in case change was not triggered by package.json
118
108
  execSync(`git add ${local_pack_path}`)
119
109
  }
110
+
111
+ // TODO: this will run on the PR workflow but not before commit here, as we only want a minor bump when incrementing from master, the release channels are handled in CI
112
+ // const {remote_version, next_version} = await get_remote_next_version({owner, repo, branch_name, remote_path, local_version})
113
+ //
114
+ // if (!semver.valid(remote_version)) {
115
+ // console.log("warning:", "live version not valid, got:", JSON.stringify(remote_version), "skipping")
116
+ // return
117
+ // }
118
+ //
119
+ // // if (next_version && semver.neq(remote_version, next_version)) {
120
+ // if (next_version && semver.neq(local_version, next_version)) {
121
+ // console.log("bumped", local_pack.name, "to", next_version)
122
+ //
123
+ // local_pack.version = next_version
124
+ //
125
+ // fs.writeFileSync(local_pack_path, JSON.stringify(local_pack, null, 2) + "\n")
126
+ // // add to git index, in case change was not triggered by package.json
127
+ // execSync(`git add ${local_pack_path}`)
128
+ // }
120
129
  }
121
130
 
122
131
  await Promise.map(Object.keys(touched_packages), process_package)