@gheima/cli 0.9.1 → 0.9.3
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/CHANGELOG.md +12 -0
- package/dist/cli.js +11 -3
- package/dist/device-login.js +15 -3
- package/dist/git-remote.js +27 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @gheima/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2910318: `gheima deploy` takes `--type WEB|WORKER|STATIC` for the service its first run creates, and a folder of plain HTML files (an `index.html` and nothing that builds or runs a server) now becomes a static site on its own. Plans count static sites apart from services, so on a Free plan whose one service is taken, a static site still deploys instead of hitting the service limit.
|
|
8
|
+
|
|
9
|
+
## 0.9.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ff3385e: A sign-in that can no longer succeed now reports a stable error code under `--json`: `login_expired` (expired or already used) or `login_denied`, instead of the generic `error`, so a script or an agent knows to start a new one with `gheima login --no-wait`.
|
|
14
|
+
|
|
3
15
|
## 0.9.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -17,9 +17,9 @@ import { completionScript } from './completion.js';
|
|
|
17
17
|
import { callOp, registerGenerated } from './generated.js';
|
|
18
18
|
import { findLink, toDotenv, writeLink } from './link.js';
|
|
19
19
|
import { listSourceFiles, packSource } from './pack.js';
|
|
20
|
-
import { defaultServiceName, gitRemote, gitSubdir } from './git-remote.js';
|
|
20
|
+
import { defaultServiceName, detectServiceType, gitRemote, gitSubdir } from './git-remote.js';
|
|
21
21
|
import { AGENTS_FILE, agentsSection, upsertAgentsMd } from './agents-md.js';
|
|
22
|
-
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
22
|
+
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginEnded, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
23
23
|
const program = new Command();
|
|
24
24
|
program
|
|
25
25
|
.name('gheima')
|
|
@@ -85,6 +85,8 @@ function localErrorCode(err) {
|
|
|
85
85
|
return 'unauthenticated';
|
|
86
86
|
if (err instanceof LoginStillPending)
|
|
87
87
|
return 'login_pending';
|
|
88
|
+
if (err instanceof LoginEnded)
|
|
89
|
+
return err.code;
|
|
88
90
|
return 'error';
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
@@ -1150,6 +1152,7 @@ program
|
|
|
1150
1152
|
.option('--timeout <minutes>', 'stop waiting after this long (exit 7)', '30')
|
|
1151
1153
|
.option('--upload', 'upload this folder instead of building from the git remote')
|
|
1152
1154
|
.option('--name <name>', 'name of the service the first deploy creates (default: the folder name)')
|
|
1155
|
+
.option('--type <type>', 'type of the service the first deploy creates: WEB | WORKER | STATIC (default: STATIC for a plain HTML folder, else WEB)')
|
|
1153
1156
|
.option('-y, --yes', 'create the service without asking (needed without a terminal)')
|
|
1154
1157
|
.action(async (ref, opts, cmd) => {
|
|
1155
1158
|
const g = globals(cmd);
|
|
@@ -1200,9 +1203,14 @@ async function serviceToDeploy(client, ref, dir, opts) {
|
|
|
1200
1203
|
return { id: await resolveServiceId(client, ref), created: false };
|
|
1201
1204
|
const remote = opts.upload ? null : gitRemote(dir);
|
|
1202
1205
|
const name = opts.name ?? defaultServiceName(dir);
|
|
1203
|
-
|
|
1206
|
+
const type = (opts.type?.toUpperCase() ?? detectServiceType(dir));
|
|
1207
|
+
if (!['WEB', 'WORKER', 'STATIC'].includes(type)) {
|
|
1208
|
+
throw new UsageError(`--type must be WEB, WORKER or STATIC, not ${opts.type}.`);
|
|
1209
|
+
}
|
|
1210
|
+
await confirmDestructive(opts.yes, `create the ${type === 'STATIC' ? 'static site' : 'service'} "${name}" ${remote ? `from ${remote.url} (${remote.branch})` : 'from the files in this folder'}`);
|
|
1204
1211
|
const created = await client.services.create({
|
|
1205
1212
|
name,
|
|
1213
|
+
type,
|
|
1206
1214
|
...(remote ? { repoUrl: remote.url, repoBranch: remote.branch } : {}),
|
|
1207
1215
|
});
|
|
1208
1216
|
// Run from a subfolder of a repository (a monorepo app): build that folder, not the root. An
|
package/dist/device-login.js
CHANGED
|
@@ -90,6 +90,18 @@ export class LoginStillPending extends Error {
|
|
|
90
90
|
'`gheima login --resume` once they say they have approved.');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A sign-in that can no longer succeed: it expired, was already used, or was denied. Carries a
|
|
95
|
+
* stable `code` so a script or an agent knows to start a new one with `login --no-wait`.
|
|
96
|
+
*/
|
|
97
|
+
export class LoginEnded extends Error {
|
|
98
|
+
code;
|
|
99
|
+
name = 'LoginEnded';
|
|
100
|
+
constructor(message, code) {
|
|
101
|
+
super(message);
|
|
102
|
+
this.code = code;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
94
106
|
/**
|
|
95
107
|
* Poll until the login is approved, denied or expires.
|
|
@@ -106,7 +118,7 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
106
118
|
let intervalMs = Math.max(1, start.interval) * 1000;
|
|
107
119
|
for (;;) {
|
|
108
120
|
if (now() >= deadline) {
|
|
109
|
-
throw new
|
|
121
|
+
throw new LoginEnded(`This sign-in expired before it was approved. ${restart}`, 'login_expired');
|
|
110
122
|
}
|
|
111
123
|
if (opts.giveUpAt !== undefined && now() >= opts.giveUpAt)
|
|
112
124
|
throw new LoginStillPending();
|
|
@@ -127,9 +139,9 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
127
139
|
opts.onSlowDown?.(Math.round(intervalMs / 1000));
|
|
128
140
|
break;
|
|
129
141
|
case 'access_denied':
|
|
130
|
-
throw new
|
|
142
|
+
throw new LoginEnded(`The sign-in was denied in the dashboard. ${restart}`, 'login_denied');
|
|
131
143
|
case 'expired_token':
|
|
132
|
-
throw new
|
|
144
|
+
throw new LoginEnded(`This sign-in expired or was already used. ${restart}`, 'login_expired');
|
|
133
145
|
default:
|
|
134
146
|
throw new Error(body.error?.message ?? `Sign-in failed (HTTP ${res.status}). ${restart}`);
|
|
135
147
|
}
|
package/dist/git-remote.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
4
|
const git = (dir, ...args) => {
|
|
5
5
|
const r = spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8' });
|
|
@@ -65,3 +65,29 @@ export function defaultServiceName(dir) {
|
|
|
65
65
|
export function gitSubdir(dir) {
|
|
66
66
|
return git(dir, 'rev-parse', '--show-prefix').replace(/\/$/, '');
|
|
67
67
|
}
|
|
68
|
+
/** Files that mean the folder is an app with a server or a build, not a bundle of static files. */
|
|
69
|
+
const APP_MARKERS = [
|
|
70
|
+
'package.json',
|
|
71
|
+
'requirements.txt',
|
|
72
|
+
'pyproject.toml',
|
|
73
|
+
'Pipfile',
|
|
74
|
+
'go.mod',
|
|
75
|
+
'Gemfile',
|
|
76
|
+
'composer.json',
|
|
77
|
+
'Cargo.toml',
|
|
78
|
+
'pom.xml',
|
|
79
|
+
'build.gradle',
|
|
80
|
+
'mix.exs',
|
|
81
|
+
'Dockerfile',
|
|
82
|
+
'deno.json',
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* The service type the first deploy of `dir` creates: STATIC for a plain site (an `index.html`
|
|
86
|
+
* at the root and nothing that builds or runs a server), WEB otherwise. A static site is served
|
|
87
|
+
* by nginx with no runtime, and plans count it apart from services (Free has one of each).
|
|
88
|
+
*/
|
|
89
|
+
export function detectServiceType(dir) {
|
|
90
|
+
if (!existsSync(join(dir, 'index.html')))
|
|
91
|
+
return 'WEB';
|
|
92
|
+
return APP_MARKERS.some((f) => existsSync(join(dir, f))) ? 'WEB' : 'STATIC';
|
|
93
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// GENERATED by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.3';
|