@motionode/cli 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -20,5 +20,5 @@ motionode finish T11-518 # Motionode checks your pushed commits and moves the
20
20
  - It runs only fixed git operations Motionode can ask for (check out a ticket
21
21
  branch, show a diff, commit and push, move changes onto a ticket branch) —
22
22
  never arbitrary commands.
23
- - `--api URL` (or `MOTIONODE_API_URL`) points it at another Motionode API.
23
+ - `motionode use <url>` points every terminal at another Motionode API until `motionode use production`; `--api URL` or `MOTIONODE_API_URL` overrides it for one run. `motionode where` shows the current one.
24
24
  - Revoke a computer in Motionode → Settings → Development workflow.
package/bin/motionode.js CHANGED
@@ -16,10 +16,11 @@ const HELP = `motionode ${version} — work Motionode tickets with your own loca
16
16
  motionode finish <ticket> [--force] [--note] you're done: Motionode checks your pushed commits and moves it on
17
17
  motionode status what each linked folder has checked out and changed
18
18
  motionode where which Motionode this terminal talks to
19
+ motionode use <url|production> switch which Motionode the CLI talks to (remembered)
19
20
  motionode logout disconnect this computer
20
21
 
21
22
  Git stays yours: fetch, commit and push use your own git credentials and identity.
22
- Talks to production (https://api.motionode.com) unless MOTIONODE_API_URL or --api says otherwise;
23
+ Talks to production (https://api.motionode.com) unless "motionode use", MOTIONODE_API_URL or --api says otherwise;
23
24
  each Motionode keeps its own connection.`;
24
25
 
25
26
  function flags(argv) {
@@ -59,6 +60,12 @@ async function main() {
59
60
  return Commands.finish(config, args._[0], { force: !!args.force, note: typeof args.note === 'string' ? args.note : null });
60
61
  case 'status':
61
62
  return Commands.status(config);
63
+ case 'use': {
64
+ const api = Config.useApi(args._[0]);
65
+ const next = Config.load();
66
+ console.log(`✓ Using ${api}${next.token ? '' : ' — run "motionode connect" in a repository folder to connect this computer to it'}`);
67
+ return null;
68
+ }
62
69
  case 'where':
63
70
  console.log(`${config.apiUrl}${config.token ? ` — connected as ${config.user?.name || config.user?.email || 'you'} (${config.machine?.name || 'this computer'})` : ' — not connected'}`);
64
71
  return null;
package/lib/config.js CHANGED
@@ -21,9 +21,33 @@ function normalizeApi(url) {
21
21
  return String(url || '').trim().replace(/\/+$/, '') || null;
22
22
  }
23
23
 
24
- /** The API this run talks to: --api, then MOTIONODE_API_URL, then production. */
24
+ const CURRENT_FILE = path.join(DIR, 'current.json');
25
+
26
+ /** The Motionode chosen with `motionode use` (stays until changed). */
27
+ function savedApi() {
28
+ try {
29
+ return normalizeApi(JSON.parse(fs.readFileSync(CURRENT_FILE, 'utf8')).apiUrl);
30
+ } catch (_e) {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ /** `motionode use <url|production>` — which Motionode every terminal talks to. */
36
+ function useApi(url) {
37
+ const next = String(url || '').trim().toLowerCase() === 'production' ? PRODUCTION_API : normalizeApi(url);
38
+ if (!next || !/^https?:\/\//.test(next)) throw new Error('Give a Motionode API address (https://…) or "production".');
39
+ fs.mkdirSync(DIR, { recursive: true });
40
+ if (next === PRODUCTION_API) {
41
+ try { fs.unlinkSync(CURRENT_FILE); } catch (_e) { /* already production */ }
42
+ } else {
43
+ fs.writeFileSync(CURRENT_FILE, JSON.stringify({ apiUrl: next }, null, 2));
44
+ }
45
+ return next;
46
+ }
47
+
48
+ /** The API this run talks to: --api, then MOTIONODE_API_URL, then `motionode use`, then production. */
25
49
  function resolveApi(override = null) {
26
- return normalizeApi(override) || normalizeApi(process.env.MOTIONODE_API_URL) || PRODUCTION_API;
50
+ return normalizeApi(override) || normalizeApi(process.env.MOTIONODE_API_URL) || savedApi() || PRODUCTION_API;
27
51
  }
28
52
 
29
53
  function fileFor(apiUrl) {
@@ -63,4 +87,4 @@ function workspaceForPath(config, dir) {
63
87
  return (config.workspaces || []).find((w) => samePath(w.path, dir)) || null;
64
88
  }
65
89
 
66
- module.exports = { DIR, PRODUCTION_API, resolveApi, fileFor, load, save, samePath, workspaceForPath };
90
+ module.exports = { DIR, PRODUCTION_API, resolveApi, useApi, fileFor, load, save, samePath, workspaceForPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionode/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Connect your local repositories to Motionode: work tickets in Cursor, VS Code or any editor while Motionode keeps the work tied to the ticket, its git branches, verification and delivery.",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {