@formigio/fazemos-cli 0.10.37 → 0.10.38
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/dist/config.d.ts +16 -0
- package/dist/config.js +31 -0
- package/dist/config.js.map +1 -1
- package/dist/dircontext.d.ts +45 -0
- package/dist/dircontext.js +89 -0
- package/dist/dircontext.js.map +1 -0
- package/dist/index.js +177 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -94,6 +94,22 @@ export declare function getEnv(): {
|
|
|
94
94
|
export declare function getToken(): string | null;
|
|
95
95
|
export declare function getActiveOrgId(): string | null;
|
|
96
96
|
export declare function setActiveOrgId(orgId: string): void;
|
|
97
|
+
/** Set the in-memory active-org override (resolved org id, or null to clear). */
|
|
98
|
+
export declare function setOrgOverride(orgId: string | null): void;
|
|
99
|
+
/** Set the in-memory active-project override (resolved project id, or null to clear). */
|
|
100
|
+
export declare function setProjectOverride(projectId: string | null): void;
|
|
101
|
+
/** Record where the directory context came from, for display in whoami/config. */
|
|
102
|
+
export declare function setDirContextSource(source: {
|
|
103
|
+
path: string;
|
|
104
|
+
org?: string;
|
|
105
|
+
project?: string;
|
|
106
|
+
} | null): void;
|
|
107
|
+
/** Returns the directory-context source (file path + raw slugs) if one is active. */
|
|
108
|
+
export declare function getDirContextSource(): {
|
|
109
|
+
path: string;
|
|
110
|
+
org?: string;
|
|
111
|
+
project?: string;
|
|
112
|
+
} | null;
|
|
97
113
|
export declare function setAuth(env: string, email: string, idToken: string, refreshToken: string, expiresInSeconds: number): void;
|
|
98
114
|
/**
|
|
99
115
|
* Returns the active project id for the currently-active org, or null if
|
package/dist/config.js
CHANGED
|
@@ -39,12 +39,41 @@ export function getToken() {
|
|
|
39
39
|
return auth.idToken;
|
|
40
40
|
}
|
|
41
41
|
export function getActiveOrgId() {
|
|
42
|
+
if (orgOverride)
|
|
43
|
+
return orgOverride;
|
|
42
44
|
const orgId = config.get('activeOrgId');
|
|
43
45
|
return orgId || null;
|
|
44
46
|
}
|
|
45
47
|
export function setActiveOrgId(orgId) {
|
|
46
48
|
config.set('activeOrgId', orgId);
|
|
47
49
|
}
|
|
50
|
+
// ── Directory-scoped context override (.fazemos.json) ───────
|
|
51
|
+
//
|
|
52
|
+
// A `.fazemos.json` discovered by walking up from the cwd pins a default org
|
|
53
|
+
// and project for the working directory. These overrides are resolved once at
|
|
54
|
+
// CLI bootstrap (slug → id against /auth/me) and held in memory for the
|
|
55
|
+
// process. They take precedence over the persisted "active" selection but sit
|
|
56
|
+
// below an explicit `--project` flag (which is threaded via ApiOptions). See
|
|
57
|
+
// src/dircontext.ts and the preAction hook in src/index.ts.
|
|
58
|
+
let orgOverride = null;
|
|
59
|
+
let projectOverride = null;
|
|
60
|
+
let dirContextSource = null;
|
|
61
|
+
/** Set the in-memory active-org override (resolved org id, or null to clear). */
|
|
62
|
+
export function setOrgOverride(orgId) {
|
|
63
|
+
orgOverride = orgId;
|
|
64
|
+
}
|
|
65
|
+
/** Set the in-memory active-project override (resolved project id, or null to clear). */
|
|
66
|
+
export function setProjectOverride(projectId) {
|
|
67
|
+
projectOverride = projectId;
|
|
68
|
+
}
|
|
69
|
+
/** Record where the directory context came from, for display in whoami/config. */
|
|
70
|
+
export function setDirContextSource(source) {
|
|
71
|
+
dirContextSource = source;
|
|
72
|
+
}
|
|
73
|
+
/** Returns the directory-context source (file path + raw slugs) if one is active. */
|
|
74
|
+
export function getDirContextSource() {
|
|
75
|
+
return dirContextSource;
|
|
76
|
+
}
|
|
48
77
|
export function setAuth(env, email, idToken, refreshToken, expiresInSeconds) {
|
|
49
78
|
const auth = config.get('auth');
|
|
50
79
|
auth[env] = {
|
|
@@ -63,6 +92,8 @@ export function setAuth(env, email, idToken, refreshToken, expiresInSeconds) {
|
|
|
63
92
|
* "requirement missing: project" error when the API says so.
|
|
64
93
|
*/
|
|
65
94
|
export function getActiveProjectId() {
|
|
95
|
+
if (projectOverride)
|
|
96
|
+
return projectOverride;
|
|
66
97
|
const orgId = getActiveOrgId();
|
|
67
98
|
if (!orgId)
|
|
68
99
|
return null;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AA+ExB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAgB;IAC5C,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE;QACR,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,kBAAkB,EAAE,EAAE;QACtB,IAAI,EAAE,EAAE;KACT;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAA8F;IACzI,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;IACjB,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IACjC,iCAAiC;IACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,MAAM;IACpB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CA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QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-directory default org/project context.
|
|
3
|
+
*
|
|
4
|
+
* A `.fazemos.json` file pins the default org and project for a working
|
|
5
|
+
* directory (and everything beneath it), so running the CLI inside a given
|
|
6
|
+
* project tree scopes every call to that org/project without a manual
|
|
7
|
+
* `orgs switch` / `projects switch`. Discovery walks up from the cwd to the
|
|
8
|
+
* filesystem root — the nearest file wins — exactly like git, eslint, etc.
|
|
9
|
+
*
|
|
10
|
+
* Values are stored as **slugs** (not UUIDs) so the file is human-readable,
|
|
11
|
+
* git-committable, and resolves correctly across environments (dev/prod have
|
|
12
|
+
* different ids for the same org/project). Slug → id resolution happens at
|
|
13
|
+
* call time against the cached /auth/me response.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DIR_CONFIG_FILENAME = ".fazemos.json";
|
|
16
|
+
export interface DirContext {
|
|
17
|
+
/** Org slug (or UUID) to pin for this directory. */
|
|
18
|
+
org?: string;
|
|
19
|
+
/** Project slug (or UUID) to pin for this directory. */
|
|
20
|
+
project?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface FoundDirContext {
|
|
23
|
+
/** Absolute path to the `.fazemos.json` that supplied the context. */
|
|
24
|
+
path: string;
|
|
25
|
+
context: DirContext;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Read the `.fazemos.json` in a single directory (no walk-up). Returns null
|
|
29
|
+
* when the file is absent. Throws on malformed JSON so the caller can surface
|
|
30
|
+
* a clear error rather than silently ignoring a typo'd config.
|
|
31
|
+
*/
|
|
32
|
+
export declare function readDirContextFile(dir: string): FoundDirContext | null;
|
|
33
|
+
/**
|
|
34
|
+
* Walk up from `startDir` to the filesystem root looking for the nearest
|
|
35
|
+
* `.fazemos.json`. Returns null if none is found. Throws if the nearest file
|
|
36
|
+
* is malformed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findDirContextFile(startDir?: string): FoundDirContext | null;
|
|
39
|
+
/**
|
|
40
|
+
* Write a `.fazemos.json` into `dir`. Fields with no value are omitted so the
|
|
41
|
+
* file stays minimal. Returns the absolute path written.
|
|
42
|
+
*/
|
|
43
|
+
export declare function writeDirContextFile(dir: string, context: DirContext): string;
|
|
44
|
+
/** Remove the `.fazemos.json` in `dir`. Returns the path if one was removed, else null. */
|
|
45
|
+
export declare function removeDirContextFile(dir: string): string | null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, rmSync } from 'fs';
|
|
2
|
+
import { dirname, join, parse as parsePath } from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Per-directory default org/project context.
|
|
5
|
+
*
|
|
6
|
+
* A `.fazemos.json` file pins the default org and project for a working
|
|
7
|
+
* directory (and everything beneath it), so running the CLI inside a given
|
|
8
|
+
* project tree scopes every call to that org/project without a manual
|
|
9
|
+
* `orgs switch` / `projects switch`. Discovery walks up from the cwd to the
|
|
10
|
+
* filesystem root — the nearest file wins — exactly like git, eslint, etc.
|
|
11
|
+
*
|
|
12
|
+
* Values are stored as **slugs** (not UUIDs) so the file is human-readable,
|
|
13
|
+
* git-committable, and resolves correctly across environments (dev/prod have
|
|
14
|
+
* different ids for the same org/project). Slug → id resolution happens at
|
|
15
|
+
* call time against the cached /auth/me response.
|
|
16
|
+
*/
|
|
17
|
+
export const DIR_CONFIG_FILENAME = '.fazemos.json';
|
|
18
|
+
/** Parse a raw object into a DirContext, tolerating unknown fields. */
|
|
19
|
+
function coerce(parsed, file) {
|
|
20
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
21
|
+
throw new Error(`Invalid ${DIR_CONFIG_FILENAME} at ${file}: expected a JSON object`);
|
|
22
|
+
}
|
|
23
|
+
const obj = parsed;
|
|
24
|
+
const ctx = {};
|
|
25
|
+
if (typeof obj.org === 'string' && obj.org.trim())
|
|
26
|
+
ctx.org = obj.org.trim();
|
|
27
|
+
if (typeof obj.project === 'string' && obj.project.trim())
|
|
28
|
+
ctx.project = obj.project.trim();
|
|
29
|
+
return ctx;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read the `.fazemos.json` in a single directory (no walk-up). Returns null
|
|
33
|
+
* when the file is absent. Throws on malformed JSON so the caller can surface
|
|
34
|
+
* a clear error rather than silently ignoring a typo'd config.
|
|
35
|
+
*/
|
|
36
|
+
export function readDirContextFile(dir) {
|
|
37
|
+
const file = join(dir, DIR_CONFIG_FILENAME);
|
|
38
|
+
if (!existsSync(file))
|
|
39
|
+
return null;
|
|
40
|
+
let parsed;
|
|
41
|
+
try {
|
|
42
|
+
parsed = JSON.parse(readFileSync(file, 'utf-8'));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
throw new Error(`Invalid ${DIR_CONFIG_FILENAME} at ${file}: ${err.message}`);
|
|
46
|
+
}
|
|
47
|
+
return { path: file, context: coerce(parsed, file) };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Walk up from `startDir` to the filesystem root looking for the nearest
|
|
51
|
+
* `.fazemos.json`. Returns null if none is found. Throws if the nearest file
|
|
52
|
+
* is malformed.
|
|
53
|
+
*/
|
|
54
|
+
export function findDirContextFile(startDir = process.cwd()) {
|
|
55
|
+
const root = parsePath(startDir).root;
|
|
56
|
+
let dir = startDir;
|
|
57
|
+
// eslint-disable-next-line no-constant-condition
|
|
58
|
+
while (true) {
|
|
59
|
+
const found = readDirContextFile(dir);
|
|
60
|
+
if (found)
|
|
61
|
+
return found;
|
|
62
|
+
if (dir === root)
|
|
63
|
+
return null;
|
|
64
|
+
dir = dirname(dir);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Write a `.fazemos.json` into `dir`. Fields with no value are omitted so the
|
|
69
|
+
* file stays minimal. Returns the absolute path written.
|
|
70
|
+
*/
|
|
71
|
+
export function writeDirContextFile(dir, context) {
|
|
72
|
+
const file = join(dir, DIR_CONFIG_FILENAME);
|
|
73
|
+
const out = {};
|
|
74
|
+
if (context.org)
|
|
75
|
+
out.org = context.org;
|
|
76
|
+
if (context.project)
|
|
77
|
+
out.project = context.project;
|
|
78
|
+
writeFileSync(file, JSON.stringify(out, null, 2) + '\n', 'utf-8');
|
|
79
|
+
return file;
|
|
80
|
+
}
|
|
81
|
+
/** Remove the `.fazemos.json` in `dir`. Returns the path if one was removed, else null. */
|
|
82
|
+
export function removeDirContextFile(dir) {
|
|
83
|
+
const file = join(dir, DIR_CONFIG_FILENAME);
|
|
84
|
+
if (!existsSync(file))
|
|
85
|
+
return null;
|
|
86
|
+
rmSync(file);
|
|
87
|
+
return file;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=dircontext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dircontext.js","sourceRoot":"","sources":["../src/dircontext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAenD,uEAAuE;AACvE,S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-3,9 +3,12 @@ import { Command } from 'commander';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { config, getEnv, getToken, getActiveOrgId, setActiveOrgId, addEnvironment, hasEnvironments,
|
|
5
5
|
// F15 — project context helpers
|
|
6
|
-
getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug, findProjectById, findOrgById,
|
|
6
|
+
getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug, findProjectById, findOrgById,
|
|
7
|
+
// Directory-scoped context override (.fazemos.json)
|
|
8
|
+
setOrgOverride, setProjectOverride, setDirContextSource, getDirContextSource, } from './config.js';
|
|
9
|
+
import { findDirContextFile, readDirContextFile, writeDirContextFile, removeDirContextFile, DIR_CONFIG_FILENAME, } from './dircontext.js';
|
|
7
10
|
import { login, signup, confirmSignup, adminLogin } from './auth.js';
|
|
8
|
-
import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug } from './api.js';
|
|
11
|
+
import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug, resolveProjectIdBySlug } from './api.js';
|
|
9
12
|
import { isProjectConnectionUnavailable, renderProjectConnectionUnavailableCopy, } from './connectionErrorCopy.js';
|
|
10
13
|
import { loadYaml, summarize } from './yaml/load.js';
|
|
11
14
|
import { printFindings, printJson } from './yaml/format.js';
|
|
@@ -21,7 +24,7 @@ import { registerGovernanceCommands } from './governance.js';
|
|
|
21
24
|
import { parseExecutionsJson, resolveWaitOptions, waitForPipelines, buildAwsCommand, validateExecutionEntry, } from './wait-for-pipeline.js';
|
|
22
25
|
import { readFileSync, readdirSync, writeFileSync, mkdirSync, existsSync, statSync } from 'fs';
|
|
23
26
|
import { fileURLToPath } from 'url';
|
|
24
|
-
import { dirname, resolve, basename } from 'path';
|
|
27
|
+
import { dirname, resolve, basename, relative } from 'path';
|
|
25
28
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
26
29
|
const pkg = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf-8'));
|
|
27
30
|
function parseNumber(val) {
|
|
@@ -193,6 +196,81 @@ program
|
|
|
193
196
|
.name('fazemos')
|
|
194
197
|
.description('Fazemos CLI — Team Accomplishment Platform')
|
|
195
198
|
.version(pkg.version);
|
|
199
|
+
// ── Directory-scoped default org/project (.fazemos.json) ─────
|
|
200
|
+
//
|
|
201
|
+
// Before any command action runs, discover the nearest `.fazemos.json`
|
|
202
|
+
// (walking up from the cwd) and resolve its org/project slugs to ids, holding
|
|
203
|
+
// them as in-memory overrides for the process. This scopes every call to the
|
|
204
|
+
// pinned org/project without a manual `orgs switch` / `projects switch`.
|
|
205
|
+
//
|
|
206
|
+
// Resolution is best-effort: if a slug can't be resolved (not logged in, slug
|
|
207
|
+
// not in your memberships, stale cache) we leave the override unset and let the
|
|
208
|
+
// normal active-selection + API error path take over. Network resolution is
|
|
209
|
+
// skipped for the bootstrap commands that don't need a scoped context.
|
|
210
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
211
|
+
/** Top-level commands that never need (and shouldn't trigger) context resolution. */
|
|
212
|
+
const DIR_CONTEXT_SKIP = new Set(['use', 'auth', 'env', 'init']);
|
|
213
|
+
let dirContextApplied = false;
|
|
214
|
+
async function applyDirContext(topCommand) {
|
|
215
|
+
if (dirContextApplied)
|
|
216
|
+
return;
|
|
217
|
+
dirContextApplied = true;
|
|
218
|
+
let found;
|
|
219
|
+
try {
|
|
220
|
+
found = findDirContextFile();
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
// Malformed .fazemos.json — surface it for normal commands, but don't
|
|
224
|
+
// abort. The bootstrap commands (notably `use`) report it themselves, so
|
|
225
|
+
// stay silent for them to avoid a double warning.
|
|
226
|
+
if (!DIR_CONTEXT_SKIP.has(topCommand))
|
|
227
|
+
console.error(chalk.yellow(err.message));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (!found)
|
|
231
|
+
return;
|
|
232
|
+
// Record the source so whoami/config can show where the scope came from.
|
|
233
|
+
setDirContextSource({ path: found.path, ...found.context });
|
|
234
|
+
// Bootstrap commands (auth/env/init/use) operate without a resolved scope.
|
|
235
|
+
if (DIR_CONTEXT_SKIP.has(topCommand))
|
|
236
|
+
return;
|
|
237
|
+
const { org, project } = found.context;
|
|
238
|
+
if (org) {
|
|
239
|
+
try {
|
|
240
|
+
setOrgOverride(await resolveOrgIdMaybeSlug(org));
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// Unresolved org slug — leave unset; the command's own "no active org"
|
|
244
|
+
// check or the API will report the problem with full context.
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (project) {
|
|
248
|
+
try {
|
|
249
|
+
if (UUID_RE.test(project)) {
|
|
250
|
+
setProjectOverride(project);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// Resolves against the active org, which now reflects the org override.
|
|
254
|
+
const projectId = await resolveProjectIdBySlug(project);
|
|
255
|
+
if (projectId)
|
|
256
|
+
setProjectOverride(projectId);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
// Unresolved project slug — leave unset; surfaced downstream.
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
program.hook('preAction', async (_thisCommand, actionCommand) => {
|
|
265
|
+
// Resolve the top-level command name (e.g. `worksheets list` → `worksheets`).
|
|
266
|
+
let c = actionCommand;
|
|
267
|
+
let top = c?.name?.();
|
|
268
|
+
while (c?.parent && c.parent !== program) {
|
|
269
|
+
c = c.parent;
|
|
270
|
+
top = c.name();
|
|
271
|
+
}
|
|
272
|
+
await applyDirContext(top ?? '');
|
|
273
|
+
});
|
|
196
274
|
// ── Init ────────────────────────────────────────────────────
|
|
197
275
|
program
|
|
198
276
|
.command('init')
|
|
@@ -401,6 +479,94 @@ program
|
|
|
401
479
|
else {
|
|
402
480
|
console.log(` Project: ${chalk.gray('(none set — fazemos projects switch <slug>)')}`);
|
|
403
481
|
}
|
|
482
|
+
// Note when the org/project scope is coming from a directory .fazemos.json
|
|
483
|
+
// rather than the persisted active selection, so the source is obvious.
|
|
484
|
+
const dirSource = getDirContextSource();
|
|
485
|
+
if (dirSource) {
|
|
486
|
+
const rel = relative(process.cwd(), dirSource.path) || dirSource.path;
|
|
487
|
+
console.log(chalk.gray(` Scope: from ${rel} (fazemos use)`));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (err) {
|
|
491
|
+
console.error(chalk.red(err.message));
|
|
492
|
+
process.exit(1);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
// ── Directory context (`fazemos use`) ───────────────────────
|
|
496
|
+
program
|
|
497
|
+
.command('use')
|
|
498
|
+
.description(`Set the default org/project for the current directory (writes ${DIR_CONFIG_FILENAME}). Running the CLI anywhere under that directory scopes calls to this org/project automatically.`)
|
|
499
|
+
.option('-o, --org <slug>', 'Org slug to pin for this directory')
|
|
500
|
+
.option('-p, --project <slug>', 'Project slug to pin for this directory')
|
|
501
|
+
.option('--show', 'Show the directory context in effect and which file provides it')
|
|
502
|
+
.option('--clear', `Remove ${DIR_CONFIG_FILENAME} from the current directory`)
|
|
503
|
+
.action(async (opts) => {
|
|
504
|
+
try {
|
|
505
|
+
// --show (also the default when no flags are given): report the nearest
|
|
506
|
+
// .fazemos.json and the effective scope.
|
|
507
|
+
if (opts.show || (!opts.org && !opts.project && !opts.clear)) {
|
|
508
|
+
const found = findDirContextFile();
|
|
509
|
+
if (!found) {
|
|
510
|
+
console.log(chalk.gray(`No ${DIR_CONFIG_FILENAME} found in this directory or any parent.`));
|
|
511
|
+
console.log(chalk.gray('Set one with: fazemos use --org <slug> --project <slug>'));
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const rel = relative(process.cwd(), found.path) || found.path;
|
|
515
|
+
console.log(`Directory context (${chalk.cyan(rel)}):`);
|
|
516
|
+
console.log(` Org: ${found.context.org ? chalk.cyan(found.context.org) : chalk.gray('(not set)')}`);
|
|
517
|
+
console.log(` Project: ${found.context.project ? chalk.cyan(found.context.project) : chalk.gray('(not set)')}`);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
// --clear: remove the .fazemos.json in the cwd (not a parent's).
|
|
521
|
+
if (opts.clear) {
|
|
522
|
+
const removed = removeDirContextFile(process.cwd());
|
|
523
|
+
if (removed) {
|
|
524
|
+
console.log(chalk.green(`Removed ${DIR_CONFIG_FILENAME} from this directory.`));
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
console.log(chalk.gray(`No ${DIR_CONFIG_FILENAME} in this directory to remove.`));
|
|
528
|
+
}
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
// Merge onto any existing file in the cwd so `use --project x` keeps a
|
|
532
|
+
// previously-pinned org (and vice versa).
|
|
533
|
+
const existing = readDirContextFile(process.cwd())?.context ?? {};
|
|
534
|
+
const orgSlug = opts.org ?? existing.org;
|
|
535
|
+
const projectSlug = opts.project ?? existing.project;
|
|
536
|
+
if (opts.project && !orgSlug) {
|
|
537
|
+
console.error(chalk.red('Cannot pin a project without an org. Pass --org <slug> too.'));
|
|
538
|
+
process.exit(1);
|
|
539
|
+
}
|
|
540
|
+
// Validate the org slug against your memberships (resolves + caches
|
|
541
|
+
// /auth/me). resolveOrgIdMaybeSlug throws a clear error on an unknown slug.
|
|
542
|
+
let orgName = orgSlug;
|
|
543
|
+
let resolvedOrgId = null;
|
|
544
|
+
if (orgSlug) {
|
|
545
|
+
resolvedOrgId = await resolveOrgIdMaybeSlug(orgSlug);
|
|
546
|
+
orgName = findOrgById(resolvedOrgId)?.name ?? orgSlug;
|
|
547
|
+
}
|
|
548
|
+
// Validate the project slug within that org.
|
|
549
|
+
let projectName = projectSlug;
|
|
550
|
+
if (projectSlug && resolvedOrgId) {
|
|
551
|
+
let project = findProjectBySlug(resolvedOrgId, projectSlug);
|
|
552
|
+
if (!project) {
|
|
553
|
+
await refreshAuthMeCache();
|
|
554
|
+
project = findProjectBySlug(resolvedOrgId, projectSlug);
|
|
555
|
+
}
|
|
556
|
+
if (!project) {
|
|
557
|
+
console.error(chalk.red(`Unknown project "${projectSlug}" in org ${orgName}.`));
|
|
558
|
+
console.log(chalk.gray('Run: fazemos projects list'));
|
|
559
|
+
process.exit(1);
|
|
560
|
+
}
|
|
561
|
+
projectName = project.name;
|
|
562
|
+
}
|
|
563
|
+
const path = writeDirContextFile(process.cwd(), { org: orgSlug, project: projectSlug });
|
|
564
|
+
const rel = relative(process.cwd(), path) || path;
|
|
565
|
+
console.log(chalk.green(`✓ Wrote ${rel}`));
|
|
566
|
+
if (orgSlug)
|
|
567
|
+
console.log(` Org: ${chalk.cyan(orgName)} (${orgSlug})`);
|
|
568
|
+
if (projectSlug)
|
|
569
|
+
console.log(` Project: ${chalk.cyan(projectName)} (${projectSlug})`);
|
|
404
570
|
}
|
|
405
571
|
catch (err) {
|
|
406
572
|
console.error(chalk.red(err.message));
|
|
@@ -9269,7 +9435,13 @@ registerGovernanceCommands(program);
|
|
|
9269
9435
|
// Earlier `import.meta.url === file://${process.argv[1]}` check was wrong: the
|
|
9270
9436
|
// bin shim's argv[1] is the shim path, not the dist/index.js path, so the guard
|
|
9271
9437
|
// returned false and silently skipped parse.
|
|
9272
|
-
|
|
9273
|
-
|
|
9438
|
+
// parseAsync (not parse) so the async preAction hook that resolves the
|
|
9439
|
+
// directory-scoped org/project context can be awaited before any action runs.
|
|
9440
|
+
if (!process.env.VITEST) {
|
|
9441
|
+
program.parseAsync().catch((err) => {
|
|
9442
|
+
console.error(chalk.red(err?.message ?? String(err)));
|
|
9443
|
+
process.exit(1);
|
|
9444
|
+
});
|
|
9445
|
+
}
|
|
9274
9446
|
export { program };
|
|
9275
9447
|
//# sourceMappingURL=index.js.map
|