@opencloudcms/cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/bin/opencloudcms.js +2 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.js +51 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +351 -0
- package/dist/index.js.map +1 -0
- package/dist/init/index.d.ts +29 -0
- package/dist/init/index.js +211 -0
- package/dist/init/index.js.map +1 -0
- package/dist/init/names.d.ts +2 -0
- package/dist/init/names.js +61 -0
- package/dist/init/names.js.map +1 -0
- package/dist/init/templates.d.ts +46 -0
- package/dist/init/templates.js +519 -0
- package/dist/init/templates.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +43 -0
- package/dist/version.js.map +1 -0
- package/package.json +39 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ánh Nguyễn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @opencloudcms/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCloudCMS command line: generate code, create and run migrations, scaffold content types.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @opencloudcms/cli init my-cms
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Part of [OpenCloudCMS](https://github.com/anhdev97/Open-CMS): see the [main README](https://github.com/anhdev97/Open-CMS#readme) for setup and documentation.
|
package/dist/env.d.ts
ADDED
package/dist/env.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadProjectEnv = loadProjectEnv;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const node_util_1 = require("node:util");
|
|
40
|
+
/** Load `<root>/.env` into `env`; variables that are already defined win. */
|
|
41
|
+
function loadProjectEnv(root, env = process.env) {
|
|
42
|
+
const file = path.join(root, '.env');
|
|
43
|
+
if (!fs.existsSync(file))
|
|
44
|
+
return;
|
|
45
|
+
const parsed = (0, node_util_1.parseEnv)(fs.readFileSync(file, 'utf8'));
|
|
46
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
47
|
+
if (env[key] === undefined)
|
|
48
|
+
env[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wCAOC;AAZD,4CAA8B;AAC9B,gDAAkC;AAClC,yCAAqC;AAErC,6EAA6E;AAC7E,SAAgB,cAAc,CAAC,IAAY,EAAE,MAAyB,OAAO,CAAC,GAAG;IAC/E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO;IACjC,MAAM,MAAM,GAAG,IAAA,oBAAQ,EAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@opencloudcms/oauth2/migrations';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import type { FieldDefinition } from '@opencloudcms/schema';
|
|
4
|
+
/**
|
|
5
|
+
* Field spec syntax for `content-type:add` / `field:add`:
|
|
6
|
+
* name:kind[:flag...] flags: required, localizable, indexed, unique, multiple
|
|
7
|
+
* kind options: text(120) number(decimal) reference(brand) taxonomy(product-category)
|
|
8
|
+
* money(VND) asset[] reference(product)[]
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseFieldSpec(spec: string): FieldDefinition;
|
|
11
|
+
declare const program: Command;
|
|
12
|
+
export { program };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.program = void 0;
|
|
37
|
+
exports.parseFieldSpec = parseFieldSpec;
|
|
38
|
+
// Registers the oauth2 core migrations so migrate:up/status see them (R8). Nest-free entry.
|
|
39
|
+
require("@opencloudcms/oauth2/migrations");
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const commander_1 = require("commander");
|
|
43
|
+
const codegen_1 = require("@opencloudcms/codegen");
|
|
44
|
+
const env_1 = require("./env");
|
|
45
|
+
const init_1 = require("./init");
|
|
46
|
+
const db_1 = require("@opencloudcms/db");
|
|
47
|
+
const schema_1 = require("@opencloudcms/schema");
|
|
48
|
+
const version_1 = require("./version");
|
|
49
|
+
const c = {
|
|
50
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
51
|
+
yellow: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
52
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
53
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
54
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
55
|
+
};
|
|
56
|
+
async function project() {
|
|
57
|
+
const root = (0, codegen_1.findProjectRoot)(process.env.OPENCLOUDCMS_ROOT ?? process.cwd());
|
|
58
|
+
(0, env_1.loadProjectEnv)(root);
|
|
59
|
+
return (0, codegen_1.loadConfig)(root);
|
|
60
|
+
}
|
|
61
|
+
const rel = (config, p) => path.relative(config.root, p) || '.';
|
|
62
|
+
async function withDb(config, fn) {
|
|
63
|
+
if (!config.database?.url)
|
|
64
|
+
throw new Error('database.url is not set in opencloudcms.config.ts (usually from DATABASE_URL).');
|
|
65
|
+
const db = (0, db_1.createDb)(config.database.url);
|
|
66
|
+
try {
|
|
67
|
+
return await fn(db);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await db.destroy();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function run(fn) {
|
|
74
|
+
return async (...args) => {
|
|
75
|
+
try {
|
|
76
|
+
await fn(...args);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
if (e instanceof schema_1.SchemaValidationError || e instanceof codegen_1.DiffError) {
|
|
80
|
+
console.error(c.red(e.name === 'DiffError' ? 'Unsupported schema change:' : 'Invalid schema:'));
|
|
81
|
+
for (const i of e.issues)
|
|
82
|
+
console.error(` - ${i}`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.error(c.red(e.message ?? String(e)));
|
|
86
|
+
if (process.env.OPENCLOUDCMS_DEBUG)
|
|
87
|
+
console.error(e);
|
|
88
|
+
}
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function printPlan(summary, warnings, sql) {
|
|
94
|
+
for (const s of summary)
|
|
95
|
+
console.log(` ${c.green('+')} ${s}`);
|
|
96
|
+
for (const w of warnings)
|
|
97
|
+
console.log(` ${c.yellow('!')} ${w}`);
|
|
98
|
+
if (sql?.length) {
|
|
99
|
+
console.log(c.dim('\n SQL:'));
|
|
100
|
+
for (const s of sql)
|
|
101
|
+
console.log(c.dim(` ${s};`));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Field spec syntax for `content-type:add` / `field:add`:
|
|
106
|
+
* name:kind[:flag...] flags: required, localizable, indexed, unique, multiple
|
|
107
|
+
* kind options: text(120) number(decimal) reference(brand) taxonomy(product-category)
|
|
108
|
+
* money(VND) asset[] reference(product)[]
|
|
109
|
+
*/
|
|
110
|
+
function parseFieldSpec(spec) {
|
|
111
|
+
const [name, kindRaw, ...flags] = spec.split(':');
|
|
112
|
+
if (!name || !kindRaw)
|
|
113
|
+
throw new Error(`Invalid field "${spec}". Use name:kind[:required:localizable:indexed:unique]`);
|
|
114
|
+
const m = /^([a-zA-Z]+)(?:\(([^)]*)\))?(\[\])?$/.exec(kindRaw);
|
|
115
|
+
if (!m)
|
|
116
|
+
throw new Error(`Invalid field kind "${kindRaw}"`);
|
|
117
|
+
const kind = m[1];
|
|
118
|
+
if (!schema_1.FIELD_KINDS.includes(kind))
|
|
119
|
+
throw new Error(`Unknown kind "${kind}". Available: ${schema_1.FIELD_KINDS.join(', ')}`);
|
|
120
|
+
const arg = m[2];
|
|
121
|
+
const options = {};
|
|
122
|
+
if (m[3] || flags.includes('multiple'))
|
|
123
|
+
options.multiple = true;
|
|
124
|
+
if (arg) {
|
|
125
|
+
if (kind === 'text' || kind === 'slug')
|
|
126
|
+
options.maxLength = Number(arg);
|
|
127
|
+
else if (kind === 'number')
|
|
128
|
+
options.format = arg === 'decimal' ? 'decimal' : 'integer';
|
|
129
|
+
else if (kind === 'reference')
|
|
130
|
+
options.target = arg;
|
|
131
|
+
else if (kind === 'taxonomy')
|
|
132
|
+
options.taxonomy = arg;
|
|
133
|
+
else if (kind === 'money')
|
|
134
|
+
Object.assign(options, { currencyMode: 'fixed', currency: arg.toUpperCase() });
|
|
135
|
+
}
|
|
136
|
+
if (kind === 'money' && !options.currencyMode)
|
|
137
|
+
options.currencyMode = 'market';
|
|
138
|
+
return {
|
|
139
|
+
id: (0, schema_1.newId)('fld'),
|
|
140
|
+
name,
|
|
141
|
+
kind,
|
|
142
|
+
required: flags.includes('required'),
|
|
143
|
+
localizable: flags.includes('localizable'),
|
|
144
|
+
unique: flags.includes('unique'),
|
|
145
|
+
indexed: flags.includes('indexed') || flags.includes('unique'),
|
|
146
|
+
options: options,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const program = new commander_1.Command();
|
|
150
|
+
exports.program = program;
|
|
151
|
+
program.name('opencloudcms').description('@opencloudcms/cli: schema-as-code headless CMS tooling').version((0, version_1.cliVersion)());
|
|
152
|
+
program
|
|
153
|
+
.command('init <dir>')
|
|
154
|
+
.description('Scaffold a new OpenCloudCMS project in <dir>')
|
|
155
|
+
.option('--pm <pm>', 'package manager: pnpm | npm | yarn')
|
|
156
|
+
.option('--no-install', 'do not install dependencies')
|
|
157
|
+
.option('--db-url <url>', 'database URL written to .env')
|
|
158
|
+
.option('--port <n>', 'server port', '4000')
|
|
159
|
+
.option('--link <path>', 'link internal packages from an OpenCloudCMS monorepo checkout')
|
|
160
|
+
.action(run(async (dir, opts) => {
|
|
161
|
+
if (opts.pm && !['pnpm', 'npm', 'yarn'].includes(opts.pm))
|
|
162
|
+
throw new Error(`Unknown package manager "${opts.pm}". Use pnpm, npm or yarn.`);
|
|
163
|
+
const port = Number(opts.port);
|
|
164
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
165
|
+
throw new Error(`Invalid port "${opts.port}"`);
|
|
166
|
+
const r = await (0, init_1.runInit)(dir, {
|
|
167
|
+
pm: opts.pm,
|
|
168
|
+
install: opts.install,
|
|
169
|
+
dbUrl: opts.dbUrl,
|
|
170
|
+
port,
|
|
171
|
+
link: opts.link,
|
|
172
|
+
cliVersion: program.version(),
|
|
173
|
+
userAgent: process.env.npm_config_user_agent,
|
|
174
|
+
});
|
|
175
|
+
console.log(`${c.green('✓')} Created ${c.bold(dir)} (${r.files.length} files)${r.installed ? ', dependencies installed' : ''}\n`);
|
|
176
|
+
console.log((0, init_1.nextSteps)(dir, r));
|
|
177
|
+
}));
|
|
178
|
+
program
|
|
179
|
+
.command('generate')
|
|
180
|
+
.description('Generate src/generated/* (types, table types, validators, registry) from schema files')
|
|
181
|
+
.action(run(async () => {
|
|
182
|
+
const config = await project();
|
|
183
|
+
const { definitions, changed } = await (0, codegen_1.generate)(config);
|
|
184
|
+
console.log(`${c.green('✓')} ${definitions.length} content type(s), ${changed.length} file(s) updated`);
|
|
185
|
+
for (const f of changed)
|
|
186
|
+
console.log(c.dim(` ${rel(config, f)}`));
|
|
187
|
+
}));
|
|
188
|
+
program
|
|
189
|
+
.command('plan')
|
|
190
|
+
.description('Show the migration that migrate:create would generate, without writing anything')
|
|
191
|
+
.action(run(async () => {
|
|
192
|
+
const config = await project();
|
|
193
|
+
const r = await (0, codegen_1.computePlan)(config);
|
|
194
|
+
if (!r.diff.changed)
|
|
195
|
+
return console.log(`${c.green('✓')} Schema is in sync with migrations/_snapshot.json`);
|
|
196
|
+
if (!r.plan.up.length)
|
|
197
|
+
return console.log('Only metadata changed (labels, required, ...). No DDL needed.');
|
|
198
|
+
printPlan(r.plan.summary, r.plan.warnings, r.sql);
|
|
199
|
+
}));
|
|
200
|
+
program
|
|
201
|
+
.command('migrate:create [name]')
|
|
202
|
+
.description('Diff schema files against the snapshot and write a migration + generated code')
|
|
203
|
+
.action(run(async (name) => {
|
|
204
|
+
const config = await project();
|
|
205
|
+
const r = await (0, codegen_1.createMigration)(config, { name });
|
|
206
|
+
if (r.status === 'up-to-date')
|
|
207
|
+
return console.log(`${c.green('✓')} No schema changes`);
|
|
208
|
+
if (r.status === 'metadata-only') {
|
|
209
|
+
return console.log(`${c.green('✓')} Metadata-only change: snapshot and generated code updated, no migration needed`);
|
|
210
|
+
}
|
|
211
|
+
console.log(`${c.green('✓')} Created ${c.bold(rel(config, r.file))}`);
|
|
212
|
+
printPlan(r.plan.plan.summary, r.plan.plan.warnings);
|
|
213
|
+
console.log(c.dim('\n Review the file, then run `opencloudcms migrate:up`.'));
|
|
214
|
+
}));
|
|
215
|
+
program
|
|
216
|
+
.command('migrate:up')
|
|
217
|
+
.description('Apply pending core and project migrations')
|
|
218
|
+
.action(run(async () => {
|
|
219
|
+
const config = await project();
|
|
220
|
+
const runs = await withDb(config, (db) => (0, db_1.migrateUp)(db, config.migrationsDir));
|
|
221
|
+
if (!runs.length)
|
|
222
|
+
return console.log(`${c.green('✓')} Database is up to date`);
|
|
223
|
+
for (const r of runs)
|
|
224
|
+
console.log(` ${c.green('↑')} ${r.stream}/${r.name}`);
|
|
225
|
+
}));
|
|
226
|
+
program
|
|
227
|
+
.command('migrate:down')
|
|
228
|
+
.description('Revert the last project migration(s)')
|
|
229
|
+
.option('-s, --steps <n>', 'how many migrations to revert', '1')
|
|
230
|
+
.action(run(async (opts) => {
|
|
231
|
+
const config = await project();
|
|
232
|
+
const runs = await withDb(config, (db) => (0, db_1.migrateDown)(db, config.migrationsDir, Number(opts.steps)));
|
|
233
|
+
if (!runs.length)
|
|
234
|
+
return console.log('Nothing to revert');
|
|
235
|
+
for (const r of runs)
|
|
236
|
+
console.log(` ${c.yellow('↓')} ${r.stream}/${r.name}`);
|
|
237
|
+
console.log(c.yellow('\n The database is now behind migrations/_snapshot.json. Either re-run migrate:up, or delete the\n' +
|
|
238
|
+
' reverted migration file and revert the schema/snapshot change in git.'));
|
|
239
|
+
}));
|
|
240
|
+
program
|
|
241
|
+
.command('migrate:status')
|
|
242
|
+
.description('List migrations and whether they have been applied')
|
|
243
|
+
.action(run(async () => {
|
|
244
|
+
const config = await project();
|
|
245
|
+
const rows = await withDb(config, (db) => (0, db_1.migrationStatus)(db, config.migrationsDir));
|
|
246
|
+
for (const r of rows) {
|
|
247
|
+
const mark = r.executedAt ? c.green('✓') : c.yellow('…');
|
|
248
|
+
const when = r.executedAt ? c.dim(r.executedAt.toISOString()) : c.yellow('pending');
|
|
249
|
+
console.log(` ${mark} ${r.stream.padEnd(7)} ${r.name.padEnd(60)} ${when}`);
|
|
250
|
+
}
|
|
251
|
+
}));
|
|
252
|
+
program
|
|
253
|
+
.command('migrate:check')
|
|
254
|
+
.description('CI check: fail if schema files changed without a migration or generated code is stale')
|
|
255
|
+
.action(run(async () => {
|
|
256
|
+
const config = await project();
|
|
257
|
+
const r = await (0, codegen_1.checkSchema)(config);
|
|
258
|
+
if (r.ok)
|
|
259
|
+
return console.log(`${c.green('✓')} Schema, migrations and generated code are in sync`);
|
|
260
|
+
for (const p of r.problems)
|
|
261
|
+
console.error(` ${c.red('✗')} ${p}`);
|
|
262
|
+
process.exitCode = 1;
|
|
263
|
+
}));
|
|
264
|
+
program
|
|
265
|
+
.command('content-type:add <apiId>')
|
|
266
|
+
.description('Create a content type schema file, e.g. content-type:add article -f title:text:required:localizable')
|
|
267
|
+
.option('-n, --display-name <name>', 'display name')
|
|
268
|
+
.option('-f, --field <spec...>', 'field spec name:kind[:flags] (repeatable)', [])
|
|
269
|
+
.option('--no-migration', 'only write the schema file')
|
|
270
|
+
.action(run(async (apiId, opts) => {
|
|
271
|
+
const config = await project();
|
|
272
|
+
const existing = await (0, codegen_1.loadDefinitions)(config);
|
|
273
|
+
if (existing.some((l) => l.def.apiId === apiId))
|
|
274
|
+
throw new Error(`Content type "${apiId}" already exists`);
|
|
275
|
+
const def = {
|
|
276
|
+
id: (0, schema_1.newId)('ct'),
|
|
277
|
+
apiId,
|
|
278
|
+
displayName: opts.displayName ?? apiId.charAt(0).toUpperCase() + apiId.slice(1),
|
|
279
|
+
fields: opts.field.map(parseFieldSpec),
|
|
280
|
+
};
|
|
281
|
+
const { file } = await (0, codegen_1.writeSchemaChange)(config, { upsert: def });
|
|
282
|
+
console.log(`${c.green('✓')} Wrote ${c.bold(rel(config, file))}`);
|
|
283
|
+
if (opts.migration) {
|
|
284
|
+
const r = await (0, codegen_1.createMigration)(config);
|
|
285
|
+
if (r.status === 'created')
|
|
286
|
+
console.log(`${c.green('✓')} Created ${c.bold(rel(config, r.file))}`);
|
|
287
|
+
}
|
|
288
|
+
}));
|
|
289
|
+
program
|
|
290
|
+
.command('field:add <apiId> <spec...>')
|
|
291
|
+
.description('Add field(s) to an existing content type, e.g. field:add product color:text:indexed')
|
|
292
|
+
.option('--no-migration', 'only update the schema file')
|
|
293
|
+
.action(run(async (apiId, specs, opts) => {
|
|
294
|
+
const config = await project();
|
|
295
|
+
const loaded = (await (0, codegen_1.loadDefinitions)(config)).find((l) => l.def.apiId === apiId);
|
|
296
|
+
if (!loaded)
|
|
297
|
+
throw new Error(`Content type "${apiId}" not found`);
|
|
298
|
+
const def = { ...loaded.def, fields: [...loaded.def.fields, ...specs.map(parseFieldSpec)] };
|
|
299
|
+
const { file } = await (0, codegen_1.writeSchemaChange)(config, { upsert: def });
|
|
300
|
+
console.log(`${c.green('✓')} Updated ${c.bold(rel(config, file))}`);
|
|
301
|
+
if (opts.migration) {
|
|
302
|
+
const r = await (0, codegen_1.createMigration)(config);
|
|
303
|
+
if (r.status === 'created')
|
|
304
|
+
console.log(`${c.green('✓')} Created ${c.bold(rel(config, r.file))}`);
|
|
305
|
+
}
|
|
306
|
+
}));
|
|
307
|
+
program
|
|
308
|
+
.command('dev')
|
|
309
|
+
.description('Watch schema files: regenerate code, create and apply migrations on every change')
|
|
310
|
+
.action(run(async () => {
|
|
311
|
+
const config = await project();
|
|
312
|
+
let timer;
|
|
313
|
+
let busy = false;
|
|
314
|
+
const cycle = async () => {
|
|
315
|
+
if (busy)
|
|
316
|
+
return;
|
|
317
|
+
busy = true;
|
|
318
|
+
try {
|
|
319
|
+
const r = await (0, codegen_1.createMigration)(config);
|
|
320
|
+
if (r.status === 'created') {
|
|
321
|
+
console.log(`${c.green('✓')} ${rel(config, r.file)}`);
|
|
322
|
+
printPlan(r.plan.plan.summary, r.plan.plan.warnings);
|
|
323
|
+
}
|
|
324
|
+
else if (r.status === 'metadata-only')
|
|
325
|
+
console.log(`${c.green('✓')} metadata updated`);
|
|
326
|
+
const runs = await withDb(config, (db) => (0, db_1.migrateUp)(db, config.migrationsDir));
|
|
327
|
+
for (const x of runs)
|
|
328
|
+
console.log(` ${c.green('↑')} ${x.stream}/${x.name}`);
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
if (e instanceof schema_1.SchemaValidationError || e instanceof codegen_1.DiffError)
|
|
332
|
+
e.issues.forEach((i) => console.error(c.red(` - ${i}`)));
|
|
333
|
+
else
|
|
334
|
+
console.error(c.red(e.message));
|
|
335
|
+
}
|
|
336
|
+
finally {
|
|
337
|
+
busy = false;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
await cycle();
|
|
341
|
+
console.log(c.dim(`Watching ${rel(config, config.contentTypesDir)} ...`));
|
|
342
|
+
fs.mkdirSync(config.contentTypesDir, { recursive: true });
|
|
343
|
+
fs.watch(config.contentTypesDir, { recursive: true }, () => {
|
|
344
|
+
clearTimeout(timer);
|
|
345
|
+
timer = setTimeout(cycle, 300);
|
|
346
|
+
});
|
|
347
|
+
await new Promise(() => undefined);
|
|
348
|
+
}));
|
|
349
|
+
if (require.main === module)
|
|
350
|
+
program.parseAsync(process.argv);
|
|
351
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":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AC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;;gBACvH,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAE,CAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,CAAC;gBAAS,CAAC;YACT,IAAI,GAAG,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IACF,MAAM,KAAK,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACzD,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IACH,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC,CAAC,CACH,CAAC;AAEJ,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as t from './templates';
|
|
2
|
+
export type { PackageManager } from './templates';
|
|
3
|
+
export interface InitOptions {
|
|
4
|
+
pm?: t.PackageManager;
|
|
5
|
+
install?: boolean;
|
|
6
|
+
dbUrl?: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
/** Path of an OpenCloudCMS monorepo checkout: internal packages are linked instead of installed. */
|
|
9
|
+
link?: string;
|
|
10
|
+
cliVersion: string;
|
|
11
|
+
userAgent?: string;
|
|
12
|
+
spawn?: (cmd: string, args: string[], cwd: string) => Promise<number>;
|
|
13
|
+
}
|
|
14
|
+
export interface InitResult {
|
|
15
|
+
files: string[];
|
|
16
|
+
installed: boolean;
|
|
17
|
+
pm: t.PackageManager;
|
|
18
|
+
port: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function detectPm(userAgent?: string): t.PackageManager | undefined;
|
|
21
|
+
/** Real path of the package root (undefined when `repo` has no packages/core) that `@opencloudcms/core` (at `<repo>/packages/core`) resolves `name` to. */
|
|
22
|
+
export declare function resolveFromCore(repo: string, name: string): string | undefined;
|
|
23
|
+
/** Nearest directory that contains both absolute paths (compared by path segments). */
|
|
24
|
+
export declare function commonAncestor(a: string, b: string): string;
|
|
25
|
+
export declare function runInit(dir: string, opts: InitOptions): Promise<InitResult>;
|
|
26
|
+
export declare function nextSteps(dir: string, r: {
|
|
27
|
+
pm: t.PackageManager;
|
|
28
|
+
port: number;
|
|
29
|
+
}): string;
|