@apso/cli 0.49.1 → 0.50.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/dist/commands/deploy.d.ts +15 -0
- package/dist/commands/deploy.js +21 -4
- package/dist/commands/mcp/serve.js +26 -42
- package/dist/commands/schema/validate.d.ts +21 -0
- package/dist/commands/schema/validate.js +57 -51
- package/dist/lib/deploy/server-push.js +2 -12
- package/dist/lib/git.d.ts +14 -1
- package/dist/lib/git.js +38 -2
- package/npm-shrinkwrap.json +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -28,3 +28,18 @@ export default class Deploy extends BaseCommand {
|
|
|
28
28
|
*/
|
|
29
29
|
private resolveRepo;
|
|
30
30
|
}
|
|
31
|
+
type SignInCommand = Pick<BaseCommand, "log" | "error"> & {
|
|
32
|
+
config: {
|
|
33
|
+
runCommand: (id: string, argv?: string[]) => Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Deploy signs you in instead of stopping. The browser flow needs no TTY, so
|
|
38
|
+
* an agent can run deploy and the person finishes sign-in in the browser. CI
|
|
39
|
+
* has nobody to do that, so it still fails with the token instructions.
|
|
40
|
+
*
|
|
41
|
+
* @param {SignInCommand} cmd - The running command.
|
|
42
|
+
* @returns {Promise<void>} Resolves once valid credentials are stored.
|
|
43
|
+
*/
|
|
44
|
+
export declare function signInIfNeeded(cmd: SignInCommand): Promise<void>;
|
|
45
|
+
export {};
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signInIfNeeded = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const core_1 = require("@oclif/core");
|
|
5
6
|
const base_command_1 = tslib_1.__importDefault(require("../lib/base-command"));
|
|
@@ -17,10 +18,7 @@ class Deploy extends base_command_1.default {
|
|
|
17
18
|
async run() {
|
|
18
19
|
const { flags } = await this.parse(Deploy);
|
|
19
20
|
const env = (0, environments_1.asEnv)(flags.env);
|
|
20
|
-
|
|
21
|
-
if (!config_1.credentials.isValid()) {
|
|
22
|
-
this.error("Not logged in. Run 'apso login' first.");
|
|
23
|
-
}
|
|
21
|
+
await signInIfNeeded(this);
|
|
24
22
|
// Link guard
|
|
25
23
|
const link = config_1.projectLink.read();
|
|
26
24
|
if (!link) {
|
|
@@ -310,3 +308,22 @@ Deploy.flags = {
|
|
|
310
308
|
}),
|
|
311
309
|
};
|
|
312
310
|
exports.default = Deploy;
|
|
311
|
+
/**
|
|
312
|
+
* Deploy signs you in instead of stopping. The browser flow needs no TTY, so
|
|
313
|
+
* an agent can run deploy and the person finishes sign-in in the browser. CI
|
|
314
|
+
* has nobody to do that, so it still fails with the token instructions.
|
|
315
|
+
*
|
|
316
|
+
* @param {SignInCommand} cmd - The running command.
|
|
317
|
+
* @returns {Promise<void>} Resolves once valid credentials are stored.
|
|
318
|
+
*/
|
|
319
|
+
async function signInIfNeeded(cmd) {
|
|
320
|
+
if (config_1.credentials.isValid())
|
|
321
|
+
return;
|
|
322
|
+
if (process.env.CI === "true" || process.env.CI === "1")
|
|
323
|
+
cmd.error('Not logged in. In CI, run `apso login --token "$APSO_API_TOKEN"` before `apso deploy`.');
|
|
324
|
+
cmd.log("You're not signed in to Apso, so signing in first.");
|
|
325
|
+
await cmd.config.runCommand("login");
|
|
326
|
+
if (!config_1.credentials.isValid())
|
|
327
|
+
cmd.error("Sign-in didn't finish. Run 'apso login', then re-run deploy.");
|
|
328
|
+
}
|
|
329
|
+
exports.signInIfNeeded = signInIfNeeded;
|
|
@@ -16,8 +16,9 @@ const lib_1 = require("../../lib");
|
|
|
16
16
|
const runner_1 = require("../../lib/doctor/runner");
|
|
17
17
|
const crud_deps_1 = require("../../lib/utils/crud-deps");
|
|
18
18
|
const file_system_1 = require("../../lib/utils/file-system");
|
|
19
|
-
const schema_convert_1 = require("../../lib/utils/schema-convert");
|
|
20
19
|
const mcp_schema_tools_1 = require("../../lib/mcp-schema-tools");
|
|
20
|
+
const schema_tools_1 = require("@apso/schema-tools");
|
|
21
|
+
const validate_1 = require("../schema/validate");
|
|
21
22
|
const perf_hooks_1 = require("perf_hooks");
|
|
22
23
|
class McpServe extends base_command_1.default {
|
|
23
24
|
async run() {
|
|
@@ -176,18 +177,26 @@ class McpServe extends base_command_1.default {
|
|
|
176
177
|
.optional()
|
|
177
178
|
.describe("Optional: JSON string of a schema to validate. If not provided, reads .apsorc from the current directory."),
|
|
178
179
|
}, async ({ schema_json }) => {
|
|
179
|
-
var _a, _b
|
|
180
|
+
var _a, _b;
|
|
180
181
|
try {
|
|
181
182
|
if (schema_json) {
|
|
182
183
|
// Validate the provided JSON
|
|
183
184
|
const schema = JSON.parse(schema_json);
|
|
184
185
|
const errors = validateSchemaObject(schema);
|
|
186
|
+
let lintReport = "";
|
|
187
|
+
if (errors.length === 0) {
|
|
188
|
+
const lint = (0, schema_tools_1.lintSchema)(schema);
|
|
189
|
+
if (lint.issues.length > 0)
|
|
190
|
+
lintReport = `${(0, schema_tools_1.formatLintReport)(lint)}\n\n`;
|
|
191
|
+
if (lint.errorCount > 0)
|
|
192
|
+
errors.push(`${lint.errorCount} lint error(s), listed above.`);
|
|
193
|
+
}
|
|
185
194
|
if (errors.length > 0) {
|
|
186
195
|
return {
|
|
187
196
|
content: [
|
|
188
197
|
{
|
|
189
198
|
type: "text",
|
|
190
|
-
text:
|
|
199
|
+
text: `${lintReport}Validation failed with ${errors.length} error(s):\n${errors.map((e) => ` - ${e}`).join("\n")}`,
|
|
191
200
|
},
|
|
192
201
|
],
|
|
193
202
|
isError: true,
|
|
@@ -218,46 +227,21 @@ class McpServe extends base_command_1.default {
|
|
|
218
227
|
isError: true,
|
|
219
228
|
};
|
|
220
229
|
}
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
if (entity.relationships) {
|
|
234
|
-
for (const rel of entity.relationships) {
|
|
235
|
-
const targetExists = schema.entities.some((e) => e.name === rel.target);
|
|
236
|
-
if (!targetExists) {
|
|
237
|
-
errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
230
|
+
// The same checks as `apso schema validate --local`
|
|
231
|
+
const check = await (0, validate_1.localSchemaCheck)();
|
|
232
|
+
const lines = [];
|
|
233
|
+
if (check.lintReport)
|
|
234
|
+
lines.push(check.lintReport, "");
|
|
235
|
+
if (check.stats)
|
|
236
|
+
lines.push(`Schema: ${check.stats.entities} entities, ${check.stats.fields} fields, ${check.stats.relationships} relationships`);
|
|
237
|
+
for (const warning of check.warnings)
|
|
238
|
+
lines.push(`Warning: ${warning}`);
|
|
239
|
+
if (check.errors.length > 0) {
|
|
240
|
+
lines.push("", `Validation failed with ${check.errors.length} error(s):`, ...check.errors.map((e) => ` - ${e}`));
|
|
241
|
+
return { content: [{ type: "text", text: lines.join("\n") }], isError: true };
|
|
241
242
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
content: [
|
|
245
|
-
{
|
|
246
|
-
type: "text",
|
|
247
|
-
text: `Schema: ${entityCount} entities, ${fieldCount} fields, ${relationshipCount} relationships\n\nValidation failed with ${errors.length} error(s):\n${errors.map((e) => ` - ${e}`).join("\n")}`,
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
isError: true,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
content: [
|
|
255
|
-
{
|
|
256
|
-
type: "text",
|
|
257
|
-
text: `Schema: ${entityCount} entities, ${fieldCount} fields, ${relationshipCount} relationships\nValidation passed.`,
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
};
|
|
243
|
+
lines.push("Validation passed.");
|
|
244
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
261
245
|
}
|
|
262
246
|
catch (error) {
|
|
263
247
|
const msg = error instanceof Error ? error.message : String(error);
|
|
@@ -9,6 +9,27 @@ import { ParsedApsorc } from "../../lib/apsorc-parser";
|
|
|
9
9
|
* @returns {Promise<string[]>} One message per problem; empty when there are none.
|
|
10
10
|
*/
|
|
11
11
|
export declare function accessRuleErrors(parsed: Pick<ParsedApsorc, "rootFolder" | "apiType" | "entities" | "relationshipMap" | "auth" | "language">): Promise<string[]>;
|
|
12
|
+
export interface LocalSchemaCheck {
|
|
13
|
+
/** The lint report, empty when the linter found nothing. */
|
|
14
|
+
lintReport: string;
|
|
15
|
+
errors: string[];
|
|
16
|
+
warnings: string[];
|
|
17
|
+
/** Set once the file parsed; absent when lint errors stopped the check first. */
|
|
18
|
+
parsed?: ParsedApsorc;
|
|
19
|
+
stats?: {
|
|
20
|
+
entities: number;
|
|
21
|
+
fields: number;
|
|
22
|
+
relationships: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every check `apso schema validate --local` runs on the project's .apsorc.
|
|
27
|
+
* The CLI command and the MCP validate_schema tool both call this, so an
|
|
28
|
+
* agent gets the same answer from either.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<LocalSchemaCheck>} The lint report, errors and warnings.
|
|
31
|
+
*/
|
|
32
|
+
export declare function localSchemaCheck(): Promise<LocalSchemaCheck>;
|
|
12
33
|
export default class SchemaValidate extends BaseCommand {
|
|
13
34
|
static description: string;
|
|
14
35
|
static examples: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.accessRuleErrors = void 0;
|
|
3
|
+
exports.localSchemaCheck = exports.accessRuleErrors = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
const base_command_1 = tslib_1.__importDefault(require("../../lib/base-command"));
|
|
@@ -58,67 +58,73 @@ async function accessRuleErrors(parsed) {
|
|
|
58
58
|
return [...new Set(errors)];
|
|
59
59
|
}
|
|
60
60
|
exports.accessRuleErrors = accessRuleErrors;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Every check `apso schema validate --local` runs on the project's .apsorc.
|
|
63
|
+
* The CLI command and the MCP validate_schema tool both call this, so an
|
|
64
|
+
* agent gets the same answer from either.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Promise<LocalSchemaCheck>} The lint report, errors and warnings.
|
|
67
|
+
*/
|
|
68
|
+
async function localSchemaCheck() {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const result = { lintReport: "", errors: [], warnings: [] };
|
|
71
|
+
// Lint first so every issue is listed, not just the first one parseApsorc throws on
|
|
72
|
+
const file = (0, apsorc_parser_1.readApsorcFile)();
|
|
73
|
+
if (file.apsorc.version === 2) {
|
|
74
|
+
const lint = (0, schema_tools_1.lintSchema)(file.apsorc);
|
|
75
|
+
if (lint.issues.length > 0)
|
|
76
|
+
result.lintReport = (0, schema_tools_1.formatLintReport)(lint);
|
|
77
|
+
if (lint.errorCount > 0) {
|
|
78
|
+
result.errors.push(`${lint.errorCount} lint error(s). Run "apso schema lint --fix" to apply the safe fixes.`);
|
|
79
|
+
return result;
|
|
69
80
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
}
|
|
82
|
+
const parsed = (0, apsorc_parser_1.parseApsorc)();
|
|
83
|
+
result.parsed = parsed;
|
|
84
|
+
result.warnings.push(...(0, guards_1.tenantClaimWarnings)(parsed.entities, parsed.auth));
|
|
85
|
+
const schema = (0, schema_convert_1.apsorcToServiceSchema)(parsed);
|
|
86
|
+
let fields = 0;
|
|
87
|
+
let relationships = 0;
|
|
88
|
+
for (const entity of schema.entities) {
|
|
89
|
+
fields += entity.fields.length;
|
|
90
|
+
relationships += ((_a = entity.relationships) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
91
|
+
if (!entity.name || entity.name.trim() === "") {
|
|
92
|
+
result.errors.push("Entity found with empty name");
|
|
73
93
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.log((0, schema_tools_1.formatLintReport)(lint));
|
|
78
|
-
this.log("");
|
|
79
|
-
}
|
|
80
|
-
if (lint.errorCount > 0) {
|
|
81
|
-
this.error(`Validation failed with ${lint.errorCount} lint error(s). Run "apso schema lint --fix" to apply the safe fixes.`);
|
|
94
|
+
for (const rel of (_b = entity.relationships) !== null && _b !== void 0 ? _b : []) {
|
|
95
|
+
if (!schema.entities.some((e) => e.name === rel.target)) {
|
|
96
|
+
result.errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
}
|
|
100
|
+
result.stats = { entities: schema.entities.length, fields, relationships };
|
|
101
|
+
// The rules apso generate enforces for auth, permissions and mcp
|
|
102
|
+
result.errors.push(...(await accessRuleErrors(parsed)));
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
exports.localSchemaCheck = localSchemaCheck;
|
|
106
|
+
class SchemaValidate extends base_command_1.default {
|
|
107
|
+
async run() {
|
|
108
|
+
const { flags } = await this.parse(SchemaValidate);
|
|
109
|
+
let check;
|
|
86
110
|
try {
|
|
87
|
-
|
|
111
|
+
check = await localSchemaCheck();
|
|
88
112
|
}
|
|
89
113
|
catch (error) {
|
|
90
114
|
const msg = error instanceof Error ? error.message : String(error);
|
|
91
|
-
this.error(`Failed to parse .apsorc: ${msg}`);
|
|
115
|
+
this.error(`Failed to read or parse .apsorc: ${msg}`);
|
|
116
|
+
}
|
|
117
|
+
if (check.lintReport) {
|
|
118
|
+
this.log(check.lintReport);
|
|
119
|
+
this.log("");
|
|
92
120
|
}
|
|
93
|
-
|
|
121
|
+
if (!check.parsed)
|
|
122
|
+
this.error(`Validation failed with ${check.errors[0]}`);
|
|
123
|
+
for (const warning of check.warnings)
|
|
94
124
|
this.warn(warning);
|
|
95
|
-
|
|
125
|
+
const { errors, parsed } = check;
|
|
96
126
|
const schema = (0, schema_convert_1.apsorcToServiceSchema)(parsed);
|
|
97
|
-
|
|
98
|
-
const entityCount = schema.entities.length;
|
|
99
|
-
let fieldCount = 0;
|
|
100
|
-
let relationshipCount = 0;
|
|
101
|
-
for (const entity of schema.entities) {
|
|
102
|
-
fieldCount += entity.fields.length;
|
|
103
|
-
relationshipCount += ((_a = entity.relationships) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
104
|
-
}
|
|
105
|
-
// Local validation
|
|
106
|
-
const errors = [];
|
|
107
|
-
for (const entity of schema.entities) {
|
|
108
|
-
if (!entity.name || entity.name.trim() === "") {
|
|
109
|
-
errors.push("Entity found with empty name");
|
|
110
|
-
}
|
|
111
|
-
if (entity.relationships) {
|
|
112
|
-
for (const rel of entity.relationships) {
|
|
113
|
-
const targetExists = schema.entities.some((e) => e.name === rel.target);
|
|
114
|
-
if (!targetExists) {
|
|
115
|
-
errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// The rules apso generate enforces for auth, permissions and mcp
|
|
121
|
-
errors.push(...(await accessRuleErrors(parsed)));
|
|
127
|
+
const { entities: entityCount, fields: fieldCount, relationships: relationshipCount } = check.stats;
|
|
122
128
|
// Server validation if linked and not --local
|
|
123
129
|
const isLinked = config_1.projectLink.exists();
|
|
124
130
|
const isAuthenticated = config_1.credentials.isValid();
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const services_1 = require("../api/services");
|
|
8
|
+
const git_1 = require("../git");
|
|
8
9
|
// Never ship these into the code zip — the backend reconstitutes the runnable
|
|
9
10
|
// base template and only needs the source + schema + user edits.
|
|
10
11
|
const EXCLUDE_DIRS = new Set([
|
|
@@ -15,17 +16,6 @@ const EXCLUDE_DIRS = new Set([
|
|
|
15
16
|
".apso",
|
|
16
17
|
"coverage",
|
|
17
18
|
]);
|
|
18
|
-
/**
|
|
19
|
-
* Never push local secrets to the repo. `.env` and `.env.*` (e.g. `.env.local`)
|
|
20
|
-
* routinely hold DB passwords and session secrets; `.env.example` is the one
|
|
21
|
-
* env file that is meant to be committed. The backend injects real production
|
|
22
|
-
* env at runtime, so these are never needed in the pushed code.
|
|
23
|
-
*/
|
|
24
|
-
function isSecretEnvFile(basename) {
|
|
25
|
-
if (basename === ".env.example" || basename === ".env.sample")
|
|
26
|
-
return false;
|
|
27
|
-
return basename === ".env" || basename.startsWith(".env.");
|
|
28
|
-
}
|
|
29
19
|
/** Zip the project source into a buffer, skipping build/vcs/dependency/secret files. */
|
|
30
20
|
function zipProject(cwd) {
|
|
31
21
|
const zip = new adm_zip_1.default();
|
|
@@ -36,7 +26,7 @@ function zipProject(cwd) {
|
|
|
36
26
|
if (!kept && parts.some((p) => EXCLUDE_DIRS.has(p)))
|
|
37
27
|
return false;
|
|
38
28
|
const base = parts[parts.length - 1];
|
|
39
|
-
if (isSecretEnvFile(base))
|
|
29
|
+
if ((0, git_1.isSecretEnvFile)(base))
|
|
40
30
|
return false;
|
|
41
31
|
return true;
|
|
42
32
|
});
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -16,7 +16,20 @@ export declare function parseRepoFullName(url: string | null): string | null;
|
|
|
16
16
|
export declare function localRepoFullName(cwd: string): string | null;
|
|
17
17
|
export declare function setOrigin(cwd: string, repoUrl: string): void;
|
|
18
18
|
export declare function hasUncommittedChanges(cwd: string): boolean;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Never push local secrets to the repo. `.env` and `.env.*` (e.g. `.env.local`)
|
|
21
|
+
* routinely hold DB passwords and session secrets; `.env.example` and
|
|
22
|
+
* `.env.sample` are the env files meant to be committed. The backend injects
|
|
23
|
+
* real production env at runtime, so these are never needed in the pushed code.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isSecretEnvFile(basename: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Keep secret env files out of commits: add them to .gitignore (the TS template
|
|
28
|
+
* only ignores `.env`, so `.env.local` got committed) and untrack any that an
|
|
29
|
+
* earlier commit already picked up.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ignoreSecretEnvFiles(cwd: string): void;
|
|
32
|
+
/** Stage everything (minus secret env files) and commit, unless there is nothing to commit. */
|
|
20
33
|
export declare function commitAll(cwd: string, message: string): boolean;
|
|
21
34
|
/** Attribution trailer appended to every commit the CLI creates. */
|
|
22
35
|
export declare const APSO_COMMIT_TRAILER = "Generated with Apso (https://apso.ai)";
|
package/dist/lib/git.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* deploy time.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.httpsUrlFor = exports.pushHead = exports.APSO_COMMIT_TRAILER = exports.commitAll = exports.hasUncommittedChanges = exports.setOrigin = exports.localRepoFullName = exports.parseRepoFullName = exports.getOriginUrl = exports.initRepo = exports.isGitRepo = exports.gitAvailable = void 0;
|
|
11
|
+
exports.httpsUrlFor = exports.pushHead = exports.APSO_COMMIT_TRAILER = exports.commitAll = exports.ignoreSecretEnvFiles = exports.isSecretEnvFile = exports.hasUncommittedChanges = exports.setOrigin = exports.localRepoFullName = exports.parseRepoFullName = exports.getOriginUrl = exports.initRepo = exports.isGitRepo = exports.gitAvailable = void 0;
|
|
12
12
|
const tslib_1 = require("tslib");
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const fs = tslib_1.__importStar(require("fs"));
|
|
@@ -77,8 +77,44 @@ function hasUncommittedChanges(cwd) {
|
|
|
77
77
|
return run("git status --porcelain", cwd).length > 0;
|
|
78
78
|
}
|
|
79
79
|
exports.hasUncommittedChanges = hasUncommittedChanges;
|
|
80
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Never push local secrets to the repo. `.env` and `.env.*` (e.g. `.env.local`)
|
|
82
|
+
* routinely hold DB passwords and session secrets; `.env.example` and
|
|
83
|
+
* `.env.sample` are the env files meant to be committed. The backend injects
|
|
84
|
+
* real production env at runtime, so these are never needed in the pushed code.
|
|
85
|
+
*/
|
|
86
|
+
function isSecretEnvFile(basename) {
|
|
87
|
+
if (basename === ".env.example" || basename === ".env.sample")
|
|
88
|
+
return false;
|
|
89
|
+
return basename === ".env" || basename.startsWith(".env.");
|
|
90
|
+
}
|
|
91
|
+
exports.isSecretEnvFile = isSecretEnvFile;
|
|
92
|
+
const SECRET_ENV_IGNORES = [".env", ".env.*", "!.env.example", "!.env.sample"];
|
|
93
|
+
/**
|
|
94
|
+
* Keep secret env files out of commits: add them to .gitignore (the TS template
|
|
95
|
+
* only ignores `.env`, so `.env.local` got committed) and untrack any that an
|
|
96
|
+
* earlier commit already picked up.
|
|
97
|
+
*/
|
|
98
|
+
function ignoreSecretEnvFiles(cwd) {
|
|
99
|
+
const file = path.join(cwd, ".gitignore");
|
|
100
|
+
const current = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
|
|
101
|
+
const have = new Set(current.split(/\r?\n/).map((l) => l.trim()));
|
|
102
|
+
const missing = SECRET_ENV_IGNORES.filter((l) => !have.has(l));
|
|
103
|
+
if (missing.length > 0) {
|
|
104
|
+
const sep = current && !current.endsWith("\n") ? "\n" : "";
|
|
105
|
+
fs.writeFileSync(file, `${current}${sep}# Local secrets, never committed (added by apso)\n${missing.join("\n")}\n`);
|
|
106
|
+
}
|
|
107
|
+
const tracked = run("git ls-files", cwd)
|
|
108
|
+
.split("\n")
|
|
109
|
+
.filter((f) => f && isSecretEnvFile(path.basename(f)));
|
|
110
|
+
if (tracked.length > 0) {
|
|
111
|
+
run(`git rm --cached -q -- ${tracked.map((f) => JSON.stringify(f)).join(" ")}`, cwd);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ignoreSecretEnvFiles = ignoreSecretEnvFiles;
|
|
115
|
+
/** Stage everything (minus secret env files) and commit, unless there is nothing to commit. */
|
|
81
116
|
function commitAll(cwd, message) {
|
|
117
|
+
ignoreSecretEnvFiles(cwd);
|
|
82
118
|
run("git add -A", cwd);
|
|
83
119
|
if (!hasUncommittedChanges(cwd)) {
|
|
84
120
|
// Something may still be staged with no worktree diff; check the index.
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@apso/cli",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.50.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@apso/schema-tools": "^0.2.2",
|
package/oclif.manifest.json
CHANGED