@vendure/cli 2.2.0-next.8 → 2.2.1
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/cli.js +48 -13
- package/dist/cli.js.map +1 -1
- package/dist/commands/add/add.d.ts +1 -2
- package/dist/commands/add/add.js +48 -51
- package/dist/commands/add/add.js.map +1 -1
- package/dist/commands/add/api-extension/add-api-extension.js +220 -50
- package/dist/commands/add/api-extension/add-api-extension.js.map +1 -1
- package/dist/commands/add/api-extension/templates/simple-resolver.template.ts +15 -6
- package/dist/commands/add/plugin/create-new-plugin.js +1 -1
- package/dist/commands/add/plugin/create-new-plugin.js.map +1 -1
- package/dist/commands/add/plugin/templates/plugin.template.ts +7 -0
- package/dist/commands/add/service/add-service.js +1 -2
- package/dist/commands/add/service/add-service.js.map +1 -1
- package/dist/commands/add/service/templates/basic-service.template.ts +3 -3
- package/dist/commands/add/service/templates/entity-service.template.ts +0 -1
- package/dist/commands/migrate/generate-migration/generate-migration.js +1 -1
- package/dist/commands/migrate/generate-migration/generate-migration.js.map +1 -1
- package/dist/commands/migrate/load-vendure-config-file.d.ts +1 -1
- package/dist/commands/migrate/load-vendure-config-file.js +39 -4
- package/dist/commands/migrate/load-vendure-config-file.js.map +1 -1
- package/dist/commands/migrate/migrate.d.ts +1 -2
- package/dist/commands/migrate/migrate.js +34 -40
- package/dist/commands/migrate/migrate.js.map +1 -1
- package/dist/commands/migrate/revert-migration/revert-migration.js +1 -1
- package/dist/commands/migrate/revert-migration/revert-migration.js.map +1 -1
- package/dist/commands/migrate/run-migration/run-migration.js +1 -1
- package/dist/commands/migrate/run-migration/run-migration.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/shared/entity-ref.js +1 -8
- package/dist/shared/entity-ref.js.map +1 -1
- package/dist/shared/shared-prompts.d.ts +1 -1
- package/dist/shared/shared-prompts.js +12 -5
- package/dist/shared/shared-prompts.js.map +1 -1
- package/dist/utilities/ast-utils.d.ts +1 -0
- package/dist/utilities/ast-utils.js +33 -5
- package/dist/utilities/ast-utils.js.map +1 -1
- package/package.json +7 -5
package/dist/cli.js
CHANGED
|
@@ -1,29 +1,64 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
3
26
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
28
|
};
|
|
6
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
30
|
const commander_1 = require("commander");
|
|
8
31
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
-
const add_1 = require("./commands/add/add");
|
|
10
|
-
const migrate_1 = require("./commands/migrate/migrate");
|
|
11
32
|
const program = new commander_1.Command();
|
|
12
33
|
const version = require('../package.json').version;
|
|
13
34
|
program
|
|
14
35
|
.version(version)
|
|
15
36
|
.usage(`vendure <command>`)
|
|
16
|
-
.description(picocolors_1.default.blue(`
|
|
17
|
-
888
|
|
18
|
-
888
|
|
19
|
-
888
|
|
20
|
-
888 888 .d88b. 88888b. .d88888 888 888 888d888 .d88b.
|
|
21
|
-
888 888 d8P Y8b 888 "88b d88" 888 888 888 888P" d8P Y8b
|
|
22
|
-
Y88 88P 88888888 888 888 888 888 888 888 888 88888888
|
|
23
|
-
Y8bd8P Y8b. 888 888 Y88b 888 Y88b 888 888 Y8b.
|
|
24
|
-
Y88P "Y8888 888 888 "Y88888 "Y88888 888 "Y8888
|
|
37
|
+
.description(picocolors_1.default.blue(`
|
|
38
|
+
888
|
|
39
|
+
888
|
|
40
|
+
888
|
|
41
|
+
888 888 .d88b. 88888b. .d88888 888 888 888d888 .d88b.
|
|
42
|
+
888 888 d8P Y8b 888 "88b d88" 888 888 888 888P" d8P Y8b
|
|
43
|
+
Y88 88P 88888888 888 888 888 888 888 888 888 88888888
|
|
44
|
+
Y8bd8P Y8b. 888 888 Y88b 888 Y88b 888 888 Y8b.
|
|
45
|
+
Y88P "Y8888 888 888 "Y88888 "Y88888 888 "Y8888
|
|
25
46
|
`));
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
program
|
|
48
|
+
.command('add')
|
|
49
|
+
.description('Add a feature to your Vendure project')
|
|
50
|
+
.action(async () => {
|
|
51
|
+
const { addCommand } = await Promise.resolve().then(() => __importStar(require('./commands/add/add')));
|
|
52
|
+
await addCommand();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
});
|
|
55
|
+
program
|
|
56
|
+
.command('migrate')
|
|
57
|
+
.description('Generate, run or revert a database migration')
|
|
58
|
+
.action(async () => {
|
|
59
|
+
const { migrateCommand } = await Promise.resolve().then(() => __importStar(require('./commands/migrate/migrate')));
|
|
60
|
+
await migrateCommand();
|
|
61
|
+
process.exit(0);
|
|
62
|
+
});
|
|
28
63
|
void program.parseAsync(process.argv);
|
|
29
64
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,4DAA4B;AAE5B,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAG9B,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC;AAEnD,OAAO;KACF,OAAO,CAAC,OAAO,CAAC;KAChB,KAAK,CAAC,mBAAmB,CAAC;KAC1B,WAAW,CACR,oBAAE,CAAC,IAAI,CAAC;;;;;;;;;CASf,CAAC,CACG,CAAC;AAEN,OAAO;KACF,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,uCAAuC,CAAC;KACpD,MAAM,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,EAAE,UAAU,EAAE,GAAG,wDAAa,oBAAoB,GAAC,CAAC;IAC1D,MAAM,UAAU,EAAE,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEP,OAAO;KACF,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,8CAA8C,CAAC;KAC3D,MAAM,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,EAAE,cAAc,EAAE,GAAG,wDAAa,4BAA4B,GAAC,CAAC;IACtE,MAAM,cAAc,EAAE,CAAC;IACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEP,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function registerAddCommand(program: Command): void;
|
|
1
|
+
export declare function addCommand(): Promise<void>;
|
package/dist/commands/add/add.js
CHANGED
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.addCommand = void 0;
|
|
7
7
|
const prompts_1 = require("@clack/prompts");
|
|
8
8
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
+
const constants_1 = require("../../constants");
|
|
9
10
|
const utils_1 = require("../../utilities/utils");
|
|
10
11
|
const add_api_extension_1 = require("./api-extension/add-api-extension");
|
|
11
12
|
const add_codegen_1 = require("./codegen/add-codegen");
|
|
@@ -15,59 +16,55 @@ const create_new_plugin_1 = require("./plugin/create-new-plugin");
|
|
|
15
16
|
const add_service_1 = require("./service/add-service");
|
|
16
17
|
const add_ui_extensions_1 = require("./ui-extensions/add-ui-extensions");
|
|
17
18
|
const cancelledMessage = 'Add feature cancelled.';
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
async function addCommand() {
|
|
20
|
+
console.log(`\n`);
|
|
21
|
+
(0, prompts_1.intro)(picocolors_1.default.blue("✨ Let's add a new feature to your Vendure project!"));
|
|
22
|
+
const addCommands = [
|
|
23
|
+
create_new_plugin_1.createNewPluginCommand,
|
|
24
|
+
add_entity_1.addEntityCommand,
|
|
25
|
+
add_service_1.addServiceCommand,
|
|
26
|
+
add_api_extension_1.addApiExtensionCommand,
|
|
27
|
+
add_job_queue_1.addJobQueueCommand,
|
|
28
|
+
add_ui_extensions_1.addUiExtensionsCommand,
|
|
29
|
+
add_codegen_1.addCodegenCommand,
|
|
30
|
+
];
|
|
31
|
+
const featureType = await (0, prompts_1.select)({
|
|
32
|
+
message: 'Which feature would you like to add?',
|
|
33
|
+
options: addCommands.map(c => ({
|
|
34
|
+
value: c.id,
|
|
35
|
+
label: `[${c.category}] ${c.description}`,
|
|
36
|
+
})),
|
|
37
|
+
});
|
|
38
|
+
if ((0, prompts_1.isCancel)(featureType)) {
|
|
39
|
+
(0, prompts_1.cancel)(cancelledMessage);
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const command = addCommands.find(c => c.id === featureType);
|
|
44
|
+
if (!command) {
|
|
45
|
+
throw new Error(`Could not find command with id "${featureType}"`);
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const importsSpinner = (0, prompts_1.spinner)();
|
|
53
|
-
importsSpinner.start('Organizing imports...');
|
|
54
|
-
await (0, utils_1.pauseForPromptDisplay)();
|
|
55
|
-
for (const sourceFile of modifiedSourceFiles) {
|
|
56
|
-
sourceFile.organizeImports();
|
|
57
|
-
}
|
|
58
|
-
await project.save();
|
|
59
|
-
importsSpinner.stop('Imports organized');
|
|
47
|
+
const { modifiedSourceFiles, project } = await command.run();
|
|
48
|
+
if (modifiedSourceFiles.length) {
|
|
49
|
+
const importsSpinner = (0, prompts_1.spinner)();
|
|
50
|
+
importsSpinner.start('Organizing imports...');
|
|
51
|
+
await (0, utils_1.pauseForPromptDisplay)();
|
|
52
|
+
for (const sourceFile of modifiedSourceFiles) {
|
|
53
|
+
sourceFile.organizeImports();
|
|
60
54
|
}
|
|
61
|
-
|
|
55
|
+
await project.save();
|
|
56
|
+
importsSpinner.stop('Imports organized');
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
(0, prompts_1.outro)('✅ Done!');
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
prompts_1.log.error(e.message);
|
|
62
|
+
const isCliMessage = Object.values(constants_1.Messages).includes(e.message);
|
|
63
|
+
if (!isCliMessage && e.stack) {
|
|
64
|
+
prompts_1.log.error(e.stack);
|
|
68
65
|
}
|
|
69
|
-
|
|
70
|
-
}
|
|
66
|
+
(0, prompts_1.outro)('❌ Error');
|
|
67
|
+
}
|
|
71
68
|
}
|
|
72
|
-
exports.
|
|
69
|
+
exports.addCommand = addCommand;
|
|
73
70
|
//# sourceMappingURL=add.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/commands/add/add.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAsF;
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/commands/add/add.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAsF;AACtF,4DAA4B;AAE5B,+CAA2C;AAE3C,iDAA8D;AAE9D,yEAA2E;AAC3E,uDAA0D;AAC1D,oDAAuD;AACvD,6DAA+D;AAC/D,kEAAoE;AACpE,uDAA0D;AAC1D,yEAA2E;AAE3E,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAE3C,KAAK,UAAU,UAAU;IAE5B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,IAAA,eAAK,EAAC,oBAAE,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC,CAAC;IACrE,MAAM,WAAW,GAA2B;QACxC,0CAAsB;QACtB,6BAAgB;QAChB,+BAAiB;QACjB,0CAAsB;QACtB,kCAAkB;QAClB,0CAAsB;QACtB,+BAAiB;KACpB,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,IAAA,gBAAM,EAAC;QAC7B,OAAO,EAAE,sCAAsC;QAC/C,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC3B,KAAK,EAAE,CAAC,CAAC,EAAE;YACX,KAAK,EAAE,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,WAAW,EAAE;SAC5C,CAAC,CAAC;KACN,CAAC,CAAC;IACH,IAAI,IAAA,kBAAQ,EAAC,WAAW,CAAC,EAAE,CAAC;QACxB,IAAA,gBAAM,EAAC,gBAAgB,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAqB,GAAG,CAAC,CAAC;QACjF,CAAC;QACD,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;QAE7D,IAAI,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAC7B,MAAM,cAAc,GAAG,IAAA,iBAAO,GAAE,CAAC;YACjC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC9C,MAAM,IAAA,6BAAqB,GAAE,CAAC;YAC9B,KAAK,MAAM,UAAU,IAAI,mBAAmB,EAAE,CAAC;gBAC3C,UAAU,CAAC,eAAe,EAAE,CAAC;YACjC,CAAC;YACD,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;IACrB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QACd,aAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAiB,CAAC,CAAC;QAC/B,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YAC3B,aAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;IACrB,CAAC;AACL,CAAC;AAlDD,gCAkDC"}
|
|
@@ -23,12 +23,30 @@ async function addApiExtension(options) {
|
|
|
23
23
|
const providedVendurePlugin = options === null || options === void 0 ? void 0 : options.plugin;
|
|
24
24
|
const project = await (0, shared_prompts_1.analyzeProject)({ providedVendurePlugin, cancelledMessage });
|
|
25
25
|
const plugin = providedVendurePlugin !== null && providedVendurePlugin !== void 0 ? providedVendurePlugin : (await (0, shared_prompts_1.selectPlugin)(project, cancelledMessage));
|
|
26
|
-
const serviceRef = await (0, shared_prompts_1.selectServiceRef)(project, plugin);
|
|
26
|
+
const serviceRef = await (0, shared_prompts_1.selectServiceRef)(project, plugin, false);
|
|
27
27
|
const serviceEntityRef = serviceRef.crudEntityRef;
|
|
28
28
|
const modifiedSourceFiles = [];
|
|
29
29
|
let resolver;
|
|
30
30
|
let apiExtensions;
|
|
31
31
|
const scaffoldSpinner = (0, prompts_1.spinner)();
|
|
32
|
+
let queryName = '';
|
|
33
|
+
let mutationName = '';
|
|
34
|
+
if (!serviceEntityRef) {
|
|
35
|
+
const queryNameResult = await (0, prompts_1.text)({
|
|
36
|
+
message: 'Enter a name for the new query',
|
|
37
|
+
initialValue: 'myNewQuery',
|
|
38
|
+
});
|
|
39
|
+
if (!(0, prompts_1.isCancel)(queryNameResult)) {
|
|
40
|
+
queryName = queryNameResult;
|
|
41
|
+
}
|
|
42
|
+
const mutationNameResult = await (0, prompts_1.text)({
|
|
43
|
+
message: 'Enter a name for the new mutation',
|
|
44
|
+
initialValue: 'myNewMutation',
|
|
45
|
+
});
|
|
46
|
+
if (!(0, prompts_1.isCancel)(mutationNameResult)) {
|
|
47
|
+
mutationName = mutationNameResult;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
32
50
|
scaffoldSpinner.start('Generating resolver file...');
|
|
33
51
|
await (0, utils_1.pauseForPromptDisplay)();
|
|
34
52
|
if (serviceEntityRef) {
|
|
@@ -36,7 +54,39 @@ async function addApiExtension(options) {
|
|
|
36
54
|
modifiedSourceFiles.push(resolver.getSourceFile());
|
|
37
55
|
}
|
|
38
56
|
else {
|
|
39
|
-
|
|
57
|
+
if ((0, prompts_1.isCancel)(queryName)) {
|
|
58
|
+
(0, prompts_1.cancel)(cancelledMessage);
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
resolver = createSimpleResolver(project, plugin, serviceRef, queryName, mutationName);
|
|
62
|
+
if (queryName) {
|
|
63
|
+
serviceRef.classDeclaration.addMethod({
|
|
64
|
+
name: queryName,
|
|
65
|
+
parameters: [
|
|
66
|
+
{ name: 'ctx', type: 'RequestContext' },
|
|
67
|
+
{ name: 'id', type: 'ID' },
|
|
68
|
+
],
|
|
69
|
+
isAsync: true,
|
|
70
|
+
returnType: 'Promise<boolean>',
|
|
71
|
+
statements: `return true;`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (mutationName) {
|
|
75
|
+
serviceRef.classDeclaration.addMethod({
|
|
76
|
+
name: mutationName,
|
|
77
|
+
parameters: [
|
|
78
|
+
{ name: 'ctx', type: 'RequestContext' },
|
|
79
|
+
{ name: 'id', type: 'ID' },
|
|
80
|
+
],
|
|
81
|
+
isAsync: true,
|
|
82
|
+
returnType: 'Promise<boolean>',
|
|
83
|
+
statements: `return true;`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
(0, ast_utils_1.addImportsToFile)(serviceRef.classDeclaration.getSourceFile(), {
|
|
87
|
+
namedImports: ['RequestContext', 'ID'],
|
|
88
|
+
moduleSpecifier: '@vendure/core',
|
|
89
|
+
});
|
|
40
90
|
modifiedSourceFiles.push(resolver.getSourceFile());
|
|
41
91
|
}
|
|
42
92
|
scaffoldSpinner.message('Generating schema definitions...');
|
|
@@ -45,7 +95,7 @@ async function addApiExtension(options) {
|
|
|
45
95
|
apiExtensions = createCrudApiExtension(project, plugin, serviceRef);
|
|
46
96
|
}
|
|
47
97
|
else {
|
|
48
|
-
apiExtensions = createSimpleApiExtension(project, plugin, serviceRef);
|
|
98
|
+
apiExtensions = createSimpleApiExtension(project, plugin, serviceRef, queryName, mutationName);
|
|
49
99
|
}
|
|
50
100
|
if (apiExtensions) {
|
|
51
101
|
modifiedSourceFiles.push(apiExtensions.getSourceFile());
|
|
@@ -74,17 +124,56 @@ async function addApiExtension(options) {
|
|
|
74
124
|
serviceRef,
|
|
75
125
|
};
|
|
76
126
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
127
|
+
function getResolverFileName(project, serviceRef) {
|
|
128
|
+
let suffix;
|
|
129
|
+
let resolverFileName = '';
|
|
130
|
+
let sourceFileExists = false;
|
|
131
|
+
do {
|
|
132
|
+
resolverFileName =
|
|
133
|
+
(0, change_case_1.paramCase)(serviceRef.name).replace('-service', '') +
|
|
134
|
+
`-admin.resolver${typeof suffix === 'number' ? `-${suffix === null || suffix === void 0 ? void 0 : suffix.toString()}` : ''}.ts`;
|
|
135
|
+
sourceFileExists = !!project.getSourceFile(resolverFileName);
|
|
136
|
+
if (sourceFileExists) {
|
|
137
|
+
suffix = (suffix !== null && suffix !== void 0 ? suffix : 1) + 1;
|
|
138
|
+
}
|
|
139
|
+
} while (sourceFileExists);
|
|
140
|
+
return { resolverFileName, suffix };
|
|
141
|
+
}
|
|
142
|
+
function createSimpleResolver(project, plugin, serviceRef, queryName, mutationName) {
|
|
143
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
144
|
+
const { resolverFileName, suffix } = getResolverFileName(project, serviceRef);
|
|
79
145
|
const resolverSourceFile = (0, ast_utils_1.createFile)(project, path_1.default.join(__dirname, 'templates/simple-resolver.template.ts'));
|
|
80
|
-
resolverSourceFile.move(path_1.default.join(plugin.getPluginDir().getPath(), 'api',
|
|
146
|
+
resolverSourceFile.move(path_1.default.join(plugin.getPluginDir().getPath(), 'api', resolverFileName));
|
|
81
147
|
const resolverClassDeclaration = resolverSourceFile
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
(
|
|
148
|
+
.getClasses()
|
|
149
|
+
.find(cl => cl.getDecorator('Resolver') != null);
|
|
150
|
+
if (!resolverClassDeclaration) {
|
|
151
|
+
throw new Error('Could not find resolver class declaration');
|
|
152
|
+
}
|
|
153
|
+
if (resolverClassDeclaration.getName() === 'SimpleAdminResolver') {
|
|
154
|
+
resolverClassDeclaration.rename(serviceRef.name.replace(/Service$/, '') + 'AdminResolver' + (suffix ? suffix.toString() : ''));
|
|
155
|
+
}
|
|
156
|
+
if (queryName) {
|
|
157
|
+
(_b = (_a = resolverSourceFile.getClass('TemplateService')) === null || _a === void 0 ? void 0 : _a.getMethod('exampleQueryHandler')) === null || _b === void 0 ? void 0 : _b.rename(queryName);
|
|
158
|
+
(_c = resolverClassDeclaration.getMethod('exampleQuery')) === null || _c === void 0 ? void 0 : _c.rename(queryName);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
(_e = (_d = resolverSourceFile.getClass('TemplateService')) === null || _d === void 0 ? void 0 : _d.getMethod('exampleQueryHandler')) === null || _e === void 0 ? void 0 : _e.remove();
|
|
162
|
+
(_f = resolverClassDeclaration.getMethod('exampleQuery')) === null || _f === void 0 ? void 0 : _f.remove();
|
|
163
|
+
}
|
|
164
|
+
if (mutationName) {
|
|
165
|
+
(_h = (_g = resolverSourceFile
|
|
166
|
+
.getClass('TemplateService')) === null || _g === void 0 ? void 0 : _g.getMethod('exampleMutationHandler')) === null || _h === void 0 ? void 0 : _h.rename(mutationName);
|
|
167
|
+
(_j = resolverClassDeclaration.getMethod('exampleMutation')) === null || _j === void 0 ? void 0 : _j.rename(mutationName);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
(_l = (_k = resolverSourceFile.getClass('TemplateService')) === null || _k === void 0 ? void 0 : _k.getMethod('exampleMutationHandler')) === null || _l === void 0 ? void 0 : _l.remove();
|
|
171
|
+
(_m = resolverClassDeclaration.getMethod('exampleMutation')) === null || _m === void 0 ? void 0 : _m.remove();
|
|
172
|
+
}
|
|
173
|
+
(_o = resolverClassDeclaration
|
|
85
174
|
.getConstructors()[0]
|
|
86
|
-
.getParameter('templateService')) === null ||
|
|
87
|
-
(
|
|
175
|
+
.getParameter('templateService')) === null || _o === void 0 ? void 0 : _o.rename(serviceRef.nameCamelCase).setType(serviceRef.name);
|
|
176
|
+
(_p = resolverSourceFile.getClass('TemplateService')) === null || _p === void 0 ? void 0 : _p.remove();
|
|
88
177
|
(0, ast_utils_1.addImportsToFile)(resolverSourceFile, {
|
|
89
178
|
namedImports: [serviceRef.name],
|
|
90
179
|
moduleSpecifier: serviceRef.classDeclaration.getSourceFile(),
|
|
@@ -164,34 +253,64 @@ function createCrudResolver(project, plugin, serviceRef, serviceEntityRef) {
|
|
|
164
253
|
});
|
|
165
254
|
return resolverClassDeclaration;
|
|
166
255
|
}
|
|
167
|
-
function createSimpleApiExtension(project, plugin, serviceRef) {
|
|
168
|
-
var _a;
|
|
256
|
+
function createSimpleApiExtension(project, plugin, serviceRef, queryName, mutationName) {
|
|
257
|
+
var _a, _b, _c;
|
|
169
258
|
const apiExtensionsFile = getOrCreateApiExtensionsFile(project, plugin);
|
|
170
|
-
const
|
|
171
|
-
const insertAtIndex = (_a =
|
|
259
|
+
const adminApiExtensions = apiExtensionsFile.getVariableDeclaration('adminApiExtensions');
|
|
260
|
+
const insertAtIndex = (_a = adminApiExtensions === null || adminApiExtensions === void 0 ? void 0 : adminApiExtensions.getParent().getParent().getChildIndex()) !== null && _a !== void 0 ? _a : 2;
|
|
172
261
|
const schemaVariableName = `${serviceRef.nameCamelCase.replace(/Service$/, '')}AdminApiExtensions`;
|
|
173
|
-
apiExtensionsFile.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
writer
|
|
262
|
+
const existingSchemaVariable = apiExtensionsFile.getVariableStatement(schemaVariableName);
|
|
263
|
+
if (!existingSchemaVariable) {
|
|
264
|
+
apiExtensionsFile.insertVariableStatement(insertAtIndex, {
|
|
265
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
266
|
+
declarations: [
|
|
267
|
+
{
|
|
268
|
+
name: schemaVariableName,
|
|
269
|
+
initializer: writer => {
|
|
270
|
+
writer.writeLine(`gql\``);
|
|
271
|
+
writer.indent(() => {
|
|
272
|
+
if (queryName) {
|
|
273
|
+
writer.writeLine(` extend type Query {`);
|
|
274
|
+
writer.writeLine(` ${queryName}(id: ID!): Boolean!`);
|
|
275
|
+
writer.writeLine(` }`);
|
|
276
|
+
}
|
|
277
|
+
writer.newLine();
|
|
278
|
+
if (mutationName) {
|
|
279
|
+
writer.writeLine(` extend type Mutation {`);
|
|
280
|
+
writer.writeLine(` ${mutationName}(id: ID!): Boolean!`);
|
|
281
|
+
writer.writeLine(` }`);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
writer.write(`\``);
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
const taggedTemplateLiteral = (_c = (_b = existingSchemaVariable
|
|
292
|
+
.getDeclarations()[0]) === null || _b === void 0 ? void 0 : _b.getFirstChildByKind(ts_morph_1.SyntaxKind.TaggedTemplateExpression)) === null || _c === void 0 ? void 0 : _c.getChildren()[1];
|
|
293
|
+
if (!taggedTemplateLiteral) {
|
|
294
|
+
prompts_1.log.error('Could not update schema automatically');
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
appendToGqlTemplateLiteral(existingSchemaVariable.getDeclarations()[0], writer => {
|
|
298
|
+
writer.indent(() => {
|
|
299
|
+
if (queryName) {
|
|
181
300
|
writer.writeLine(` extend type Query {`);
|
|
182
|
-
writer.writeLine(`
|
|
301
|
+
writer.writeLine(` ${queryName}(id: ID!): Boolean!`);
|
|
183
302
|
writer.writeLine(` }`);
|
|
184
|
-
|
|
303
|
+
}
|
|
304
|
+
writer.newLine();
|
|
305
|
+
if (mutationName) {
|
|
185
306
|
writer.writeLine(` extend type Mutation {`);
|
|
186
|
-
writer.writeLine(`
|
|
307
|
+
writer.writeLine(` ${mutationName}(id: ID!): Boolean!`);
|
|
187
308
|
writer.writeLine(` }`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
const adminApiExtensions = apiExtensionsFile.getVariableDeclaration('adminApiExtensions');
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
195
314
|
addSchemaToApiExtensionsTemplateLiteral(adminApiExtensions, schemaVariableName);
|
|
196
315
|
return adminApiExtensions;
|
|
197
316
|
}
|
|
@@ -211,6 +330,24 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
211
330
|
const entityRef = serviceRef.crudEntityRef;
|
|
212
331
|
if (entityRef) {
|
|
213
332
|
writer.indent(() => {
|
|
333
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
334
|
+
if (entityRef.isTranslatable()) {
|
|
335
|
+
const translationClass = entityRef.getTranslationClass();
|
|
336
|
+
if (translationClass) {
|
|
337
|
+
writer.writeLine(` type ${(_a = translationClass.getName()) !== null && _a !== void 0 ? _a : ''} {`);
|
|
338
|
+
writer.writeLine(` id: ID!`);
|
|
339
|
+
writer.writeLine(` createdAt: DateTime!`);
|
|
340
|
+
writer.writeLine(` updatedAt: DateTime!`);
|
|
341
|
+
writer.writeLine(` languageCode: LanguageCode!`);
|
|
342
|
+
for (const { name, type, nullable } of entityRef.getProps()) {
|
|
343
|
+
if (type.getText().includes('LocaleString')) {
|
|
344
|
+
writer.writeLine(` ${name}: String${nullable ? '' : '!'}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
writer.writeLine(` }`);
|
|
348
|
+
writer.newLine();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
214
351
|
writer.writeLine(` type ${entityRef.name} implements Node {`);
|
|
215
352
|
writer.writeLine(` id: ID!`);
|
|
216
353
|
writer.writeLine(` createdAt: DateTime!`);
|
|
@@ -221,6 +358,9 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
221
358
|
writer.writeLine(` ${name}: ${graphQlType}${nullable ? '' : '!'}`);
|
|
222
359
|
}
|
|
223
360
|
}
|
|
361
|
+
if (entityRef.isTranslatable()) {
|
|
362
|
+
writer.writeLine(` translations: [${(_c = (_b = entityRef.getTranslationClass()) === null || _b === void 0 ? void 0 : _b.getName()) !== null && _c !== void 0 ? _c : ''}!]!`);
|
|
363
|
+
}
|
|
224
364
|
writer.writeLine(` }`);
|
|
225
365
|
writer.newLine();
|
|
226
366
|
writer.writeLine(` type ${entityRef.name}List implements PaginatedList {`);
|
|
@@ -240,6 +380,19 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
240
380
|
}
|
|
241
381
|
writer.writeLine(` }`);
|
|
242
382
|
writer.newLine();
|
|
383
|
+
if (entityRef.isTranslatable() &&
|
|
384
|
+
(serviceRef.features.create || serviceRef.features.update)) {
|
|
385
|
+
writer.writeLine(` input ${(_e = (_d = entityRef.getTranslationClass()) === null || _d === void 0 ? void 0 : _d.getName()) !== null && _e !== void 0 ? _e : ''}Input {`);
|
|
386
|
+
writer.writeLine(` id: ID`);
|
|
387
|
+
writer.writeLine(` languageCode: LanguageCode!`);
|
|
388
|
+
for (const { name, type, nullable } of entityRef.getProps()) {
|
|
389
|
+
if (type.getText().includes('LocaleString')) {
|
|
390
|
+
writer.writeLine(` ${name}: String`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
writer.writeLine(` }`);
|
|
394
|
+
writer.newLine();
|
|
395
|
+
}
|
|
243
396
|
if (serviceRef.features.create) {
|
|
244
397
|
writer.writeLine(` input Create${entityRef.name}Input {`);
|
|
245
398
|
for (const { name, type, nullable } of entityRef.getProps()) {
|
|
@@ -248,6 +401,9 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
248
401
|
writer.writeLine(` ${name}: ${graphQlType}${nullable ? '' : '!'}`);
|
|
249
402
|
}
|
|
250
403
|
}
|
|
404
|
+
if (entityRef.isTranslatable()) {
|
|
405
|
+
writer.writeLine(` translations: [${(_g = (_f = entityRef.getTranslationClass()) === null || _f === void 0 ? void 0 : _f.getName()) !== null && _g !== void 0 ? _g : ''}Input!]!`);
|
|
406
|
+
}
|
|
251
407
|
writer.writeLine(` }`);
|
|
252
408
|
writer.newLine();
|
|
253
409
|
}
|
|
@@ -260,6 +416,9 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
260
416
|
writer.writeLine(` ${name}: ${graphQlType}`);
|
|
261
417
|
}
|
|
262
418
|
}
|
|
419
|
+
if (entityRef.isTranslatable()) {
|
|
420
|
+
writer.writeLine(` translations: [${(_j = (_h = entityRef.getTranslationClass()) === null || _h === void 0 ? void 0 : _h.getName()) !== null && _j !== void 0 ? _j : ''}Input!]`);
|
|
421
|
+
}
|
|
263
422
|
writer.writeLine(` }`);
|
|
264
423
|
writer.newLine();
|
|
265
424
|
}
|
|
@@ -290,23 +449,31 @@ function createCrudApiExtension(project, plugin, serviceRef) {
|
|
|
290
449
|
}
|
|
291
450
|
function addSchemaToApiExtensionsTemplateLiteral(adminApiExtensions, schemaVariableName) {
|
|
292
451
|
if (adminApiExtensions) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
adminApiExtensions
|
|
296
|
-
.setInitializer(writer => {
|
|
297
|
-
writer.writeLine(`gql\``);
|
|
298
|
-
const template = apiExtensionsInitializer.getTemplate();
|
|
299
|
-
if (ts_morph_1.Node.isNoSubstitutionTemplateLiteral(template)) {
|
|
300
|
-
writer.write(`${template.getLiteralValue()}`);
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
writer.write(template.getText().replace(/^`/, '').replace(/`$/, ''));
|
|
304
|
-
}
|
|
305
|
-
writer.writeLine(` \${${schemaVariableName}}`);
|
|
306
|
-
writer.write(`\``);
|
|
307
|
-
})
|
|
308
|
-
.formatText();
|
|
452
|
+
if (adminApiExtensions.getText().includes(` \${${schemaVariableName}}`)) {
|
|
453
|
+
return;
|
|
309
454
|
}
|
|
455
|
+
appendToGqlTemplateLiteral(adminApiExtensions, writer => {
|
|
456
|
+
writer.writeLine(` \${${schemaVariableName}}`);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function appendToGqlTemplateLiteral(variableDeclaration, append) {
|
|
461
|
+
const initializer = variableDeclaration.getInitializer();
|
|
462
|
+
if (ts_morph_1.Node.isTaggedTemplateExpression(initializer)) {
|
|
463
|
+
variableDeclaration
|
|
464
|
+
.setInitializer(writer => {
|
|
465
|
+
writer.write(`gql\``);
|
|
466
|
+
const template = initializer.getTemplate();
|
|
467
|
+
if (ts_morph_1.Node.isNoSubstitutionTemplateLiteral(template)) {
|
|
468
|
+
writer.write(`${template.getLiteralValue()}`);
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
writer.write(template.getText().replace(/^`/, '').replace(/`$/, ''));
|
|
472
|
+
}
|
|
473
|
+
append(writer);
|
|
474
|
+
writer.write(`\``);
|
|
475
|
+
})
|
|
476
|
+
.formatText();
|
|
310
477
|
}
|
|
311
478
|
}
|
|
312
479
|
function getGraphQLType(type) {
|
|
@@ -319,9 +486,12 @@ function getGraphQLType(type) {
|
|
|
319
486
|
if (type.isNumber()) {
|
|
320
487
|
return 'Int';
|
|
321
488
|
}
|
|
322
|
-
if (type.
|
|
489
|
+
if (type.isObject() && type.getText() === 'Date') {
|
|
323
490
|
return 'DateTime';
|
|
324
491
|
}
|
|
492
|
+
if (type.getText().includes('LocaleString')) {
|
|
493
|
+
return 'String';
|
|
494
|
+
}
|
|
325
495
|
return;
|
|
326
496
|
}
|
|
327
497
|
function getOrCreateApiExtensionsFile(project, plugin) {
|