@deenruv/ui-devkit 1.0.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.
Files changed (43) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +5 -0
  3. package/client/devkit-client-api.d.ts +109 -0
  4. package/client/index.d.ts +1 -0
  5. package/client/index.js +1 -0
  6. package/compiler/compile.d.ts +9 -0
  7. package/compiler/compile.js +265 -0
  8. package/compiler/compile.js.map +1 -0
  9. package/compiler/constants.d.ts +6 -0
  10. package/compiler/constants.js +10 -0
  11. package/compiler/constants.js.map +1 -0
  12. package/compiler/helpers.d.ts +25 -0
  13. package/compiler/helpers.js +50 -0
  14. package/compiler/helpers.js.map +1 -0
  15. package/compiler/index.d.ts +3 -0
  16. package/compiler/index.js +20 -0
  17. package/compiler/index.js.map +1 -0
  18. package/compiler/scaffold.d.ts +4 -0
  19. package/compiler/scaffold.js +259 -0
  20. package/compiler/scaffold.js.map +1 -0
  21. package/compiler/translations.d.ts +12 -0
  22. package/compiler/translations.js +135 -0
  23. package/compiler/translations.js.map +1 -0
  24. package/compiler/types.d.ts +454 -0
  25. package/compiler/types.js +3 -0
  26. package/compiler/types.js.map +1 -0
  27. package/compiler/utils.d.ts +34 -0
  28. package/compiler/utils.js +139 -0
  29. package/compiler/utils.js.map +1 -0
  30. package/package.json +66 -0
  31. package/scaffold/README.md +7 -0
  32. package/scaffold/angular.json +128 -0
  33. package/scaffold/package.json +11 -0
  34. package/scaffold/src/app.module.ts +23 -0
  35. package/scaffold/src/app.routes.ts +63 -0
  36. package/scaffold/src/environment.prod.ts +3 -0
  37. package/scaffold/src/environment.ts +6 -0
  38. package/scaffold/src/extension.routes.ts +1 -0
  39. package/scaffold/src/main.ts +16 -0
  40. package/scaffold/src/shared-extensions.module.ts +7 -0
  41. package/scaffold/src/styles/global-styles.scss +1 -0
  42. package/scaffold/src/tsconfig.app.json +18 -0
  43. package/scaffold/tsconfig.json +28 -0
@@ -0,0 +1,454 @@
1
+ import { LanguageCode } from "@deenruv/common/lib/generated-types";
2
+ export type Extension = AdminUiExtension | TranslationExtension | StaticAssetExtension | GlobalStylesExtension | SassVariableOverridesExtension;
3
+ /**
4
+ * @description
5
+ * Defines extensions to the Admin UI translations. Can be used as a stand-alone extension definition which only adds translations
6
+ * without adding new UI functionality, or as part of a full {@link AdminUiExtension}.
7
+ *
8
+ * @docsCategory UiDevkit
9
+ * @docsPage AdminUiExtension
10
+ */
11
+ export interface TranslationExtension {
12
+ /**
13
+ * @description
14
+ * Optional object defining any translation files for the Admin UI. The value should be an object with
15
+ * the key as a 2-character [ISO 639-1 language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes),
16
+ * and the value being a [glob](https://github.com/isaacs/node-glob) for any relevant
17
+ * translation files in JSON format.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * translations: {
22
+ * en: path.join(__dirname, 'translations/*.en.json'),
23
+ * de: path.join(__dirname, 'translations/*.de.json'),
24
+ * }
25
+ * ```
26
+ */
27
+ translations: {
28
+ [languageCode in LanguageCode]?: string;
29
+ };
30
+ }
31
+ /**
32
+ * @description
33
+ * Defines extensions which copy static assets to the custom Admin UI application source asset directory.
34
+ *
35
+ * @docsCategory UiDevkit
36
+ * @docsPage AdminUiExtension
37
+ */
38
+ export interface StaticAssetExtension {
39
+ /**
40
+ * @description
41
+ * Optional array of paths to static assets which will be copied over to the Admin UI app's `/static`
42
+ * directory.
43
+ */
44
+ staticAssets: StaticAssetDefinition[];
45
+ }
46
+ /**
47
+ * @description
48
+ * Defines extensions which add global styles to the custom Admin UI application.
49
+ *
50
+ * @docsCategory UiDevkit
51
+ * @docsPage AdminUiExtension
52
+ */
53
+ export interface GlobalStylesExtension {
54
+ /**
55
+ * @description
56
+ * Specifies a path (or array of paths) to global style files (css or Sass) which will be
57
+ * incorporated into the Admin UI app global stylesheet.
58
+ */
59
+ globalStyles: string[] | string;
60
+ }
61
+ /**
62
+ * @description
63
+ * Defines an extension which allows overriding Clarity Design System's Sass variables used in styles on the Admin UI.
64
+ *
65
+ * @docsCategory UiDevkit
66
+ * @docsPage AdminUiExtension
67
+ */
68
+ export interface SassVariableOverridesExtension {
69
+ /**
70
+ * @description
71
+ * Specifies a path to a Sass style file containing variable declarations, which will take precedence over
72
+ * default values defined in Clarity.
73
+ */
74
+ sassVariableOverrides: string;
75
+ }
76
+ /**
77
+ * @description
78
+ * Defines a route which will be added to the Admin UI application.
79
+ *
80
+ * @docsCategory UiDevkit
81
+ * @docsPage AdminUiExtension
82
+ */
83
+ export interface UiExtensionRouteDefinition {
84
+ /**
85
+ * @description
86
+ * The name of the route. This will be used as the path in the URL.
87
+ */
88
+ route: string;
89
+ /**
90
+ * @description
91
+ * The path to the file which exports an array of Angular route definitions.
92
+ */
93
+ filePath: string;
94
+ /**
95
+ * @description
96
+ * All extensions will be mounted under the `/extensions/` route. This option allows you to specify a
97
+ * custom prefix rather than `/extensions/`. For example, setting this to `custom` would cause the extension
98
+ * to be mounted at `/custom/<route>` instead.
99
+ *
100
+ * A common use case for this is to mount the extension at the root of the Admin UI, by setting this to an empty string.
101
+ * This is useful when the extension is intended to replace the default Admin UI, rather than extend it.
102
+ *
103
+ * @since 2.2.0
104
+ */
105
+ prefix?: string;
106
+ }
107
+ /**
108
+ * @description
109
+ * Defines extensions to the Admin UI application by specifying additional
110
+ * Angular [NgModules](https://angular.io/guide/ngmodules) which are compiled
111
+ * into the application.
112
+ *
113
+ * See [Extending the Admin UI](/guides/extending-the-admin-ui/getting-started/) for
114
+ * detailed instructions.
115
+ *
116
+ * @docsCategory UiDevkit
117
+ * @docsPage AdminUiExtension
118
+ * @docsWeight 0
119
+ */
120
+ export interface AdminUiExtension extends Partial<TranslationExtension>, Partial<StaticAssetExtension>, Partial<GlobalStylesExtension> {
121
+ /**
122
+ * @description
123
+ * An optional ID for the extension module. Only used internally for generating
124
+ * import paths to your module. If not specified, a unique hash will be used as the id.
125
+ */
126
+ id?: string;
127
+ /**
128
+ * @description
129
+ * The path to the directory containing the extension module(s). The entire contents of this directory
130
+ * will be copied into the Admin UI app, including all TypeScript source files, html templates,
131
+ * scss style sheets etc.
132
+ */
133
+ extensionPath: string;
134
+ /**
135
+ * @description
136
+ * One or more Angular modules which extend the default Admin UI.
137
+ *
138
+ * @deprecated use `routes` instead of lazy modules, and `providers` instead of shared modules in combination
139
+ * with Angular standalone components.
140
+ */
141
+ ngModules?: Array<AdminUiExtensionSharedModule | AdminUiExtensionLazyModule>;
142
+ /**
143
+ * @description
144
+ * Defines the paths to a file that exports an array of shared providers such as nav menu items, custom form inputs,
145
+ * custom detail components, action bar items, custom history entry components.
146
+ */
147
+ providers?: string[];
148
+ /**
149
+ * @description
150
+ * Defines routes that will be lazy-loaded at the `/extensions/` route. The filePath should point to a file
151
+ * relative to the `extensionPath` which exports an array of Angular route definitions.
152
+ */
153
+ routes?: UiExtensionRouteDefinition[];
154
+ /**
155
+ * @description
156
+ * An optional alias for the module so it can be referenced by other UI extension modules.
157
+ *
158
+ * By default, Angular modules declared in an AdminUiExtension do not have access to code outside the directory
159
+ * defined by the `extensionPath`. A scenario in which that can be useful though is in a monorepo codebase where
160
+ * a common NgModule is shared across different plugins, each defined in its own package. An example can be found
161
+ * below - note that the main `tsconfig.json` also maps the target module but using a path relative to the project's
162
+ * root folder. The UI module is not part of the main TypeScript build task as explained in
163
+ * [Extending the Admin UI](https://deenruv.com/docs/plugins/extending-the-admin-ui/) but having `paths`
164
+ * properly configured helps with usual IDE code editing features such as code completion and quick navigation, as
165
+ * well as linting.
166
+ *
167
+ * @example
168
+ * ```ts title="packages/common-ui-module/src/ui/ui-shared.module.ts"
169
+ * import { NgModule } from '\@angular/core';
170
+ * import { SharedModule } from '\@deenruv/admin-ui/core';
171
+ * import { CommonUiComponent } from './components/common-ui/common-ui.component';
172
+ *
173
+ * export { CommonUiComponent };
174
+ *
175
+ * \@NgModule({
176
+ * imports: [SharedModule],
177
+ * exports: [CommonUiComponent],
178
+ * declarations: [CommonUiComponent],
179
+ * })
180
+ * export class CommonSharedUiModule {}
181
+ * ```
182
+ *
183
+ * ```ts title="packages/common-ui-module/src/index.ts"
184
+ * import path from 'path';
185
+ *
186
+ * import { AdminUiExtension } from '\@deenruv/ui-devkit/compiler';
187
+ *
188
+ * export const uiExtensions: AdminUiExtension = {
189
+ * // highlight-next-line
190
+ * pathAlias: '\@common-ui-module', // this is the important part
191
+ * extensionPath: path.join(__dirname, 'ui'),
192
+ * ngModules: [
193
+ * {
194
+ * type: 'shared' as const,
195
+ * ngModuleFileName: 'ui-shared.module.ts',
196
+ * ngModuleName: 'CommonSharedUiModule',
197
+ * },
198
+ * ],
199
+ * };
200
+ * ```
201
+ *
202
+ * ```json title="tsconfig.json"
203
+ * {
204
+ * "compilerOptions": {
205
+ * "baseUrl": ".",
206
+ * "paths": {
207
+ * // highlight-next-line
208
+ * "\@common-ui-module/*": ["packages/common-ui-module/src/ui/*"]
209
+ * }
210
+ * }
211
+ * }
212
+ * ```
213
+ *
214
+ * ```ts title="packages/sample-plugin/src/ui/ui-extension.module.ts"
215
+ * import { NgModule } from '\@angular/core';
216
+ * import { SharedModule } from '\@deenruv/admin-ui/core';
217
+ * // highlight-start
218
+ * // the import below works both in the context of the custom Admin UI app as well as the main project
219
+ * // '\@common-ui-module' is the value of "pathAlias" and 'ui-shared.module' is the file we want to reference inside "extensionPath"
220
+ * import { CommonSharedUiModule, CommonUiComponent } from '\@common-ui-module/ui-shared.module';
221
+ * // highlight-end
222
+ *
223
+ * \@NgModule({
224
+ * imports: [
225
+ * SharedModule,
226
+ * CommonSharedUiModule,
227
+ * RouterModule.forChild([
228
+ * {
229
+ * path: '',
230
+ * pathMatch: 'full',
231
+ * component: CommonUiComponent,
232
+ * },
233
+ * ]),
234
+ * ],
235
+ * })
236
+ * export class SampleUiExtensionModule {}
237
+ * ```
238
+ */
239
+ pathAlias?: string;
240
+ /**
241
+ * @description
242
+ * Optional array specifying filenames or [glob](https://github.com/isaacs/node-glob) patterns that should
243
+ * be skipped when copying the directory defined by `extensionPath`.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * exclude: ['**\/*.spec.ts']
248
+ * ```
249
+ */
250
+ exclude?: string[];
251
+ }
252
+ /**
253
+ * @description
254
+ * A static asset can be provided as a path to the asset, or as an object containing a path and a new
255
+ * name, which will cause the compiler to copy and then rename the asset.
256
+ *
257
+ * @docsCategory UiDevkit
258
+ * @docsPage AdminUiExtension
259
+ */
260
+ export type StaticAssetDefinition = string | {
261
+ path: string;
262
+ rename: string;
263
+ };
264
+ /**
265
+ * @description
266
+ * Configuration defining a single NgModule with which to extend the Admin UI.
267
+ *
268
+ * @docsCategory UiDevkit
269
+ * @docsPage AdminUiExtension
270
+ */
271
+ export interface AdminUiExtensionSharedModule {
272
+ /**
273
+ * @description
274
+ * Shared modules are directly imported into the main AppModule of the Admin UI
275
+ * and should be used to declare custom form components and define custom
276
+ * navigation items.
277
+ */
278
+ type: "shared";
279
+ /**
280
+ * @description
281
+ * The name of the file containing the extension module class.
282
+ */
283
+ ngModuleFileName: string;
284
+ /**
285
+ * @description
286
+ * The name of the extension module class.
287
+ */
288
+ ngModuleName: string;
289
+ }
290
+ /**
291
+ * @description
292
+ * Configuration defining a single NgModule with which to extend the Admin UI.
293
+ *
294
+ * @docsCategory UiDevkit
295
+ * @docsPage AdminUiExtension
296
+ */
297
+ export interface AdminUiExtensionLazyModule {
298
+ /**
299
+ * @description
300
+ * Lazy modules are lazy-loaded at the `/extensions/` route and should be used for
301
+ * modules which define new views for the Admin UI.
302
+ */
303
+ type: "lazy";
304
+ /**
305
+ * @description
306
+ * The route specifies the route at which the module will be lazy-loaded. E.g. a value
307
+ * of `'foo'` will cause the module to lazy-load when the `/extensions/foo` route
308
+ * is activated.
309
+ */
310
+ route: string;
311
+ /**
312
+ * @description
313
+ * The name of the file containing the extension module class.
314
+ */
315
+ ngModuleFileName: string;
316
+ /**
317
+ * @description
318
+ * The name of the extension module class.
319
+ */
320
+ ngModuleName: string;
321
+ }
322
+ /**
323
+ * @description
324
+ * Argument to configure process (watch or compile)
325
+ *
326
+ * @docsCategory UiDevkit
327
+ */
328
+ export type UiExtensionCompilerProcessArgument = string | [string, any];
329
+ /**
330
+ * @description
331
+ * The package manager to use when invoking the Angular CLI to build UI extensions.
332
+ *
333
+ * @docsCategory UiDevkit
334
+ */
335
+ export type UiExtensionBuildCommand = "npm" | "yarn" | "pnpm";
336
+ /**
337
+ * @description
338
+ * Options to configure how the Admin UI should be compiled.
339
+ *
340
+ * @docsCategory UiDevkit
341
+ */
342
+ export interface UiExtensionCompilerOptions {
343
+ /**
344
+ * @description
345
+ * The directory into which the sources for the extended Admin UI will be copied.
346
+ */
347
+ outputPath: string;
348
+ /**
349
+ * @description
350
+ * An array of objects which configure Angular modules and/or
351
+ * translations with which to extend the Admin UI.
352
+ */
353
+ extensions: Extension[];
354
+ /**
355
+ * @description
356
+ * Allows you to manually specify the path to the Angular CLI compiler script. This can be useful in scenarios
357
+ * where for some reason the built-in start/build scripts are unable to locate the `ng` command.
358
+ *
359
+ * This option should not usually be required.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * compileUiExtensions({
364
+ * ngCompilerPath: path.join(__dirname, '../../node_modules/@angular/cli/bin/ng.js'),
365
+ * outputPath: path.join(__dirname, '../admin-ui'),
366
+ * extensions: [
367
+ * // ...
368
+ * ],
369
+ * })
370
+ * ```
371
+ *
372
+ * @since 2.1.0
373
+ */
374
+ ngCompilerPath?: string | undefined;
375
+ /**
376
+ * @description
377
+ * Set to `true` in order to compile the Admin UI in development mode (using the Angular CLI
378
+ * [ng serve](https://angular.io/cli/serve) command). When in dev mode, any changes to
379
+ * UI extension files will be watched and trigger a rebuild of the Admin UI with live
380
+ * reloading.
381
+ *
382
+ * @default false
383
+ */
384
+ devMode?: boolean;
385
+ /**
386
+ * @description
387
+ * Allows the baseHref of the compiled Admin UI app to be set. This determines the prefix
388
+ * of the app, for example with the default value of `'/admin/'`, the Admin UI app
389
+ * will be configured to be served from `http://<host>/admin/`.
390
+ *
391
+ * Note: if you are using this in conjunction with the {@link AdminUiPlugin} then you should
392
+ * also set the `route` option to match this value.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * AdminUiPlugin.init({
397
+ * route: 'my-route',
398
+ * port: 5001,
399
+ * app: compileUiExtensions({
400
+ * baseHref: '/my-route/',
401
+ * outputPath: path.join(__dirname, './custom-admin-ui'),
402
+ * extensions: [],
403
+ * devMode: true,
404
+ * }),
405
+ * }),
406
+ * ```
407
+ *
408
+ * @default '/admin/'
409
+ */
410
+ baseHref?: string;
411
+ /**
412
+ * @description
413
+ * In watch mode, allows the port of the dev server to be specified. Defaults to the Angular CLI default
414
+ * of `4200`.
415
+ *
416
+ * @default 4200 | undefined
417
+ */
418
+ watchPort?: number;
419
+ /**
420
+ * @description
421
+ * Internally, the Angular CLI will be invoked as an npm script. By default, the compiler will use Yarn
422
+ * to run the script if it is detected, otherwise it will use npm. This setting allows you to explicitly
423
+ * set which command to use, including pnpm, rather than relying on the default behavior.
424
+ *
425
+ * @since 1.5.0
426
+ */
427
+ command?: UiExtensionBuildCommand;
428
+ /**
429
+ * @description
430
+ * Additional command-line arguments which will get passed to the [ng build](https://angular.io/cli/build)
431
+ * command (or [ng serve](https://angular.io/cli/serve) if `devMode = true`).
432
+ *
433
+ * @example
434
+ * ['--disable-host-check'] // to disable host check
435
+ *
436
+ * @default undefined
437
+ *
438
+ * @since 1.5.0
439
+ */
440
+ additionalProcessArguments?: UiExtensionCompilerProcessArgument[];
441
+ }
442
+ export type Translations = {
443
+ [section: string]: {
444
+ [token: string]: string;
445
+ };
446
+ };
447
+ export interface BrandingOptions {
448
+ smallLogoPath?: string;
449
+ largeLogoPath?: string;
450
+ faviconPath?: string;
451
+ }
452
+ export interface AdminUiExtensionWithId extends AdminUiExtension {
453
+ id: string;
454
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/compiler/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { AdminUiExtension, AdminUiExtensionWithId, Extension, GlobalStylesExtension, SassVariableOverridesExtension, StaticAssetDefinition, StaticAssetExtension, TranslationExtension } from "./types";
2
+ export declare const logger: {
3
+ log: (message: string) => void;
4
+ error: (message: string) => void;
5
+ };
6
+ /**
7
+ * Checks for the global yarn binary to determine whether to use yarn or npm.
8
+ */
9
+ export declare function determinePackageManager(): "yarn" | "npm";
10
+ /**
11
+ * Returns the string path of a static asset
12
+ */
13
+ export declare function getStaticAssetPath(staticAssetDef: StaticAssetDefinition): string;
14
+ /**
15
+ * Copy the @deenruv/ui-devkit files to the static assets dir.
16
+ */
17
+ export declare function copyUiDevkit(outputPath: string): void;
18
+ /**
19
+ * Copies over any files defined by the extensions' `staticAssets` array to the shared
20
+ * static assets directory. When the app is built by the ng cli, this assets directory is
21
+ * the copied over to the final static assets location (i.e. http://domain/admin/assets/)
22
+ */
23
+ export declare function copyStaticAsset(outputPath: string, staticAssetDef: StaticAssetDefinition): Promise<void>;
24
+ /**
25
+ * Ensures each extension has an ID and a value for the optional properties.
26
+ * If not defined by the user, a deterministic ID is generated
27
+ * from a hash of the extension config.
28
+ */
29
+ export declare function normalizeExtensions(extensions?: AdminUiExtension[]): AdminUiExtensionWithId[];
30
+ export declare function isAdminUiExtension(input: Extension): input is AdminUiExtension;
31
+ export declare function isTranslationExtension(input: Extension): input is TranslationExtension;
32
+ export declare function isStaticAssetExtension(input: Extension): input is StaticAssetExtension;
33
+ export declare function isGlobalStylesExtension(input: Extension): input is GlobalStylesExtension;
34
+ export declare function isSassVariableOverridesExtension(input: Extension): input is SassVariableOverridesExtension;
@@ -0,0 +1,139 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.isSassVariableOverridesExtension = exports.isGlobalStylesExtension = exports.isStaticAssetExtension = exports.isTranslationExtension = exports.isAdminUiExtension = exports.normalizeExtensions = exports.copyStaticAsset = exports.copyUiDevkit = exports.getStaticAssetPath = exports.determinePackageManager = exports.logger = void 0;
30
+ const chalk_1 = __importDefault(require("chalk"));
31
+ const child_process_1 = require("child_process");
32
+ const crypto_1 = require("crypto");
33
+ const fs = __importStar(require("fs-extra"));
34
+ const path = __importStar(require("path"));
35
+ const constants_1 = require("./constants");
36
+ exports.logger = {
37
+ log: (message) => console.log(chalk_1.default.green(message)),
38
+ error: (message) => console.log(chalk_1.default.red(message)),
39
+ };
40
+ /**
41
+ * Checks for the global yarn binary to determine whether to use yarn or npm.
42
+ */
43
+ function determinePackageManager() {
44
+ try {
45
+ (0, child_process_1.execSync)("yarnpkg --version", { stdio: "ignore" });
46
+ return "yarn";
47
+ }
48
+ catch (e) {
49
+ return "npm";
50
+ }
51
+ }
52
+ exports.determinePackageManager = determinePackageManager;
53
+ /**
54
+ * Returns the string path of a static asset
55
+ */
56
+ function getStaticAssetPath(staticAssetDef) {
57
+ return typeof staticAssetDef === "string"
58
+ ? staticAssetDef
59
+ : staticAssetDef.path;
60
+ }
61
+ exports.getStaticAssetPath = getStaticAssetPath;
62
+ /**
63
+ * Copy the @deenruv/ui-devkit files to the static assets dir.
64
+ */
65
+ function copyUiDevkit(outputPath) {
66
+ const devkitDir = path.join(outputPath, constants_1.STATIC_ASSETS_OUTPUT_DIR, "devkit");
67
+ fs.ensureDirSync(devkitDir);
68
+ fs.copySync(require.resolve("@deenruv/ui-devkit"), path.join(devkitDir, "ui-devkit.js"));
69
+ }
70
+ exports.copyUiDevkit = copyUiDevkit;
71
+ /**
72
+ * Copies over any files defined by the extensions' `staticAssets` array to the shared
73
+ * static assets directory. When the app is built by the ng cli, this assets directory is
74
+ * the copied over to the final static assets location (i.e. http://domain/admin/assets/)
75
+ */
76
+ async function copyStaticAsset(outputPath, staticAssetDef) {
77
+ const staticAssetPath = getStaticAssetPath(staticAssetDef);
78
+ const assetBasename = path.basename(staticAssetPath);
79
+ const assetOutputPath = path.join(outputPath, constants_1.STATIC_ASSETS_OUTPUT_DIR, assetBasename);
80
+ fs.copySync(staticAssetPath, assetOutputPath);
81
+ if (typeof staticAssetDef !== "string") {
82
+ // The asset is being renamed
83
+ const newName = path.join(path.dirname(assetOutputPath), staticAssetDef.rename);
84
+ try {
85
+ // We use copy, remove rather than rename due to problems with the
86
+ // EPERM error in Windows.
87
+ await fs.copy(assetOutputPath, newName);
88
+ await fs.remove(assetOutputPath);
89
+ }
90
+ catch (e) {
91
+ exports.logger.log(e);
92
+ }
93
+ }
94
+ }
95
+ exports.copyStaticAsset = copyStaticAsset;
96
+ /**
97
+ * Ensures each extension has an ID and a value for the optional properties.
98
+ * If not defined by the user, a deterministic ID is generated
99
+ * from a hash of the extension config.
100
+ */
101
+ function normalizeExtensions(extensions) {
102
+ return (extensions || []).map((e) => {
103
+ let id = e.id;
104
+ if (!id) {
105
+ const hash = (0, crypto_1.createHash)("sha256");
106
+ hash.update(JSON.stringify(e));
107
+ id = hash.digest("hex");
108
+ }
109
+ return {
110
+ staticAssets: [],
111
+ translations: {},
112
+ globalStyles: [],
113
+ ...e,
114
+ id,
115
+ };
116
+ });
117
+ }
118
+ exports.normalizeExtensions = normalizeExtensions;
119
+ function isAdminUiExtension(input) {
120
+ return input.hasOwnProperty("extensionPath");
121
+ }
122
+ exports.isAdminUiExtension = isAdminUiExtension;
123
+ function isTranslationExtension(input) {
124
+ return input.hasOwnProperty("translations");
125
+ }
126
+ exports.isTranslationExtension = isTranslationExtension;
127
+ function isStaticAssetExtension(input) {
128
+ return input.hasOwnProperty("staticAssets");
129
+ }
130
+ exports.isStaticAssetExtension = isStaticAssetExtension;
131
+ function isGlobalStylesExtension(input) {
132
+ return input.hasOwnProperty("globalStyles");
133
+ }
134
+ exports.isGlobalStylesExtension = isGlobalStylesExtension;
135
+ function isSassVariableOverridesExtension(input) {
136
+ return input.hasOwnProperty("sassVariableOverrides");
137
+ }
138
+ exports.isSassVariableOverridesExtension = isSassVariableOverridesExtension;
139
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/compiler/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,iDAAyC;AACzC,mCAAoC;AACpC,6CAA+B;AAC/B,2CAA6B;AAE7B,2CAAuD;AAY1C,QAAA,MAAM,GAAG;IACpB,GAAG,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3D,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;CAC5D,CAAC;AAEF;;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