@vendure/cli 2.2.0-next.7 → 2.2.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/cli.js +54 -5
- package/dist/cli.js.map +1 -1
- package/dist/commands/add/add.d.ts +1 -2
- package/dist/commands/add/add.js +58 -27
- package/dist/commands/add/add.js.map +1 -1
- package/dist/commands/add/api-extension/add-api-extension.d.ts +9 -0
- package/dist/commands/add/api-extension/add-api-extension.js +506 -0
- package/dist/commands/add/api-extension/add-api-extension.js.map +1 -0
- package/dist/commands/add/api-extension/templates/api-extensions.template.ts +3 -0
- package/dist/commands/add/api-extension/templates/crud-resolver.template.ts +109 -0
- package/dist/commands/add/api-extension/templates/simple-resolver.template.ts +31 -0
- package/dist/commands/add/codegen/add-codegen.d.ts +8 -0
- package/dist/commands/add/codegen/add-codegen.js +106 -0
- package/dist/commands/add/codegen/add-codegen.js.map +1 -0
- package/dist/commands/add/codegen/codegen-config-ref.d.ts +10 -0
- package/dist/commands/add/codegen/codegen-config-ref.js +53 -0
- package/dist/commands/add/codegen/codegen-config-ref.js.map +1 -0
- package/dist/commands/add/codegen/templates/codegen.template.ts +17 -0
- package/dist/commands/add/entity/add-entity.d.ts +15 -5
- package/dist/commands/add/entity/add-entity.js +130 -23
- package/dist/commands/add/entity/add-entity.js.map +1 -1
- package/dist/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.d.ts +3 -2
- package/dist/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.js +3 -27
- package/dist/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.js.map +1 -1
- package/dist/commands/add/entity/templates/entity-translation.template.ts +29 -0
- package/dist/commands/add/entity/templates/entity.template.ts +18 -4
- package/dist/commands/add/job-queue/add-job-queue.d.ts +9 -0
- package/dist/commands/add/job-queue/add-job-queue.js +130 -0
- package/dist/commands/add/job-queue/add-job-queue.js.map +1 -0
- package/dist/commands/add/plugin/create-new-plugin.d.ts +8 -0
- package/dist/commands/add/plugin/create-new-plugin.js +209 -0
- package/dist/commands/add/plugin/create-new-plugin.js.map +1 -0
- package/dist/commands/add/plugin/templates/constants.template.ts +2 -0
- package/dist/commands/add/plugin/templates/plugin.template.ts +25 -0
- package/dist/commands/add/plugin/templates/types.template.ts +7 -0
- package/dist/commands/add/plugin/types.d.ts +8 -0
- package/dist/commands/add/plugin/types.js.map +1 -0
- package/dist/commands/add/service/add-service.d.ts +5 -0
- package/dist/commands/add/service/add-service.js +278 -0
- package/dist/commands/add/service/add-service.js.map +1 -0
- package/dist/commands/add/service/templates/basic-service.template.ts +13 -0
- package/dist/commands/add/service/templates/entity-service.template.ts +146 -0
- package/dist/commands/add/ui-extensions/add-ui-extensions.d.ts +6 -1
- package/dist/commands/add/ui-extensions/add-ui-extensions.js +32 -42
- package/dist/commands/add/ui-extensions/add-ui-extensions.js.map +1 -1
- package/dist/commands/add/ui-extensions/codemods/add-ui-extension-static-prop/add-ui-extension-static-prop.d.ts +2 -2
- package/dist/commands/add/ui-extensions/codemods/add-ui-extension-static-prop/add-ui-extension-static-prop.js +6 -3
- package/dist/commands/add/ui-extensions/codemods/add-ui-extension-static-prop/add-ui-extension-static-prop.js.map +1 -1
- package/dist/commands/add/ui-extensions/codemods/update-admin-ui-plugin-init/update-admin-ui-plugin-init.d.ts +2 -2
- package/dist/commands/add/ui-extensions/codemods/update-admin-ui-plugin-init/update-admin-ui-plugin-init.js +10 -10
- package/dist/commands/add/ui-extensions/codemods/update-admin-ui-plugin-init/update-admin-ui-plugin-init.js.map +1 -1
- package/dist/commands/add/ui-extensions/templates/providers.template.ts +3 -0
- package/dist/commands/add/ui-extensions/templates/routes.template.ts +3 -0
- package/dist/commands/migrate/generate-migration/generate-migration.d.ts +2 -0
- package/dist/commands/migrate/generate-migration/generate-migration.js +48 -0
- package/dist/commands/migrate/generate-migration/generate-migration.js.map +1 -0
- package/dist/commands/migrate/load-vendure-config-file.d.ts +2 -0
- package/dist/commands/migrate/load-vendure-config-file.js +24 -0
- package/dist/commands/migrate/load-vendure-config-file.js.map +1 -0
- package/dist/commands/migrate/migrate.d.ts +1 -0
- package/dist/commands/migrate/migrate.js +50 -0
- package/dist/commands/migrate/migrate.js.map +1 -0
- package/dist/commands/migrate/revert-migration/revert-migration.d.ts +2 -0
- package/dist/commands/migrate/revert-migration/revert-migration.js +31 -0
- package/dist/commands/migrate/revert-migration/revert-migration.js.map +1 -0
- package/dist/commands/migrate/run-migration/run-migration.d.ts +2 -0
- package/dist/commands/migrate/run-migration/run-migration.js +34 -0
- package/dist/commands/migrate/run-migration/run-migration.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +9 -1
- package/dist/constants.js.map +1 -1
- package/dist/shared/cli-command.d.ts +24 -0
- package/dist/shared/cli-command.js +22 -0
- package/dist/shared/cli-command.js.map +1 -0
- package/dist/shared/entity-ref.d.ts +16 -0
- package/dist/shared/entity-ref.js +48 -0
- package/dist/shared/entity-ref.js.map +1 -0
- package/dist/shared/package-json-ref.d.ts +17 -0
- package/dist/shared/package-json-ref.js +115 -0
- package/dist/shared/package-json-ref.js.map +1 -0
- package/dist/shared/service-ref.d.ts +25 -0
- package/dist/shared/service-ref.js +82 -0
- package/dist/shared/service-ref.js.map +1 -0
- package/dist/shared/shared-prompts.d.ts +13 -3
- package/dist/shared/shared-prompts.js +143 -24
- package/dist/shared/shared-prompts.js.map +1 -1
- package/dist/shared/vendure-config-ref.d.ts +14 -0
- package/dist/shared/vendure-config-ref.js +65 -0
- package/dist/shared/vendure-config-ref.js.map +1 -0
- package/dist/shared/vendure-plugin-ref.d.ts +18 -0
- package/dist/shared/vendure-plugin-ref.js +145 -0
- package/dist/shared/vendure-plugin-ref.js.map +1 -0
- package/dist/utilities/ast-utils.d.ts +7 -9
- package/dist/utilities/ast-utils.js +65 -39
- package/dist/utilities/ast-utils.js.map +1 -1
- package/dist/utilities/utils.d.ts +2 -0
- package/dist/utilities/utils.js +12 -0
- package/dist/utilities/utils.js.map +1 -0
- package/package.json +6 -4
- package/dist/commands/add/ui-extensions/scaffold/providers.d.ts +0 -1
- package/dist/commands/add/ui-extensions/scaffold/providers.js +0 -13
- package/dist/commands/add/ui-extensions/scaffold/providers.js.map +0 -1
- package/dist/commands/add/ui-extensions/scaffold/routes.d.ts +0 -1
- package/dist/commands/add/ui-extensions/scaffold/routes.js +0 -13
- package/dist/commands/add/ui-extensions/scaffold/routes.js.map +0 -1
- package/dist/commands/new/new.d.ts +0 -2
- package/dist/commands/new/new.js +0 -18
- package/dist/commands/new/new.js.map +0 -1
- package/dist/commands/new/plugin/new-plugin.d.ts +0 -3
- package/dist/commands/new/plugin/new-plugin.js +0 -158
- package/dist/commands/new/plugin/new-plugin.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/api/admin.resolver.d.ts +0 -3
- package/dist/commands/new/plugin/scaffold/api/admin.resolver.js +0 -66
- package/dist/commands/new/plugin/scaffold/api/admin.resolver.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/api/api-extensions.d.ts +0 -2
- package/dist/commands/new/plugin/scaffold/api/api-extensions.js +0 -82
- package/dist/commands/new/plugin/scaffold/api/api-extensions.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/api/shop.resolver.d.ts +0 -3
- package/dist/commands/new/plugin/scaffold/api/shop.resolver.js +0 -57
- package/dist/commands/new/plugin/scaffold/api/shop.resolver.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/constants.d.ts +0 -2
- package/dist/commands/new/plugin/scaffold/constants.js +0 -21
- package/dist/commands/new/plugin/scaffold/constants.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/plugin.d.ts +0 -2
- package/dist/commands/new/plugin/scaffold/plugin.js +0 -51
- package/dist/commands/new/plugin/scaffold/plugin.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/services/service.d.ts +0 -3
- package/dist/commands/new/plugin/scaffold/services/service.js +0 -80
- package/dist/commands/new/plugin/scaffold/services/service.js.map +0 -1
- package/dist/commands/new/plugin/scaffold/types.d.ts +0 -2
- package/dist/commands/new/plugin/scaffold/types.js +0 -15
- package/dist/commands/new/plugin/scaffold/types.js.map +0 -1
- package/dist/commands/new/plugin/types.d.ts +0 -22
- package/dist/commands/new/plugin/types.js.map +0 -1
- package/dist/shared/shared-scaffold/entity.d.ts +0 -5
- package/dist/shared/shared-scaffold/entity.js +0 -26
- package/dist/shared/shared-scaffold/entity.js.map +0 -1
- package/dist/utilities/package-utils.d.ts +0 -8
- package/dist/utilities/package-utils.js +0 -96
- package/dist/utilities/package-utils.js.map +0 -1
- package/dist/utilities/scaffolder.d.ts +0 -8
- package/dist/utilities/scaffolder.js +0 -50
- package/dist/utilities/scaffolder.js.map +0 -1
- /package/dist/commands/{new → add}/plugin/types.js +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
|
2
|
+
import { Permission } from '@vendure/common/lib/generated-types';
|
|
3
|
+
import { ID } from '@vendure/common/lib/shared-types';
|
|
4
|
+
import { Allow, Ctx, RequestContext, Transaction } from '@vendure/core';
|
|
5
|
+
|
|
6
|
+
class TemplateService {
|
|
7
|
+
async exampleQueryHandler(ctx: RequestContext, id: ID) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
async exampleMutationHandler(ctx: RequestContext, id: ID) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Resolver()
|
|
16
|
+
export class SimpleAdminResolver {
|
|
17
|
+
constructor(private templateService: TemplateService) {}
|
|
18
|
+
|
|
19
|
+
@Query()
|
|
20
|
+
@Allow(Permission.SuperAdmin)
|
|
21
|
+
async exampleQuery(@Ctx() ctx: RequestContext, @Args() args: { id: ID }): Promise<boolean> {
|
|
22
|
+
return this.templateService.exampleQueryHandler(ctx, args.id);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Mutation()
|
|
26
|
+
@Transaction()
|
|
27
|
+
@Allow(Permission.SuperAdmin)
|
|
28
|
+
async exampleMutation(@Ctx() ctx: RequestContext, @Args() args: { id: ID }): Promise<boolean> {
|
|
29
|
+
return this.templateService.exampleMutationHandler(ctx, args.id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CliCommand, CliCommandReturnVal } from '../../../shared/cli-command';
|
|
2
|
+
import { VendurePluginRef } from '../../../shared/vendure-plugin-ref';
|
|
3
|
+
export interface AddCodegenOptions {
|
|
4
|
+
plugin?: VendurePluginRef;
|
|
5
|
+
}
|
|
6
|
+
export declare const addCodegenCommand: CliCommand<{
|
|
7
|
+
plugin: VendurePluginRef;
|
|
8
|
+
}, CliCommandReturnVal>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addCodegenCommand = void 0;
|
|
7
|
+
const prompts_1 = require("@clack/prompts");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ts_morph_1 = require("ts-morph");
|
|
10
|
+
const cli_command_1 = require("../../../shared/cli-command");
|
|
11
|
+
const package_json_ref_1 = require("../../../shared/package-json-ref");
|
|
12
|
+
const shared_prompts_1 = require("../../../shared/shared-prompts");
|
|
13
|
+
const ast_utils_1 = require("../../../utilities/ast-utils");
|
|
14
|
+
const utils_1 = require("../../../utilities/utils");
|
|
15
|
+
const codegen_config_ref_1 = require("./codegen-config-ref");
|
|
16
|
+
exports.addCodegenCommand = new cli_command_1.CliCommand({
|
|
17
|
+
id: 'add-codegen',
|
|
18
|
+
category: 'Project: Codegen',
|
|
19
|
+
description: 'Set up GraphQL code generation',
|
|
20
|
+
run: addCodegen,
|
|
21
|
+
});
|
|
22
|
+
async function addCodegen(options) {
|
|
23
|
+
const providedVendurePlugin = options === null || options === void 0 ? void 0 : options.plugin;
|
|
24
|
+
const project = await (0, shared_prompts_1.analyzeProject)({
|
|
25
|
+
providedVendurePlugin,
|
|
26
|
+
cancelledMessage: 'Add codegen cancelled',
|
|
27
|
+
});
|
|
28
|
+
const plugins = providedVendurePlugin
|
|
29
|
+
? [providedVendurePlugin]
|
|
30
|
+
: await (0, shared_prompts_1.selectMultiplePluginClasses)(project, 'Add codegen cancelled');
|
|
31
|
+
const packageJson = new package_json_ref_1.PackageJson(project);
|
|
32
|
+
const installSpinner = (0, prompts_1.spinner)();
|
|
33
|
+
installSpinner.start(`Installing dependencies...`);
|
|
34
|
+
const packagesToInstall = [
|
|
35
|
+
{
|
|
36
|
+
pkg: '@graphql-codegen/cli',
|
|
37
|
+
isDevDependency: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
pkg: '@graphql-codegen/typescript',
|
|
41
|
+
isDevDependency: true,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
if (plugins.some(p => p.hasUiExtensions())) {
|
|
45
|
+
packagesToInstall.push({
|
|
46
|
+
pkg: '@graphql-codegen/client-preset',
|
|
47
|
+
isDevDependency: true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await packageJson.installPackages(packagesToInstall);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
prompts_1.log.error(`Failed to install dependencies: ${e.message}.`);
|
|
55
|
+
}
|
|
56
|
+
installSpinner.stop('Dependencies installed');
|
|
57
|
+
const configSpinner = (0, prompts_1.spinner)();
|
|
58
|
+
configSpinner.start('Configuring codegen file...');
|
|
59
|
+
await (0, utils_1.pauseForPromptDisplay)();
|
|
60
|
+
const codegenFile = new codegen_config_ref_1.CodegenConfigRef(packageJson.getPackageRootDir());
|
|
61
|
+
const rootDir = project.getDirectory('.');
|
|
62
|
+
if (!rootDir) {
|
|
63
|
+
throw new Error('Could not find the root directory of the project');
|
|
64
|
+
}
|
|
65
|
+
for (const plugin of plugins) {
|
|
66
|
+
const relativePluginPath = (0, ast_utils_1.getRelativeImportPath)({
|
|
67
|
+
from: rootDir,
|
|
68
|
+
to: plugin.classDeclaration.getSourceFile(),
|
|
69
|
+
});
|
|
70
|
+
const generatedTypesPath = `${path_1.default.dirname(relativePluginPath)}/gql/generated.ts`;
|
|
71
|
+
codegenFile.addEntryToGeneratesObject({
|
|
72
|
+
name: `'${generatedTypesPath}'`,
|
|
73
|
+
kind: ts_morph_1.StructureKind.PropertyAssignment,
|
|
74
|
+
initializer: `{ plugins: ['typescript'] }`,
|
|
75
|
+
});
|
|
76
|
+
if (plugin.hasUiExtensions()) {
|
|
77
|
+
const uiExtensionsPath = `${path_1.default.dirname(relativePluginPath)}/ui`;
|
|
78
|
+
codegenFile.addEntryToGeneratesObject({
|
|
79
|
+
name: `'${uiExtensionsPath}/gql/'`,
|
|
80
|
+
kind: ts_morph_1.StructureKind.PropertyAssignment,
|
|
81
|
+
initializer: `{
|
|
82
|
+
preset: 'client',
|
|
83
|
+
documents: '${uiExtensionsPath}/**/*.ts',
|
|
84
|
+
presetConfig: {
|
|
85
|
+
fragmentMasking: false,
|
|
86
|
+
},
|
|
87
|
+
}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
packageJson.addScript('codegen', 'graphql-codegen --config codegen.ts');
|
|
92
|
+
configSpinner.stop('Configured codegen file');
|
|
93
|
+
await project.save();
|
|
94
|
+
await codegenFile.save();
|
|
95
|
+
const nextSteps = [
|
|
96
|
+
`You can run codegen by doing the following:`,
|
|
97
|
+
`1. Ensure your dev server is running`,
|
|
98
|
+
`2. Run "npm run codegen"`,
|
|
99
|
+
];
|
|
100
|
+
(0, prompts_1.note)(nextSteps.join('\n'));
|
|
101
|
+
return {
|
|
102
|
+
project,
|
|
103
|
+
modifiedSourceFiles: [codegenFile.sourceFile],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=add-codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-codegen.js","sourceRoot":"","sources":["../../../../src/commands/add/codegen/add-codegen.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA2D;AAC3D,gDAAwB;AACxB,uCAAyC;AAEzC,6DAA8E;AAC9E,uEAA+D;AAC/D,mEAA6F;AAE7F,4DAAqE;AACrE,oDAAiE;AAEjE,6DAAwD;AAM3C,QAAA,iBAAiB,GAAG,IAAI,wBAAU,CAAC;IAC5C,EAAE,EAAE,aAAa;IACjB,QAAQ,EAAE,kBAAkB;IAC5B,WAAW,EAAE,gCAAgC;IAC7C,GAAG,EAAE,UAAU;CAClB,CAAC,CAAC;AAEH,KAAK,UAAU,UAAU,CAAC,OAA2B;IACjD,MAAM,qBAAqB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,IAAA,+BAAc,EAAC;QACjC,qBAAqB;QACrB,gBAAgB,EAAE,uBAAuB;KAC5C,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,qBAAqB;QACjC,CAAC,CAAC,CAAC,qBAAqB,CAAC;QACzB,CAAC,CAAC,MAAM,IAAA,4CAA2B,EAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAE1E,MAAM,WAAW,GAAG,IAAI,8BAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,cAAc,GAAG,IAAA,iBAAO,GAAE,CAAC;IACjC,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACnD,MAAM,iBAAiB,GAAG;QACtB;YACI,GAAG,EAAE,sBAAsB;YAC3B,eAAe,EAAE,IAAI;SACxB;QACD;YACI,GAAG,EAAE,6BAA6B;YAClC,eAAe,EAAE,IAAI;SACxB;KACJ,CAAC;IACF,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE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eAAe,EAAE,EAAE,CAAC;YAC3B,MAAM,gBAAgB,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC;YAClE,WAAW,CAAC,yBAAyB,CAAC;gBAClC,IAAI,EAAE,IAAI,gBAAgB,QAAQ;gBAClC,IAAI,EAAE,wBAAa,CAAC,kBAAkB;gBACtC,WAAW,EAAE;;sCAES,gBAAgB;;;;uBAI/B;aACV,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,WAAW,CAAC,SAAS,CAAC,SAAS,EAAE,qCAAqC,CAAC,CAAC;IAExE,aAAa,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAE9C,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACrB,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;IAEzB,MAAM,SAAS,GAAG;QACd,6CAA6C;QAC7C,sCAAsC;QACtC,0BAA0B;KAC7B,CAAC;IACF,IAAA,cAAI,EAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE3B,OAAO;QACH,OAAO;QACP,mBAAmB,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC;KAChD,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Directory, ObjectLiteralExpression, PropertyAssignmentStructure, SourceFile } from 'ts-morph';
|
|
2
|
+
export declare class CodegenConfigRef {
|
|
3
|
+
private readonly tempProject;
|
|
4
|
+
readonly sourceFile: SourceFile;
|
|
5
|
+
private configObject;
|
|
6
|
+
constructor(rootDir: Directory);
|
|
7
|
+
addEntryToGeneratesObject(structure: PropertyAssignmentStructure): void;
|
|
8
|
+
getConfigObject(): ObjectLiteralExpression;
|
|
9
|
+
save(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CodegenConfigRef = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ts_morph_1 = require("ts-morph");
|
|
10
|
+
const ast_utils_1 = require("../../../utilities/ast-utils");
|
|
11
|
+
class CodegenConfigRef {
|
|
12
|
+
constructor(rootDir) {
|
|
13
|
+
this.tempProject = (0, ast_utils_1.getTsMorphProject)({ skipAddingFilesFromTsConfig: true });
|
|
14
|
+
const codegenFilePath = path_1.default.join(rootDir.getPath(), 'codegen.ts');
|
|
15
|
+
if (fs_extra_1.default.existsSync(codegenFilePath)) {
|
|
16
|
+
this.sourceFile = this.tempProject.addSourceFileAtPath(codegenFilePath);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.sourceFile = (0, ast_utils_1.createFile)(this.tempProject, path_1.default.join(__dirname, 'templates/codegen.template.ts'));
|
|
20
|
+
this.sourceFile.move(path_1.default.join(rootDir.getPath(), 'codegen.ts'));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
addEntryToGeneratesObject(structure) {
|
|
24
|
+
var _a;
|
|
25
|
+
const generatesProp = (_a = this.getConfigObject()
|
|
26
|
+
.getProperty('generates')) === null || _a === void 0 ? void 0 : _a.getFirstChildByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
27
|
+
if (!generatesProp) {
|
|
28
|
+
throw new Error('Could not find the generates property in the template codegen file');
|
|
29
|
+
}
|
|
30
|
+
if (generatesProp.getProperty(structure.name)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
generatesProp.addProperty(structure).formatText();
|
|
34
|
+
}
|
|
35
|
+
getConfigObject() {
|
|
36
|
+
var _a;
|
|
37
|
+
if (this.configObject) {
|
|
38
|
+
return this.configObject;
|
|
39
|
+
}
|
|
40
|
+
const codegenConfig = (_a = this.sourceFile
|
|
41
|
+
.getVariableDeclaration('config')) === null || _a === void 0 ? void 0 : _a.getChildrenOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0];
|
|
42
|
+
if (!codegenConfig) {
|
|
43
|
+
throw new Error('Could not find the config variable in the template codegen file');
|
|
44
|
+
}
|
|
45
|
+
this.configObject = codegenConfig;
|
|
46
|
+
return this.configObject;
|
|
47
|
+
}
|
|
48
|
+
save() {
|
|
49
|
+
return this.tempProject.save();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CodegenConfigRef = CodegenConfigRef;
|
|
53
|
+
//# sourceMappingURL=codegen-config-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-config-ref.js","sourceRoot":"","sources":["../../../../src/commands/add/codegen/codegen-config-ref.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,uCAQkB;AAElB,4DAA6E;AAE7E,MAAa,gBAAgB;IAIzB,YAAY,OAAkB;QAC1B,IAAI,CAAC,WAAW,GAAG,IAAA,6BAAiB,EAAC,EAAE,2BAA2B,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5E,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;QACnE,IAAI,kBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;QAC5E,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,UAAU,GAAG,IAAA,sBAAU,EACxB,IAAI,CAAC,WAAW,EAChB,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,+BAA+B,CAAC,CACxD,CAAC;YACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;QACrE,CAAC;IACL,CAAC;IAED,yBAAyB,CAAC,SAAsC;;QAC5D,MAAM,aAAa,GAAG,MAAA,IAAI,CAAC,eAAe,EAAE;aACvC,WAAW,CAAC,WAAW,CAAC,0CACvB,mBAAmB,CAAC,qBAAU,CAAC,uBAAuB,CAAC,CAAC;QAC9D,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;QAC1F,CAAC;QACD,IAAI,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5C,OAAO;QACX,CAAC;QACD,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;IACtD,CAAC;IAED,eAAe;;QACX,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,YAAY,CAAC;QAC7B,CAAC;QACD,MAAM,aAAa,GAAG,MAAA,IAAI,CAAC,UAAU;aAChC,sBAAsB,CAAC,QAAQ,CAAC,0CAC/B,iBAAiB,CAAC,qBAAU,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;QACvF,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC;QAClC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;CACJ;AAhDD,4CAgDC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
2
|
+
|
|
3
|
+
const config: CodegenConfig = {
|
|
4
|
+
overwrite: true,
|
|
5
|
+
// This assumes your server is running on the standard port
|
|
6
|
+
// and with the default admin API path. Adjust accordingly.
|
|
7
|
+
schema: 'http://localhost:3000/admin-api',
|
|
8
|
+
config: {
|
|
9
|
+
// This tells codegen that the `Money` scalar is a number
|
|
10
|
+
scalars: { Money: 'number' },
|
|
11
|
+
// This ensures generated enums do not conflict with the built-in types.
|
|
12
|
+
namingConvention: { enumValues: 'keep' },
|
|
13
|
+
},
|
|
14
|
+
generates: {},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default config;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { CliCommand, CliCommandReturnVal } from '../../../shared/cli-command';
|
|
2
|
+
import { EntityRef } from '../../../shared/entity-ref';
|
|
3
|
+
import { VendurePluginRef } from '../../../shared/vendure-plugin-ref';
|
|
4
|
+
export interface AddEntityOptions {
|
|
5
|
+
plugin?: VendurePluginRef;
|
|
6
|
+
className: string;
|
|
7
|
+
fileName: string;
|
|
8
|
+
translationFileName: string;
|
|
9
|
+
features: {
|
|
10
|
+
customFields: boolean;
|
|
11
|
+
translatable: boolean;
|
|
5
12
|
};
|
|
6
13
|
}
|
|
7
|
-
export declare
|
|
14
|
+
export declare const addEntityCommand: CliCommand<Record<string, any>, CliCommandReturnVal<{
|
|
15
|
+
entityRef: EntityRef;
|
|
16
|
+
}>>;
|
|
17
|
+
export declare function getCustomEntityName(_cancelledMessage: string): Promise<string>;
|
|
@@ -3,37 +3,144 @@ 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.getCustomEntityName = exports.addEntityCommand = void 0;
|
|
7
7
|
const prompts_1 = require("@clack/prompts");
|
|
8
8
|
const change_case_1 = require("change-case");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const constants_1 = require("../../../constants");
|
|
11
|
+
const cli_command_1 = require("../../../shared/cli-command");
|
|
12
|
+
const entity_ref_1 = require("../../../shared/entity-ref");
|
|
10
13
|
const shared_prompts_1 = require("../../../shared/shared-prompts");
|
|
11
14
|
const ast_utils_1 = require("../../../utilities/ast-utils");
|
|
15
|
+
const utils_1 = require("../../../utilities/utils");
|
|
12
16
|
const add_entity_to_plugin_1 = require("./codemods/add-entity-to-plugin/add-entity-to-plugin");
|
|
13
17
|
const cancelledMessage = 'Add entity cancelled';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
exports.addEntityCommand = new cli_command_1.CliCommand({
|
|
19
|
+
id: 'add-entity',
|
|
20
|
+
category: 'Plugin: Entity',
|
|
21
|
+
description: 'Add a new entity to a plugin',
|
|
22
|
+
run: options => addEntity(options),
|
|
23
|
+
});
|
|
24
|
+
async function addEntity(options) {
|
|
25
|
+
var _a;
|
|
26
|
+
const providedVendurePlugin = options === null || options === void 0 ? void 0 : options.plugin;
|
|
27
|
+
const project = await (0, shared_prompts_1.analyzeProject)({ providedVendurePlugin, cancelledMessage });
|
|
28
|
+
const vendurePlugin = providedVendurePlugin !== null && providedVendurePlugin !== void 0 ? providedVendurePlugin : (await (0, shared_prompts_1.selectPlugin)(project, cancelledMessage));
|
|
29
|
+
const modifiedSourceFiles = [];
|
|
30
|
+
const customEntityName = (_a = options === null || options === void 0 ? void 0 : options.className) !== null && _a !== void 0 ? _a : (await getCustomEntityName(cancelledMessage));
|
|
22
31
|
const context = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
className: customEntityName,
|
|
33
|
+
fileName: (0, change_case_1.paramCase)(customEntityName) + '.entity',
|
|
34
|
+
translationFileName: (0, change_case_1.paramCase)(customEntityName) + '-translation.entity',
|
|
35
|
+
features: await getFeatures(options),
|
|
36
|
+
};
|
|
37
|
+
const entitySpinner = (0, prompts_1.spinner)();
|
|
38
|
+
entitySpinner.start('Creating entity...');
|
|
39
|
+
await (0, utils_1.pauseForPromptDisplay)();
|
|
40
|
+
const { entityClass, translationClass } = createEntity(vendurePlugin, context);
|
|
41
|
+
(0, add_entity_to_plugin_1.addEntityToPlugin)(vendurePlugin, entityClass);
|
|
42
|
+
modifiedSourceFiles.push(entityClass.getSourceFile());
|
|
43
|
+
if (context.features.translatable) {
|
|
44
|
+
(0, add_entity_to_plugin_1.addEntityToPlugin)(vendurePlugin, translationClass);
|
|
45
|
+
modifiedSourceFiles.push(translationClass.getSourceFile());
|
|
46
|
+
}
|
|
47
|
+
entitySpinner.stop('Entity created');
|
|
48
|
+
await project.save();
|
|
49
|
+
return {
|
|
50
|
+
project,
|
|
51
|
+
modifiedSourceFiles,
|
|
52
|
+
entityRef: new entity_ref_1.EntityRef(entityClass),
|
|
27
53
|
};
|
|
28
|
-
const entitiesDir = path_1.default.join(pluginClass.getSourceFile().getDirectory().getPath(), 'entities');
|
|
29
|
-
const entityTemplatePath = path_1.default.join(__dirname, 'templates/entity.template.ts');
|
|
30
|
-
const entityFile = (0, ast_utils_1.createSourceFileFromTemplate)(project, entityTemplatePath);
|
|
31
|
-
entityFile.move(path_1.default.join(entitiesDir, `${context.entity.fileName}.ts`));
|
|
32
|
-
entityFile.getClasses()[0].rename(`${context.entity.className}CustomFields`);
|
|
33
|
-
entityFile.getClasses()[1].rename(context.entity.className);
|
|
34
|
-
(0, add_entity_to_plugin_1.addEntityToPlugin)(pluginClass, entityFile);
|
|
35
|
-
project.saveSync();
|
|
36
|
-
(0, prompts_1.outro)('✅ Done!');
|
|
37
54
|
}
|
|
38
|
-
|
|
55
|
+
async function getFeatures(options) {
|
|
56
|
+
if (options === null || options === void 0 ? void 0 : options.features) {
|
|
57
|
+
return options === null || options === void 0 ? void 0 : options.features;
|
|
58
|
+
}
|
|
59
|
+
const features = await (0, prompts_1.multiselect)({
|
|
60
|
+
message: 'Entity features (use ↑, ↓, space to select)',
|
|
61
|
+
required: false,
|
|
62
|
+
initialValues: ['customFields'],
|
|
63
|
+
options: [
|
|
64
|
+
{
|
|
65
|
+
label: 'Custom fields',
|
|
66
|
+
value: 'customFields',
|
|
67
|
+
hint: 'Adds support for custom fields on this entity',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: 'Translatable',
|
|
71
|
+
value: 'translatable',
|
|
72
|
+
hint: 'Adds support for localized properties on this entity',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
if ((0, prompts_1.isCancel)(features)) {
|
|
77
|
+
(0, prompts_1.cancel)(cancelledMessage);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
customFields: features.includes('customFields'),
|
|
82
|
+
translatable: features.includes('translatable'),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function createEntity(plugin, options) {
|
|
86
|
+
var _a, _b, _c, _d, _e, _f;
|
|
87
|
+
const entitiesDir = path_1.default.join(plugin.getPluginDir().getPath(), 'entities');
|
|
88
|
+
const entityFile = (0, ast_utils_1.createFile)(plugin.getSourceFile().getProject(), path_1.default.join(__dirname, 'templates/entity.template.ts'));
|
|
89
|
+
const translationFile = (0, ast_utils_1.createFile)(plugin.getSourceFile().getProject(), path_1.default.join(__dirname, 'templates/entity-translation.template.ts'));
|
|
90
|
+
entityFile.move(path_1.default.join(entitiesDir, `${options.fileName}.ts`));
|
|
91
|
+
translationFile.move(path_1.default.join(entitiesDir, `${options.translationFileName}.ts`));
|
|
92
|
+
const entityClass = (_a = entityFile.getClass('ScaffoldEntity')) === null || _a === void 0 ? void 0 : _a.rename(options.className);
|
|
93
|
+
const customFieldsClass = (_b = entityFile
|
|
94
|
+
.getClass('ScaffoldEntityCustomFields')) === null || _b === void 0 ? void 0 : _b.rename(`${options.className}CustomFields`);
|
|
95
|
+
const translationClass = (_c = translationFile
|
|
96
|
+
.getClass('ScaffoldTranslation')) === null || _c === void 0 ? void 0 : _c.rename(`${options.className}Translation`);
|
|
97
|
+
const translationCustomFieldsClass = (_d = translationFile
|
|
98
|
+
.getClass('ScaffoldEntityCustomFieldsTranslation')) === null || _d === void 0 ? void 0 : _d.rename(`${options.className}CustomFieldsTranslation`);
|
|
99
|
+
if (!options.features.customFields) {
|
|
100
|
+
customFieldsClass === null || customFieldsClass === void 0 ? void 0 : customFieldsClass.remove();
|
|
101
|
+
translationCustomFieldsClass === null || translationCustomFieldsClass === void 0 ? void 0 : translationCustomFieldsClass.remove();
|
|
102
|
+
removeCustomFieldsFromClass(entityClass);
|
|
103
|
+
removeCustomFieldsFromClass(translationClass);
|
|
104
|
+
}
|
|
105
|
+
if (!options.features.translatable) {
|
|
106
|
+
translationClass === null || translationClass === void 0 ? void 0 : translationClass.remove();
|
|
107
|
+
(_e = entityClass === null || entityClass === void 0 ? void 0 : entityClass.getProperty('localizedName')) === null || _e === void 0 ? void 0 : _e.remove();
|
|
108
|
+
(_f = entityClass === null || entityClass === void 0 ? void 0 : entityClass.getProperty('translations')) === null || _f === void 0 ? void 0 : _f.remove();
|
|
109
|
+
removeImplementsFromClass('Translatable', entityClass);
|
|
110
|
+
translationFile.delete();
|
|
111
|
+
}
|
|
112
|
+
return { entityClass: entityClass, translationClass: translationClass };
|
|
113
|
+
}
|
|
114
|
+
function removeCustomFieldsFromClass(entityClass) {
|
|
115
|
+
var _a;
|
|
116
|
+
(_a = entityClass === null || entityClass === void 0 ? void 0 : entityClass.getProperty('customFields')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
117
|
+
removeImplementsFromClass('HasCustomFields', entityClass);
|
|
118
|
+
}
|
|
119
|
+
function removeImplementsFromClass(implementsName, entityClass) {
|
|
120
|
+
var _a;
|
|
121
|
+
const index = (_a = entityClass === null || entityClass === void 0 ? void 0 : entityClass.getImplements().findIndex(i => i.getText() === implementsName)) !== null && _a !== void 0 ? _a : -1;
|
|
122
|
+
if (index > -1) {
|
|
123
|
+
entityClass === null || entityClass === void 0 ? void 0 : entityClass.removeImplements(index);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function getCustomEntityName(_cancelledMessage) {
|
|
127
|
+
const entityName = await (0, prompts_1.text)({
|
|
128
|
+
message: 'What is the name of the custom entity?',
|
|
129
|
+
initialValue: '',
|
|
130
|
+
validate: input => {
|
|
131
|
+
if (!input) {
|
|
132
|
+
return 'The custom entity name cannot be empty';
|
|
133
|
+
}
|
|
134
|
+
if (!constants_1.pascalCaseRegex.test(input)) {
|
|
135
|
+
return 'The custom entity name must be in PascalCase, e.g. "ProductReview"';
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if ((0, prompts_1.isCancel)(entityName)) {
|
|
140
|
+
(0, prompts_1.cancel)(_cancelledMessage);
|
|
141
|
+
process.exit(0);
|
|
142
|
+
}
|
|
143
|
+
return (0, change_case_1.pascalCase)(entityName);
|
|
144
|
+
}
|
|
145
|
+
exports.getCustomEntityName = getCustomEntityName;
|
|
39
146
|
//# sourceMappingURL=add-entity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-entity.js","sourceRoot":"","sources":["../../../../src/commands/add/entity/add-entity.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"add-entity.js","sourceRoot":"","sources":["../../../../src/commands/add/entity/add-entity.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA8E;AAC9E,6CAAoD;AACpD,gDAAwB;AAGxB,kDAAqD;AACrD,6DAA8E;AAC9E,2DAAuD;AACvD,mEAA8E;AAE9E,4DAA0D;AAC1D,oDAAiE;AAEjE,+FAAyF;AAEzF,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAanC,QAAA,gBAAgB,GAAG,IAAI,wBAAU,CAAC;IAC3C,EAAE,EAAE,YAAY;IAChB,QAAQ,EAAE,gBAAgB;IAC1B,WAAW,EAAE,8BAA8B;IAC3C,GAAG,EAAE,OAAO,CAAC,EAAE,CA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,CAAC,CAAC,EAAE,CAAC;QACb,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,iBAAyB;IAC/D,MAAM,UAAU,GAAG,MAAM,IAAA,cAAI,EAAC;QAC1B,OAAO,EAAE,wCAAwC;QACjD,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,KAAK,CAAC,EAAE;YACd,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,OAAO,wCAAwC,CAAC;YACpD,CAAC;YACD,IAAI,CAAC,2BAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/B,OAAO,oEAAoE,CAAC;YAChF,CAAC;QACL,CAAC;KACJ,CAAC,CAAC;IACH,IAAI,IAAA,kBAAQ,EAAC,UAAU,CAAC,EAAE,CAAC;QACvB,IAAA,gBAAM,EAAC,iBAAiB,CAAC,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,IAAA,wBAAU,EAAC,UAAU,CAAC,CAAC;AAClC,CAAC;AAlBD,kDAkBC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { ClassDeclaration
|
|
2
|
-
|
|
1
|
+
import { ClassDeclaration } from 'ts-morph';
|
|
2
|
+
import { VendurePluginRef } from '../../../../../shared/vendure-plugin-ref';
|
|
3
|
+
export declare function addEntityToPlugin(plugin: VendurePluginRef, entityClass: ClassDeclaration): void;
|
|
@@ -1,38 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addEntityToPlugin = void 0;
|
|
4
|
-
const ts_morph_1 = require("ts-morph");
|
|
5
4
|
const ast_utils_1 = require("../../../../../utilities/ast-utils");
|
|
6
|
-
function addEntityToPlugin(
|
|
7
|
-
const pluginDecorator = pluginClass.getDecorator('VendurePlugin');
|
|
8
|
-
if (!pluginDecorator) {
|
|
9
|
-
throw new Error('Could not find VendurePlugin decorator');
|
|
10
|
-
}
|
|
11
|
-
const pluginOptions = pluginDecorator.getArguments()[0];
|
|
12
|
-
if (!pluginOptions) {
|
|
13
|
-
throw new Error('Could not find VendurePlugin options');
|
|
14
|
-
}
|
|
15
|
-
const entityClass = entitySourceFile.getClasses().find(c => { var _a; return !((_a = c.getName()) === null || _a === void 0 ? void 0 : _a.includes('CustomFields')); });
|
|
5
|
+
function addEntityToPlugin(plugin, entityClass) {
|
|
16
6
|
if (!entityClass) {
|
|
17
7
|
throw new Error('Could not find entity class');
|
|
18
8
|
}
|
|
19
9
|
const entityClassName = entityClass.getName();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (entityProperty) {
|
|
23
|
-
const entitiesArray = entityProperty.getFirstChildByKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
24
|
-
if (entitiesArray) {
|
|
25
|
-
entitiesArray.addElement(entityClassName);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
pluginOptions.addPropertyAssignment({
|
|
30
|
-
name: 'entities',
|
|
31
|
-
initializer: `[${entityClassName}]`,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
(0, ast_utils_1.addImportsToFile)(pluginClass.getSourceFile(), {
|
|
10
|
+
plugin.addEntity(entityClassName);
|
|
11
|
+
(0, ast_utils_1.addImportsToFile)(plugin.classDeclaration.getSourceFile(), {
|
|
36
12
|
moduleSpecifier: entityClass.getSourceFile(),
|
|
37
13
|
namedImports: [entityClassName],
|
|
38
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-entity-to-plugin.js","sourceRoot":"","sources":["../../../../../../src/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"add-entity-to-plugin.js","sourceRoot":"","sources":["../../../../../../src/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.ts"],"names":[],"mappings":";;;AAGA,kEAAsE;AAEtE,SAAgB,iBAAiB,CAAC,MAAwB,EAAE,WAA6B;IACrF,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,EAAY,CAAC;IACxD,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAElC,IAAA,4BAAgB,EAAC,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,EAAE;QACtD,eAAe,EAAE,WAAW,CAAC,aAAa,EAAE;QAC5C,YAAY,EAAE,CAAC,eAAe,CAAC;KAClC,CAAC,CAAC;AACP,CAAC;AAXD,8CAWC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
2
|
+
import { DeepPartial } from '@vendure/common/lib/shared-types';
|
|
3
|
+
import { HasCustomFields, Translation, VendureEntity } from '@vendure/core';
|
|
4
|
+
import { Column, Entity, Index, ManyToOne } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
import { ScaffoldEntity } from './entity.template';
|
|
7
|
+
|
|
8
|
+
export class ScaffoldEntityCustomFieldsTranslation {}
|
|
9
|
+
|
|
10
|
+
@Entity()
|
|
11
|
+
export class ScaffoldTranslation
|
|
12
|
+
extends VendureEntity
|
|
13
|
+
implements Translation<ScaffoldEntity>, HasCustomFields
|
|
14
|
+
{
|
|
15
|
+
constructor(input?: DeepPartial<Translation<ScaffoldTranslation>>) {
|
|
16
|
+
super(input);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Column('varchar') languageCode: LanguageCode;
|
|
20
|
+
|
|
21
|
+
@Column() localizedName: string;
|
|
22
|
+
|
|
23
|
+
@Index()
|
|
24
|
+
@ManyToOne(type => ScaffoldEntity, base => base.translations, { onDelete: 'CASCADE' })
|
|
25
|
+
base: ScaffoldEntity;
|
|
26
|
+
|
|
27
|
+
@Column(type => ScaffoldEntityCustomFieldsTranslation)
|
|
28
|
+
customFields: ScaffoldEntityCustomFieldsTranslation;
|
|
29
|
+
}
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
DeepPartial,
|
|
3
|
+
HasCustomFields,
|
|
4
|
+
LocaleString,
|
|
5
|
+
Translatable,
|
|
6
|
+
Translation,
|
|
7
|
+
VendureEntity,
|
|
8
|
+
} from '@vendure/core';
|
|
9
|
+
import { Column, Entity, OneToMany } from 'typeorm';
|
|
10
|
+
|
|
11
|
+
import { ScaffoldTranslation } from './entity-translation.template';
|
|
3
12
|
|
|
4
13
|
export class ScaffoldEntityCustomFields {}
|
|
5
14
|
|
|
6
15
|
@Entity()
|
|
7
|
-
export class ScaffoldEntity extends VendureEntity implements HasCustomFields {
|
|
16
|
+
export class ScaffoldEntity extends VendureEntity implements Translatable, HasCustomFields {
|
|
8
17
|
constructor(input?: DeepPartial<ScaffoldEntity>) {
|
|
9
18
|
super(input);
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
@Column()
|
|
13
|
-
|
|
22
|
+
code: string;
|
|
14
23
|
|
|
15
24
|
@Column(type => ScaffoldEntityCustomFields)
|
|
16
25
|
customFields: ScaffoldEntityCustomFields;
|
|
26
|
+
|
|
27
|
+
localizedName: LocaleString;
|
|
28
|
+
|
|
29
|
+
@OneToMany(type => ScaffoldTranslation, translation => translation.base, { eager: true })
|
|
30
|
+
translations: Array<Translation<ScaffoldEntity>>;
|
|
17
31
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CliCommand, CliCommandReturnVal } from '../../../shared/cli-command';
|
|
2
|
+
import { ServiceRef } from '../../../shared/service-ref';
|
|
3
|
+
import { VendurePluginRef } from '../../../shared/vendure-plugin-ref';
|
|
4
|
+
export interface AddJobQueueOptions {
|
|
5
|
+
plugin?: VendurePluginRef;
|
|
6
|
+
}
|
|
7
|
+
export declare const addJobQueueCommand: CliCommand<Record<string, any>, CliCommandReturnVal<{
|
|
8
|
+
serviceRef: ServiceRef;
|
|
9
|
+
}>>;
|