@vendure/ui-devkit 2.2.0-next.3 → 2.2.0-next.4

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.
@@ -1,50 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setBranding = void 0;
4
- /**
5
- * @description
6
- * A helper function to simplify the process of setting custom branding images.
7
- *
8
- * @example
9
- * ```ts
10
- * compileUiExtensions({
11
- * outputPath: path.join(__dirname, '../admin-ui'),
12
- * extensions: [
13
- * setBranding({
14
- * // This is used as the branding in the top-left above the navigation
15
- * smallLogoPath: path.join(__dirname, 'images/my-logo-sm.png'),
16
- * // This is used on the login page
17
- * largeLogoPath: path.join(__dirname, 'images/my-logo-lg.png'),
18
- * faviconPath: path.join(__dirname, 'images/my-favicon.ico'),
19
- * }),
20
- * ],
21
- * });
22
- * ```
23
- *
24
- * @docsCategory UiDevkit
25
- * @docsPage helpers
26
- */
27
- function setBranding(options) {
28
- const staticAssets = [];
29
- if (options.smallLogoPath) {
30
- staticAssets.push({
31
- path: options.smallLogoPath,
32
- rename: 'logo-top.webp',
33
- });
34
- }
35
- if (options.largeLogoPath) {
36
- staticAssets.push({
37
- path: options.largeLogoPath,
38
- rename: 'logo-login.webp',
39
- });
40
- }
41
- if (options.faviconPath) {
42
- staticAssets.push({
43
- path: options.faviconPath,
44
- rename: 'favicon.ico',
45
- });
46
- }
47
- return { staticAssets };
48
- }
49
- exports.setBranding = setBranding;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setBranding = void 0;
4
+ /**
5
+ * @description
6
+ * A helper function to simplify the process of setting custom branding images.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * compileUiExtensions({
11
+ * outputPath: path.join(__dirname, '../admin-ui'),
12
+ * extensions: [
13
+ * setBranding({
14
+ * // This is used as the branding in the top-left above the navigation
15
+ * smallLogoPath: path.join(__dirname, 'images/my-logo-sm.png'),
16
+ * // This is used on the login page
17
+ * largeLogoPath: path.join(__dirname, 'images/my-logo-lg.png'),
18
+ * faviconPath: path.join(__dirname, 'images/my-favicon.ico'),
19
+ * }),
20
+ * ],
21
+ * });
22
+ * ```
23
+ *
24
+ * @docsCategory UiDevkit
25
+ * @docsPage helpers
26
+ */
27
+ function setBranding(options) {
28
+ const staticAssets = [];
29
+ if (options.smallLogoPath) {
30
+ staticAssets.push({
31
+ path: options.smallLogoPath,
32
+ rename: 'logo-top.webp',
33
+ });
34
+ }
35
+ if (options.largeLogoPath) {
36
+ staticAssets.push({
37
+ path: options.largeLogoPath,
38
+ rename: 'logo-login.webp',
39
+ });
40
+ }
41
+ if (options.faviconPath) {
42
+ staticAssets.push({
43
+ path: options.faviconPath,
44
+ rename: 'favicon.ico',
45
+ });
46
+ }
47
+ return { staticAssets };
48
+ }
49
+ exports.setBranding = setBranding;
50
50
  //# sourceMappingURL=helpers.js.map
@@ -1,3 +1,3 @@
1
- export * from './compile';
2
- export * from './helpers';
3
- export * from './types';
1
+ export * from './compile';
2
+ export * from './helpers';
3
+ export * from './types';
package/compiler/index.js CHANGED
@@ -1,20 +1,20 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./compile"), exports);
18
- __exportStar(require("./helpers"), exports);
19
- __exportStar(require("./types"), exports);
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compile"), exports);
18
+ __exportStar(require("./helpers"), exports);
19
+ __exportStar(require("./types"), exports);
20
20
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { Extension } from './types';
2
- export declare function setupScaffold(outputPath: string, extensions: Extension[]): Promise<void>;
3
- export declare function copyGlobalStyleFile(outputPath: string, stylePath: string): Promise<void>;
4
- export declare function setBaseHref(outputPath: string, baseHref: string): Promise<void>;
1
+ import { Extension } from './types';
2
+ export declare function setupScaffold(outputPath: string, extensions: Extension[]): Promise<void>;
3
+ export declare function copyGlobalStyleFile(outputPath: string, stylePath: string): Promise<void>;
4
+ export declare function setBaseHref(outputPath: string, baseHref: string): Promise<void>;
@@ -1,193 +1,193 @@
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.setBaseHref = exports.copyGlobalStyleFile = exports.setupScaffold = void 0;
27
- /* eslint-disable no-console */
28
- const shared_utils_1 = require("@vendure/common/lib/shared-utils");
29
- const fs = __importStar(require("fs-extra"));
30
- const glob_1 = require("glob");
31
- const path = __importStar(require("path"));
32
- const constants_1 = require("./constants");
33
- const translations_1 = require("./translations");
34
- const utils_1 = require("./utils");
35
- async function setupScaffold(outputPath, extensions) {
36
- deleteExistingExtensionModules(outputPath);
37
- const adminUiExtensions = extensions.filter((e) => (0, utils_1.isAdminUiExtension)(e));
38
- const normalizedExtensions = (0, utils_1.normalizeExtensions)(adminUiExtensions);
39
- const modulePathMapping = generateModulePathMapping(normalizedExtensions);
40
- copyAdminUiSource(outputPath, modulePathMapping);
41
- await copyExtensionModules(outputPath, normalizedExtensions);
42
- const staticAssetExtensions = extensions.filter(utils_1.isStaticAssetExtension);
43
- await copyStaticAssets(outputPath, staticAssetExtensions);
44
- const globalStyleExtensions = extensions.filter(utils_1.isGlobalStylesExtension);
45
- const sassVariableOverridesExtension = extensions.find(utils_1.isSassVariableOverridesExtension);
46
- await addGlobalStyles(outputPath, globalStyleExtensions, sassVariableOverridesExtension);
47
- const allTranslationFiles = (0, translations_1.getAllTranslationFiles)(extensions.filter(utils_1.isTranslationExtension));
48
- await (0, translations_1.mergeExtensionTranslations)(outputPath, allTranslationFiles);
49
- (0, utils_1.copyUiDevkit)(outputPath);
50
- }
51
- exports.setupScaffold = setupScaffold;
52
- /**
53
- * Deletes the contents of the /modules directory, which contains the plugin
54
- * extension modules copied over during the last compilation.
55
- */
56
- function deleteExistingExtensionModules(outputPath) {
57
- fs.removeSync(path.join(outputPath, constants_1.MODULES_OUTPUT_DIR));
58
- }
59
- /**
60
- * Generates a module path mapping object for all extensions with a "pathAlias"
61
- * property declared (if any).
62
- */
63
- function generateModulePathMapping(extensions) {
64
- const extensionsWithAlias = extensions.filter(e => e.pathAlias);
65
- if (extensionsWithAlias.length === 0) {
66
- return undefined;
67
- }
68
- return extensionsWithAlias.reduce((acc, e) => {
69
- // for imports from the index file if there is one
70
- acc[e.pathAlias] = [`src/extensions/${e.id}`];
71
- // direct access to files / deep imports
72
- acc[`${e.pathAlias}/*`] = [`src/extensions/${e.id}/*`];
73
- return acc;
74
- }, {});
75
- }
76
- /**
77
- * Copies all files from the extensionPaths of the configured extensions into the
78
- * admin-ui source tree.
79
- */
80
- async function copyExtensionModules(outputPath, extensions) {
81
- const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
82
- const extensionRoutesSource = generateLazyExtensionRoutes(adminUiExtensions);
83
- fs.writeFileSync(path.join(outputPath, constants_1.EXTENSION_ROUTES_FILE), extensionRoutesSource, 'utf8');
84
- const sharedExtensionModulesSource = generateSharedExtensionModule(extensions);
85
- fs.writeFileSync(path.join(outputPath, constants_1.SHARED_EXTENSIONS_FILE), sharedExtensionModulesSource, 'utf8');
86
- for (const extension of adminUiExtensions) {
87
- if (!extension.extensionPath) {
88
- continue;
89
- }
90
- const dest = path.join(outputPath, constants_1.MODULES_OUTPUT_DIR, extension.id);
91
- if (!extension.exclude) {
92
- fs.copySync(extension.extensionPath, dest);
93
- continue;
94
- }
95
- const exclude = extension.exclude?.map(e => (0, glob_1.globSync)(path.join(extension.extensionPath, e))).flatMap(e => e) ??
96
- [];
97
- fs.copySync(extension.extensionPath, dest, {
98
- filter: name => name === extension.extensionPath || exclude.every(e => e !== name),
99
- });
100
- }
101
- }
102
- async function copyStaticAssets(outputPath, extensions) {
103
- for (const extension of extensions) {
104
- if (Array.isArray(extension.staticAssets)) {
105
- for (const asset of extension.staticAssets) {
106
- await (0, utils_1.copyStaticAsset)(outputPath, asset);
107
- }
108
- }
109
- }
110
- }
111
- async function addGlobalStyles(outputPath, globalStylesExtensions, sassVariableOverridesExtension) {
112
- const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
113
- await fs.remove(globalStylesDir);
114
- await fs.ensureDir(globalStylesDir);
115
- const imports = [];
116
- for (const extension of globalStylesExtensions) {
117
- const styleFiles = Array.isArray(extension.globalStyles)
118
- ? extension.globalStyles
119
- : [extension.globalStyles];
120
- for (const styleFile of styleFiles) {
121
- await copyGlobalStyleFile(outputPath, styleFile);
122
- imports.push(path.basename(styleFile, path.extname(styleFile)));
123
- }
124
- }
125
- let overridesImport = '';
126
- if (sassVariableOverridesExtension) {
127
- const overridesFile = sassVariableOverridesExtension.sassVariableOverrides;
128
- await copyGlobalStyleFile(outputPath, overridesFile);
129
- overridesImport = `@import "./${constants_1.GLOBAL_STYLES_OUTPUT_DIR}/${path.basename(overridesFile, path.extname(overridesFile))}";\n`;
130
- }
131
- const globalStylesSource = overridesImport +
132
- '@import "./styles/styles";\n' +
133
- imports.map(file => `@import "./${constants_1.GLOBAL_STYLES_OUTPUT_DIR}/${file}";`).join('\n');
134
- const globalStylesFile = path.join(outputPath, 'src', 'global-styles.scss');
135
- await fs.writeFile(globalStylesFile, globalStylesSource, 'utf-8');
136
- }
137
- async function copyGlobalStyleFile(outputPath, stylePath) {
138
- const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
139
- const fileBasename = path.basename(stylePath);
140
- const styleOutputPath = path.join(globalStylesDir, fileBasename);
141
- await fs.copyFile(stylePath, styleOutputPath);
142
- }
143
- exports.copyGlobalStyleFile = copyGlobalStyleFile;
144
- function generateLazyExtensionRoutes(extensions) {
145
- const routes = [];
146
- for (const extension of extensions) {
147
- for (const module of extension.ngModules ?? []) {
148
- if (module.type === 'lazy') {
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.setBaseHref = exports.copyGlobalStyleFile = exports.setupScaffold = void 0;
27
+ /* eslint-disable no-console */
28
+ const shared_utils_1 = require("@vendure/common/lib/shared-utils");
29
+ const fs = __importStar(require("fs-extra"));
30
+ const glob_1 = require("glob");
31
+ const path = __importStar(require("path"));
32
+ const constants_1 = require("./constants");
33
+ const translations_1 = require("./translations");
34
+ const utils_1 = require("./utils");
35
+ async function setupScaffold(outputPath, extensions) {
36
+ deleteExistingExtensionModules(outputPath);
37
+ const adminUiExtensions = extensions.filter((e) => (0, utils_1.isAdminUiExtension)(e));
38
+ const normalizedExtensions = (0, utils_1.normalizeExtensions)(adminUiExtensions);
39
+ const modulePathMapping = generateModulePathMapping(normalizedExtensions);
40
+ copyAdminUiSource(outputPath, modulePathMapping);
41
+ await copyExtensionModules(outputPath, normalizedExtensions);
42
+ const staticAssetExtensions = extensions.filter(utils_1.isStaticAssetExtension);
43
+ await copyStaticAssets(outputPath, staticAssetExtensions);
44
+ const globalStyleExtensions = extensions.filter(utils_1.isGlobalStylesExtension);
45
+ const sassVariableOverridesExtension = extensions.find(utils_1.isSassVariableOverridesExtension);
46
+ await addGlobalStyles(outputPath, globalStyleExtensions, sassVariableOverridesExtension);
47
+ const allTranslationFiles = (0, translations_1.getAllTranslationFiles)(extensions.filter(utils_1.isTranslationExtension));
48
+ await (0, translations_1.mergeExtensionTranslations)(outputPath, allTranslationFiles);
49
+ (0, utils_1.copyUiDevkit)(outputPath);
50
+ }
51
+ exports.setupScaffold = setupScaffold;
52
+ /**
53
+ * Deletes the contents of the /modules directory, which contains the plugin
54
+ * extension modules copied over during the last compilation.
55
+ */
56
+ function deleteExistingExtensionModules(outputPath) {
57
+ fs.removeSync(path.join(outputPath, constants_1.MODULES_OUTPUT_DIR));
58
+ }
59
+ /**
60
+ * Generates a module path mapping object for all extensions with a "pathAlias"
61
+ * property declared (if any).
62
+ */
63
+ function generateModulePathMapping(extensions) {
64
+ const extensionsWithAlias = extensions.filter(e => e.pathAlias);
65
+ if (extensionsWithAlias.length === 0) {
66
+ return undefined;
67
+ }
68
+ return extensionsWithAlias.reduce((acc, e) => {
69
+ // for imports from the index file if there is one
70
+ acc[e.pathAlias] = [`src/extensions/${e.id}`];
71
+ // direct access to files / deep imports
72
+ acc[`${e.pathAlias}/*`] = [`src/extensions/${e.id}/*`];
73
+ return acc;
74
+ }, {});
75
+ }
76
+ /**
77
+ * Copies all files from the extensionPaths of the configured extensions into the
78
+ * admin-ui source tree.
79
+ */
80
+ async function copyExtensionModules(outputPath, extensions) {
81
+ const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
82
+ const extensionRoutesSource = generateLazyExtensionRoutes(adminUiExtensions);
83
+ fs.writeFileSync(path.join(outputPath, constants_1.EXTENSION_ROUTES_FILE), extensionRoutesSource, 'utf8');
84
+ const sharedExtensionModulesSource = generateSharedExtensionModule(extensions);
85
+ fs.writeFileSync(path.join(outputPath, constants_1.SHARED_EXTENSIONS_FILE), sharedExtensionModulesSource, 'utf8');
86
+ for (const extension of adminUiExtensions) {
87
+ if (!extension.extensionPath) {
88
+ continue;
89
+ }
90
+ const dest = path.join(outputPath, constants_1.MODULES_OUTPUT_DIR, extension.id);
91
+ if (!extension.exclude) {
92
+ fs.copySync(extension.extensionPath, dest);
93
+ continue;
94
+ }
95
+ const exclude = extension.exclude?.map(e => (0, glob_1.globSync)(path.join(extension.extensionPath, e))).flatMap(e => e) ??
96
+ [];
97
+ fs.copySync(extension.extensionPath, dest, {
98
+ filter: name => name === extension.extensionPath || exclude.every(e => e !== name),
99
+ });
100
+ }
101
+ }
102
+ async function copyStaticAssets(outputPath, extensions) {
103
+ for (const extension of extensions) {
104
+ if (Array.isArray(extension.staticAssets)) {
105
+ for (const asset of extension.staticAssets) {
106
+ await (0, utils_1.copyStaticAsset)(outputPath, asset);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ async function addGlobalStyles(outputPath, globalStylesExtensions, sassVariableOverridesExtension) {
112
+ const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
113
+ await fs.remove(globalStylesDir);
114
+ await fs.ensureDir(globalStylesDir);
115
+ const imports = [];
116
+ for (const extension of globalStylesExtensions) {
117
+ const styleFiles = Array.isArray(extension.globalStyles)
118
+ ? extension.globalStyles
119
+ : [extension.globalStyles];
120
+ for (const styleFile of styleFiles) {
121
+ await copyGlobalStyleFile(outputPath, styleFile);
122
+ imports.push(path.basename(styleFile, path.extname(styleFile)));
123
+ }
124
+ }
125
+ let overridesImport = '';
126
+ if (sassVariableOverridesExtension) {
127
+ const overridesFile = sassVariableOverridesExtension.sassVariableOverrides;
128
+ await copyGlobalStyleFile(outputPath, overridesFile);
129
+ overridesImport = `@import "./${constants_1.GLOBAL_STYLES_OUTPUT_DIR}/${path.basename(overridesFile, path.extname(overridesFile))}";\n`;
130
+ }
131
+ const globalStylesSource = overridesImport +
132
+ '@import "./styles/styles";\n' +
133
+ imports.map(file => `@import "./${constants_1.GLOBAL_STYLES_OUTPUT_DIR}/${file}";`).join('\n');
134
+ const globalStylesFile = path.join(outputPath, 'src', 'global-styles.scss');
135
+ await fs.writeFile(globalStylesFile, globalStylesSource, 'utf-8');
136
+ }
137
+ async function copyGlobalStyleFile(outputPath, stylePath) {
138
+ const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
139
+ const fileBasename = path.basename(stylePath);
140
+ const styleOutputPath = path.join(globalStylesDir, fileBasename);
141
+ await fs.copyFile(stylePath, styleOutputPath);
142
+ }
143
+ exports.copyGlobalStyleFile = copyGlobalStyleFile;
144
+ function generateLazyExtensionRoutes(extensions) {
145
+ const routes = [];
146
+ for (const extension of extensions) {
147
+ for (const module of extension.ngModules ?? []) {
148
+ if (module.type === 'lazy') {
149
149
  routes.push(` {
150
150
  path: 'extensions/${module.route}',
151
151
  loadChildren: () => import('${getModuleFilePath(extension.id, module)}').then(m => m.${module.ngModuleName}),
152
- }`);
153
- }
154
- }
155
- for (const route of extension.routes ?? []) {
152
+ }`);
153
+ }
154
+ }
155
+ for (const route of extension.routes ?? []) {
156
156
  routes.push(` {
157
157
  path: 'extensions/${route.route}',
158
158
  loadChildren: () => import('./extensions/${extension.id}/${path.basename(route.filePath, '.ts')}'),
159
- }`);
160
- }
161
- }
162
- return `export const extensionRoutes = [${routes.join(',\n')}];\n`;
163
- }
164
- function generateSharedExtensionModule(extensions) {
165
- const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
166
- const moduleImports = adminUiExtensions
167
- .map(e => e.ngModules
168
- ?.filter(m => m.type === 'shared')
169
- .map(m => `import { ${m.ngModuleName} } from '${getModuleFilePath(e.id, m)}';\n`)
170
- .join(''))
171
- .filter(val => !!val)
172
- .join('');
173
- const providerImports = adminUiExtensions
174
- .map((m, i) => (m.providers ?? [])
175
- .map((f, j) => `import SharedProviders_${i}_${j} from './extensions/${m.id}/${path.basename(f, '.ts')}';\n`)
176
- .join(''))
177
- .filter(val => !!val)
178
- .join('');
179
- const modules = adminUiExtensions
180
- .map(e => e.ngModules
181
- ?.filter(m => m.type === 'shared')
182
- .map(m => m.ngModuleName)
183
- .join(', '))
184
- .filter(val => !!val)
185
- .join(', ');
186
- const providers = adminUiExtensions
187
- .filter(shared_utils_1.notNullOrUndefined)
188
- .map((m, i) => (m.providers ?? []).map((f, j) => `...SharedProviders_${i}_${j}`).join(', '))
189
- .filter(val => !!val)
190
- .join(', ');
159
+ }`);
160
+ }
161
+ }
162
+ return `export const extensionRoutes = [${routes.join(',\n')}];\n`;
163
+ }
164
+ function generateSharedExtensionModule(extensions) {
165
+ const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
166
+ const moduleImports = adminUiExtensions
167
+ .map(e => e.ngModules
168
+ ?.filter(m => m.type === 'shared')
169
+ .map(m => `import { ${m.ngModuleName} } from '${getModuleFilePath(e.id, m)}';\n`)
170
+ .join(''))
171
+ .filter(val => !!val)
172
+ .join('');
173
+ const providerImports = adminUiExtensions
174
+ .map((m, i) => (m.providers ?? [])
175
+ .map((f, j) => `import SharedProviders_${i}_${j} from './extensions/${m.id}/${path.basename(f, '.ts')}';\n`)
176
+ .join(''))
177
+ .filter(val => !!val)
178
+ .join('');
179
+ const modules = adminUiExtensions
180
+ .map(e => e.ngModules
181
+ ?.filter(m => m.type === 'shared')
182
+ .map(m => m.ngModuleName)
183
+ .join(', '))
184
+ .filter(val => !!val)
185
+ .join(', ');
186
+ const providers = adminUiExtensions
187
+ .filter(shared_utils_1.notNullOrUndefined)
188
+ .map((m, i) => (m.providers ?? []).map((f, j) => `...SharedProviders_${i}_${j}`).join(', '))
189
+ .filter(val => !!val)
190
+ .join(', ');
191
191
  return `import { NgModule } from '@angular/core';
192
192
  import { CommonModule } from '@angular/common';
193
193
  ${moduleImports}
@@ -198,57 +198,57 @@ ${providerImports}
198
198
  providers: [${providers}],
199
199
  })
200
200
  export class SharedExtensionsModule {}
201
- `;
202
- }
203
- function getModuleFilePath(id, module) {
204
- return `./extensions/${id}/${path.basename(module.ngModuleFileName, '.ts')}`;
205
- }
206
- /**
207
- * Copies the Admin UI sources & static assets to the outputPath if it does not already
208
- * exist there.
209
- */
210
- function copyAdminUiSource(outputPath, modulePathMapping) {
211
- const tsconfigFilePath = path.join(outputPath, 'tsconfig.json');
212
- const indexFilePath = path.join(outputPath, '/src/index.html');
213
- if (fs.existsSync(tsconfigFilePath) && fs.existsSync(indexFilePath)) {
214
- configureModulePathMapping(tsconfigFilePath, modulePathMapping);
215
- return;
216
- }
217
- const scaffoldDir = path.join(__dirname, '../scaffold');
218
- const adminUiSrc = path.join(require.resolve('@vendure/admin-ui'), '../../static');
219
- if (!fs.existsSync(scaffoldDir)) {
220
- throw new Error(`Could not find the admin ui scaffold files at ${scaffoldDir}`);
221
- }
222
- if (!fs.existsSync(adminUiSrc)) {
223
- throw new Error(`Could not find the @vendure/admin-ui sources. Looked in ${adminUiSrc}`);
224
- }
225
- // copy scaffold
226
- fs.removeSync(outputPath);
227
- fs.ensureDirSync(outputPath);
228
- fs.copySync(scaffoldDir, outputPath);
229
- configureModulePathMapping(tsconfigFilePath, modulePathMapping);
230
- // copy source files from admin-ui package
231
- const outputSrc = path.join(outputPath, 'src');
232
- fs.ensureDirSync(outputSrc);
233
- fs.copySync(adminUiSrc, outputSrc);
234
- }
235
- async function setBaseHref(outputPath, baseHref) {
236
- const angularJsonFilePath = path.join(outputPath, '/angular.json');
237
- const angularJson = await fs.readJSON(angularJsonFilePath, 'utf-8');
238
- angularJson.projects['vendure-admin'].architect.build.options.baseHref = baseHref;
239
- await fs.writeJSON(angularJsonFilePath, angularJson, { spaces: 2 });
240
- }
241
- exports.setBaseHref = setBaseHref;
242
- /**
243
- * Adds module path mapping to the bundled tsconfig.json file if defined as a UI extension.
244
- */
245
- function configureModulePathMapping(tsconfigFilePath, modulePathMapping) {
246
- if (!modulePathMapping) {
247
- return;
248
- }
249
- // eslint-disable-next-line @typescript-eslint/no-var-requires
250
- const tsconfig = require(tsconfigFilePath);
251
- tsconfig.compilerOptions.paths = modulePathMapping;
252
- fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsconfig, null, 2));
253
- }
201
+ `;
202
+ }
203
+ function getModuleFilePath(id, module) {
204
+ return `./extensions/${id}/${path.basename(module.ngModuleFileName, '.ts')}`;
205
+ }
206
+ /**
207
+ * Copies the Admin UI sources & static assets to the outputPath if it does not already
208
+ * exist there.
209
+ */
210
+ function copyAdminUiSource(outputPath, modulePathMapping) {
211
+ const tsconfigFilePath = path.join(outputPath, 'tsconfig.json');
212
+ const indexFilePath = path.join(outputPath, '/src/index.html');
213
+ if (fs.existsSync(tsconfigFilePath) && fs.existsSync(indexFilePath)) {
214
+ configureModulePathMapping(tsconfigFilePath, modulePathMapping);
215
+ return;
216
+ }
217
+ const scaffoldDir = path.join(__dirname, '../scaffold');
218
+ const adminUiSrc = path.join(require.resolve('@vendure/admin-ui'), '../../static');
219
+ if (!fs.existsSync(scaffoldDir)) {
220
+ throw new Error(`Could not find the admin ui scaffold files at ${scaffoldDir}`);
221
+ }
222
+ if (!fs.existsSync(adminUiSrc)) {
223
+ throw new Error(`Could not find the @vendure/admin-ui sources. Looked in ${adminUiSrc}`);
224
+ }
225
+ // copy scaffold
226
+ fs.removeSync(outputPath);
227
+ fs.ensureDirSync(outputPath);
228
+ fs.copySync(scaffoldDir, outputPath);
229
+ configureModulePathMapping(tsconfigFilePath, modulePathMapping);
230
+ // copy source files from admin-ui package
231
+ const outputSrc = path.join(outputPath, 'src');
232
+ fs.ensureDirSync(outputSrc);
233
+ fs.copySync(adminUiSrc, outputSrc);
234
+ }
235
+ async function setBaseHref(outputPath, baseHref) {
236
+ const angularJsonFilePath = path.join(outputPath, '/angular.json');
237
+ const angularJson = await fs.readJSON(angularJsonFilePath, 'utf-8');
238
+ angularJson.projects['vendure-admin'].architect.build.options.baseHref = baseHref;
239
+ await fs.writeJSON(angularJsonFilePath, angularJson, { spaces: 2 });
240
+ }
241
+ exports.setBaseHref = setBaseHref;
242
+ /**
243
+ * Adds module path mapping to the bundled tsconfig.json file if defined as a UI extension.
244
+ */
245
+ function configureModulePathMapping(tsconfigFilePath, modulePathMapping) {
246
+ if (!modulePathMapping) {
247
+ return;
248
+ }
249
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
250
+ const tsconfig = require(tsconfigFilePath);
251
+ tsconfig.compilerOptions.paths = modulePathMapping;
252
+ fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsconfig, null, 2));
253
+ }
254
254
  //# sourceMappingURL=scaffold.js.map