@vendure/ui-devkit 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +5 -0
- package/client/devkit-client-api.d.ts +51 -0
- package/client/index.d.ts +1 -0
- package/client/index.js +1 -0
- package/compiler/compile.d.ts +9 -0
- package/compiler/compile.js +218 -0
- package/compiler/compile.js.map +1 -0
- package/compiler/constants.d.ts +6 -0
- package/compiler/constants.js +10 -0
- package/compiler/constants.js.map +1 -0
- package/compiler/helpers.d.ts +23 -0
- package/compiler/helpers.js +48 -0
- package/compiler/helpers.js.map +1 -0
- package/compiler/index.d.ts +3 -0
- package/compiler/index.js +16 -0
- package/compiler/index.js.map +1 -0
- package/compiler/scaffold.d.ts +3 -0
- package/compiler/scaffold.js +219 -0
- package/compiler/scaffold.js.map +1 -0
- package/compiler/translations.d.ts +12 -0
- package/compiler/translations.js +136 -0
- package/compiler/translations.js.map +1 -0
- package/compiler/types.d.ts +219 -0
- package/compiler/types.js +3 -0
- package/compiler/types.js.map +1 -0
- package/compiler/utils.d.ts +33 -0
- package/compiler/utils.js +125 -0
- package/compiler/utils.js.map +1 -0
- package/package.json +64 -0
- package/scaffold/README.md +7 -0
- package/scaffold/angular.json +119 -0
- package/scaffold/package.json +11 -0
- package/scaffold/src/app.module.ts +19 -0
- package/scaffold/src/app.routes.ts +49 -0
- package/scaffold/src/environment.prod.ts +3 -0
- package/scaffold/src/environment.ts +6 -0
- package/scaffold/src/extension.routes.ts +1 -0
- package/scaffold/src/global-styles.scss +1 -0
- package/scaffold/src/main.ts +17 -0
- package/scaffold/src/shared-extensions.module.ts +7 -0
- package/scaffold/src/tsconfig.app.json +18 -0
- package/scaffold/tsconfig.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Michael Bromley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { NotificationMessage, WatchQueryFetchPolicy } from '@vendure/common/lib/extension-host-types';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Set the [window.postMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
|
|
6
|
+
* `targetOrigin`. The Vendure ui-devkit uses the postMessage API to
|
|
7
|
+
* enable cross-frame and cross-origin communication between the ui extension code and the Admin UI
|
|
8
|
+
* app. The `targetOrigin` is a security feature intended to provide control over where messages are sent.
|
|
9
|
+
*
|
|
10
|
+
* @docsCategory ui-devkit
|
|
11
|
+
* @docsPage UiDevkitClient
|
|
12
|
+
*/
|
|
13
|
+
export declare function setTargetOrigin(value: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* @description
|
|
16
|
+
* Perform a GraphQL query and returns either an Observable or a Promise of the result.
|
|
17
|
+
*
|
|
18
|
+
* @docsCategory ui-devkit
|
|
19
|
+
* @docsPage UiDevkitClient
|
|
20
|
+
*/
|
|
21
|
+
export declare function graphQlQuery<T, V extends {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}>(document: string, variables?: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}, fetchPolicy?: WatchQueryFetchPolicy): {
|
|
26
|
+
then: Promise<T>['then'];
|
|
27
|
+
stream: Observable<T>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @description
|
|
31
|
+
* Perform a GraphQL mutation and returns either an Observable or a Promise of the result.
|
|
32
|
+
*
|
|
33
|
+
* @docsCategory ui-devkit
|
|
34
|
+
* @docsPage UiDevkitClient
|
|
35
|
+
*/
|
|
36
|
+
export declare function graphQlMutation<T, V extends {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}>(document: string, variables?: {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}): {
|
|
41
|
+
then: Promise<T>['then'];
|
|
42
|
+
stream: Observable<T>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @description
|
|
46
|
+
* Display a toast notification.
|
|
47
|
+
*
|
|
48
|
+
* @docsCategory ui-devkit
|
|
49
|
+
* @docsPage UiDevkitClient
|
|
50
|
+
*/
|
|
51
|
+
export declare function notify(options: NotificationMessage['data']): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './devkit-client-api';
|
package/client/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).VendureUiClient={})}(this,(function(r){"use strict";var t=function(r,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n])})(r,n)};function n(r,n){function e(){this.constructor=r}t(r,n),r.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}function e(r){return"function"==typeof r}var o=!1,i={Promise:void 0,set useDeprecatedSynchronousErrorHandling(r){r&&(new Error).stack;o=r},get useDeprecatedSynchronousErrorHandling(){return o}};function s(r){setTimeout((function(){throw r}),0)}var u={closed:!0,next:function(r){},error:function(r){if(i.useDeprecatedSynchronousErrorHandling)throw r;s(r)},complete:function(){}},c=function(){return Array.isArray||function(r){return r&&"number"==typeof r.length}}();var a=function(){function r(r){return Error.call(this),this.message=r?r.length+" errors occurred during unsubscription:\n"+r.map((function(r,t){return t+1+") "+r.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=r,this}return r.prototype=Object.create(Error.prototype),r}(),h=function(){function r(r){this.closed=!1,this._parentOrParents=null,this._subscriptions=null,r&&(this._ctorUnsubscribe=!0,this._unsubscribe=r)}return r.prototype.unsubscribe=function(){var t;if(!this.closed){var n,o=this,i=o._parentOrParents,s=o._ctorUnsubscribe,u=o._unsubscribe,h=o._subscriptions;if(this.closed=!0,this._parentOrParents=null,this._subscriptions=null,i instanceof r)i.remove(this);else if(null!==i)for(var f=0;f<i.length;++f){i[f].remove(this)}if(e(u)){s&&(this._unsubscribe=void 0);try{u.call(this)}catch(r){t=r instanceof a?p(r.errors):[r]}}if(c(h)){f=-1;for(var l=h.length;++f<l;){var b=h[f];if(null!==(n=b)&&"object"==typeof n)try{b.unsubscribe()}catch(r){t=t||[],r instanceof a?t=t.concat(p(r.errors)):t.push(r)}}}if(t)throw new a(t)}},r.prototype.add=function(t){var n=t;if(!t)return r.EMPTY;switch(typeof t){case"function":n=new r(t);case"object":if(n===this||n.closed||"function"!=typeof n.unsubscribe)return n;if(this.closed)return n.unsubscribe(),n;if(!(n instanceof r)){var e=n;(n=new r)._subscriptions=[e]}break;default:throw new Error("unrecognized teardown "+t+" added to Subscription.")}var o=n._parentOrParents;if(null===o)n._parentOrParents=this;else if(o instanceof r){if(o===this)return n;n._parentOrParents=[o,this]}else{if(-1!==o.indexOf(this))return n;o.push(this)}var i=this._subscriptions;return null===i?this._subscriptions=[n]:i.push(n),n},r.prototype.remove=function(r){var t=this._subscriptions;if(t){var n=t.indexOf(r);-1!==n&&t.splice(n,1)}},r.EMPTY=function(r){return r.closed=!0,r}(new r),r}();function p(r){return r.reduce((function(r,t){return r.concat(t instanceof a?t.errors:t)}),[])}var f=function(){return"function"==typeof Symbol?Symbol("rxSubscriber"):"@@rxSubscriber_"+Math.random()}(),l=function(r){function t(n,e,o){var i=r.call(this)||this;switch(i.syncErrorValue=null,i.syncErrorThrown=!1,i.syncErrorThrowable=!1,i.isStopped=!1,arguments.length){case 0:i.destination=u;break;case 1:if(!n){i.destination=u;break}if("object"==typeof n){n instanceof t?(i.syncErrorThrowable=n.syncErrorThrowable,i.destination=n,n.add(i)):(i.syncErrorThrowable=!0,i.destination=new b(i,n));break}default:i.syncErrorThrowable=!0,i.destination=new b(i,n,e,o)}return i}return n(t,r),t.prototype[f]=function(){return this},t.create=function(r,n,e){var o=new t(r,n,e);return o.syncErrorThrowable=!1,o},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this))},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){this.destination.error(r),this.unsubscribe()},t.prototype._complete=function(){this.destination.complete(),this.unsubscribe()},t.prototype._unsubscribeAndRecycle=function(){var r=this._parentOrParents;return this._parentOrParents=null,this.unsubscribe(),this.closed=!1,this.isStopped=!1,this._parentOrParents=r,this},t}(h),b=function(r){function t(t,n,o,i){var s,c=r.call(this)||this;c._parentSubscriber=t;var a=c;return e(n)?s=n:n&&(s=n.next,o=n.error,i=n.complete,n!==u&&(e((a=Object.create(n)).unsubscribe)&&c.add(a.unsubscribe.bind(a)),a.unsubscribe=c.unsubscribe.bind(c))),c._context=a,c._next=s,c._error=o,c._complete=i,c}return n(t,r),t.prototype.next=function(r){if(!this.isStopped&&this._next){var t=this._parentSubscriber;i.useDeprecatedSynchronousErrorHandling&&t.syncErrorThrowable?this.__tryOrSetError(t,this._next,r)&&this.unsubscribe():this.__tryOrUnsub(this._next,r)}},t.prototype.error=function(r){if(!this.isStopped){var t=this._parentSubscriber,n=i.useDeprecatedSynchronousErrorHandling;if(this._error)n&&t.syncErrorThrowable?(this.__tryOrSetError(t,this._error,r),this.unsubscribe()):(this.__tryOrUnsub(this._error,r),this.unsubscribe());else if(t.syncErrorThrowable)n?(t.syncErrorValue=r,t.syncErrorThrown=!0):s(r),this.unsubscribe();else{if(this.unsubscribe(),n)throw r;s(r)}}},t.prototype.complete=function(){var r=this;if(!this.isStopped){var t=this._parentSubscriber;if(this._complete){var n=function(){return r._complete.call(r._context)};i.useDeprecatedSynchronousErrorHandling&&t.syncErrorThrowable?(this.__tryOrSetError(t,n),this.unsubscribe()):(this.__tryOrUnsub(n),this.unsubscribe())}else this.unsubscribe()}},t.prototype.__tryOrUnsub=function(r,t){try{r.call(this._context,t)}catch(r){if(this.unsubscribe(),i.useDeprecatedSynchronousErrorHandling)throw r;s(r)}},t.prototype.__tryOrSetError=function(r,t,n){if(!i.useDeprecatedSynchronousErrorHandling)throw new Error("bad call");try{t.call(this._context,n)}catch(t){return i.useDeprecatedSynchronousErrorHandling?(r.syncErrorValue=t,r.syncErrorThrown=!0,!0):(s(t),!0)}return!1},t.prototype._unsubscribe=function(){var r=this._parentSubscriber;this._context=null,this._parentSubscriber=null,r.unsubscribe()},t}(l);var d=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function y(r){return r}function _(r){return 0===r.length?y:1===r.length?r[0]:function(t){return r.reduce((function(r,t){return t(r)}),t)}}var v=function(){function r(r){this._isScalar=!1,r&&(this._subscribe=r)}return r.prototype.lift=function(t){var n=new r;return n.source=this,n.operator=t,n},r.prototype.subscribe=function(r,t,n){var e=this.operator,o=function(r,t,n){if(r){if(r instanceof l)return r;if(r[f])return r[f]()}return r||t||n?new l(r,t,n):new l(u)}(r,t,n);if(e?o.add(e.call(o,this.source)):o.add(this.source||i.useDeprecatedSynchronousErrorHandling&&!o.syncErrorThrowable?this._subscribe(o):this._trySubscribe(o)),i.useDeprecatedSynchronousErrorHandling&&o.syncErrorThrowable&&(o.syncErrorThrowable=!1,o.syncErrorThrown))throw o.syncErrorValue;return o},r.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(t){i.useDeprecatedSynchronousErrorHandling&&(r.syncErrorThrown=!0,r.syncErrorValue=t),!function(r){for(;r;){var t=r,n=t.closed,e=t.destination,o=t.isStopped;if(n||o)return!1;r=e&&e instanceof l?e:null}return!0}(r)?console.warn(t):r.error(t)}},r.prototype.forEach=function(r,t){var n=this;return new(t=w(t))((function(t,e){var o;o=n.subscribe((function(t){try{r(t)}catch(r){e(r),o&&o.unsubscribe()}}),e,t)}))},r.prototype._subscribe=function(r){var t=this.source;return t&&t.subscribe(r)},r.prototype[d]=function(){return this},r.prototype.pipe=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return 0===r.length?this:_(r)(this)},r.prototype.toPromise=function(r){var t=this;return new(r=w(r))((function(r,n){var e;t.subscribe((function(r){return e=r}),(function(r){return n(r)}),(function(){return r(e)}))}))},r.create=function(t){return new r(t)},r}();function w(r){if(r||(r=i.Promise||Promise),!r)throw new Error("no Promise impl found");return r}var E=new v((function(r){return r.complete()}));function m(r){return r?function(r){return new v((function(t){return r.schedule((function(){return t.complete()}))}))}(r):E}var S=function(){function r(){return Error.call(this),this.message="argument out of range",this.name="ArgumentOutOfRangeError",this}return r.prototype=Object.create(Error.prototype),r}();function g(r){return function(t){return 0===r?m():t.lift(new O(r))}}var O=function(){function r(r){if(this.total=r,this.total<0)throw new S}return r.prototype.call=function(r,t){return t.subscribe(new x(r,this.total))},r}(),x=function(r){function t(t,n){var e=r.call(this,t)||this;return e.total=n,e.count=0,e}return n(t,r),t.prototype._next=function(r){var t=this.total,n=++this.count;n<=t&&(this.destination.next(r),n===t&&(this.destination.complete(),this.unsubscribe()))},t}(l),T="http://localhost:3000";function P(r,t){var n=r+"__"+Math.random().toString(36).substr(3),e={requestId:n,type:r,data:t};return new v((function(r){var t=window.opener||window.parent,o=function(){t.postMessage({requestId:n,type:"cancellation",data:null},T)};return window.addEventListener("message",(function(t){var e=t.data;if(e&&e.requestId===n){if(e.complete)return r.complete(),void o();if(e.error)return r.error(e.data),void o();r.next(e.data)}})),t.postMessage(e,T),o}))}r.graphQlMutation=function(r,t){var n=P("graphql-mutation",{document:r,variables:t});return{then:function(){for(var r,t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(r=n.pipe(g(1)).toPromise()).then.apply(r,t)},stream:n}},r.graphQlQuery=function(r,t,n){var e=P("graphql-query",{document:r,variables:t,fetchPolicy:n});return{then:function(){for(var r,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(r=e.pipe(g(1)).toPromise()).then.apply(r,t)},stream:e}},r.notify=function(r){P("notification",r).toPromise()},r.setTargetOrigin=function(r){T=r},Object.defineProperty(r,"__esModule",{value:!0})}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdminUiAppConfig, AdminUiAppDevModeConfig } from '@vendure/common/lib/shared-types';
|
|
2
|
+
import { UiExtensionCompilerOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Compiles the Admin UI app with the specified extensions.
|
|
6
|
+
*
|
|
7
|
+
* @docsCategory UiDevkit
|
|
8
|
+
*/
|
|
9
|
+
export declare function compileUiExtensions(options: UiExtensionCompilerOptions): AdminUiAppConfig | AdminUiAppDevModeConfig;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.compileUiExtensions = void 0;
|
|
23
|
+
const child_process_1 = require("child_process");
|
|
24
|
+
const chokidar_1 = require("chokidar");
|
|
25
|
+
const fs = __importStar(require("fs-extra"));
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const constants_1 = require("./constants");
|
|
28
|
+
const scaffold_1 = require("./scaffold");
|
|
29
|
+
const translations_1 = require("./translations");
|
|
30
|
+
const utils_1 = require("./utils");
|
|
31
|
+
/**
|
|
32
|
+
* @description
|
|
33
|
+
* Compiles the Admin UI app with the specified extensions.
|
|
34
|
+
*
|
|
35
|
+
* @docsCategory UiDevkit
|
|
36
|
+
*/
|
|
37
|
+
function compileUiExtensions(options) {
|
|
38
|
+
const { outputPath, baseHref, devMode, watchPort, extensions } = options;
|
|
39
|
+
if (devMode) {
|
|
40
|
+
return runWatchMode(outputPath, baseHref || constants_1.DEFAULT_BASE_HREF, watchPort || 4200, extensions);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return runCompileMode(outputPath, baseHref || constants_1.DEFAULT_BASE_HREF, extensions);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.compileUiExtensions = compileUiExtensions;
|
|
47
|
+
function runCompileMode(outputPath, baseHref, extensions) {
|
|
48
|
+
const usingYarn = utils_1.shouldUseYarn();
|
|
49
|
+
const cmd = usingYarn ? 'yarn' : 'npm';
|
|
50
|
+
const distPath = path.join(outputPath, 'dist');
|
|
51
|
+
const compile = () => new Promise(async (resolve, reject) => {
|
|
52
|
+
await scaffold_1.setupScaffold(outputPath, extensions);
|
|
53
|
+
const commandArgs = ['run', 'build', `--outputPath=${distPath}`, `--base-href=${baseHref}`];
|
|
54
|
+
if (!usingYarn) {
|
|
55
|
+
// npm requires `--` before any command line args being passed to a script
|
|
56
|
+
commandArgs.splice(2, 0, '--');
|
|
57
|
+
}
|
|
58
|
+
const buildProcess = child_process_1.spawn(cmd, commandArgs, {
|
|
59
|
+
cwd: outputPath,
|
|
60
|
+
shell: true,
|
|
61
|
+
stdio: 'inherit',
|
|
62
|
+
});
|
|
63
|
+
buildProcess.on('close', code => {
|
|
64
|
+
if (code !== 0) {
|
|
65
|
+
reject(code);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolve();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
path: distPath,
|
|
74
|
+
compile,
|
|
75
|
+
route: baseHrefToRoute(baseHref),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function runWatchMode(outputPath, baseHref, port, extensions) {
|
|
79
|
+
const cmd = utils_1.shouldUseYarn() ? 'yarn' : 'npm';
|
|
80
|
+
const devkitPath = require.resolve('@vendure/ui-devkit');
|
|
81
|
+
let buildProcess;
|
|
82
|
+
let watcher;
|
|
83
|
+
let close = () => {
|
|
84
|
+
/* */
|
|
85
|
+
};
|
|
86
|
+
const compile = () => new Promise(async (resolve, reject) => {
|
|
87
|
+
await scaffold_1.setupScaffold(outputPath, extensions);
|
|
88
|
+
const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
|
|
89
|
+
const normalizedExtensions = utils_1.normalizeExtensions(adminUiExtensions);
|
|
90
|
+
const globalStylesExtensions = extensions.filter(utils_1.isGlobalStylesExtension);
|
|
91
|
+
const staticAssetExtensions = extensions.filter(utils_1.isStaticAssetExtension);
|
|
92
|
+
const allTranslationFiles = translations_1.getAllTranslationFiles(extensions.filter(utils_1.isTranslationExtension));
|
|
93
|
+
buildProcess = child_process_1.spawn(cmd, ['run', 'start', `--port=${port}`, `--base-href=${baseHref}`], {
|
|
94
|
+
cwd: outputPath,
|
|
95
|
+
shell: true,
|
|
96
|
+
stdio: 'inherit',
|
|
97
|
+
});
|
|
98
|
+
buildProcess.on('close', code => {
|
|
99
|
+
if (code !== 0) {
|
|
100
|
+
reject(code);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
resolve();
|
|
104
|
+
}
|
|
105
|
+
close();
|
|
106
|
+
});
|
|
107
|
+
for (const extension of normalizedExtensions) {
|
|
108
|
+
if (!watcher) {
|
|
109
|
+
watcher = chokidar_1.watch(extension.extensionPath, {
|
|
110
|
+
depth: 4,
|
|
111
|
+
ignored: '**/node_modules/',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
watcher.add(extension.extensionPath);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const extension of staticAssetExtensions) {
|
|
119
|
+
for (const staticAssetDef of extension.staticAssets) {
|
|
120
|
+
const assetPath = utils_1.getStaticAssetPath(staticAssetDef);
|
|
121
|
+
if (!watcher) {
|
|
122
|
+
watcher = chokidar_1.watch(assetPath);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
watcher.add(assetPath);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const extension of globalStylesExtensions) {
|
|
130
|
+
const globalStylePaths = Array.isArray(extension.globalStyles)
|
|
131
|
+
? extension.globalStyles
|
|
132
|
+
: [extension.globalStyles];
|
|
133
|
+
for (const stylePath of globalStylePaths) {
|
|
134
|
+
if (!watcher) {
|
|
135
|
+
watcher = chokidar_1.watch(stylePath);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
watcher.add(stylePath);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
for (const translationFiles of Object.values(allTranslationFiles)) {
|
|
143
|
+
if (!translationFiles) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
for (const file of translationFiles) {
|
|
147
|
+
if (!watcher) {
|
|
148
|
+
watcher = chokidar_1.watch(file);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
watcher.add(file);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (watcher) {
|
|
156
|
+
// watch the ui-devkit package files too
|
|
157
|
+
watcher.add(devkitPath);
|
|
158
|
+
}
|
|
159
|
+
if (watcher) {
|
|
160
|
+
const allStaticAssetDefs = staticAssetExtensions.reduce((defs, e) => [...defs, ...(e.staticAssets || [])], []);
|
|
161
|
+
const allGlobalStyles = globalStylesExtensions.reduce((defs, e) => [
|
|
162
|
+
...defs,
|
|
163
|
+
...(Array.isArray(e.globalStyles) ? e.globalStyles : [e.globalStyles]),
|
|
164
|
+
], []);
|
|
165
|
+
watcher.on('change', async (filePath) => {
|
|
166
|
+
const extension = normalizedExtensions.find(e => filePath.includes(e.extensionPath));
|
|
167
|
+
if (extension) {
|
|
168
|
+
const outputDir = path.join(outputPath, constants_1.MODULES_OUTPUT_DIR, extension.id);
|
|
169
|
+
const filePart = path.relative(extension.extensionPath, filePath);
|
|
170
|
+
const dest = path.join(outputDir, filePart);
|
|
171
|
+
await fs.copyFile(filePath, dest);
|
|
172
|
+
}
|
|
173
|
+
if (filePath.includes(devkitPath)) {
|
|
174
|
+
utils_1.copyUiDevkit(outputPath);
|
|
175
|
+
}
|
|
176
|
+
for (const staticAssetDef of allStaticAssetDefs) {
|
|
177
|
+
const assetPath = utils_1.getStaticAssetPath(staticAssetDef);
|
|
178
|
+
if (filePath.includes(assetPath)) {
|
|
179
|
+
await utils_1.copyStaticAsset(outputPath, staticAssetDef);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (const stylePath of allGlobalStyles) {
|
|
184
|
+
if (filePath.includes(stylePath)) {
|
|
185
|
+
await scaffold_1.copyGlobalStyleFile(outputPath, stylePath);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const languageCode of Object.keys(allTranslationFiles)) {
|
|
190
|
+
// tslint:disable-next-line:no-non-null-assertion
|
|
191
|
+
const translationFiles = allTranslationFiles[languageCode];
|
|
192
|
+
for (const file of translationFiles) {
|
|
193
|
+
if (filePath.includes(path.normalize(file))) {
|
|
194
|
+
await translations_1.mergeExtensionTranslations(outputPath, {
|
|
195
|
+
[languageCode]: translationFiles,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
resolve();
|
|
203
|
+
});
|
|
204
|
+
close = () => {
|
|
205
|
+
if (watcher) {
|
|
206
|
+
watcher.close();
|
|
207
|
+
}
|
|
208
|
+
if (buildProcess) {
|
|
209
|
+
buildProcess.kill();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
process.on('SIGINT', close);
|
|
213
|
+
return { sourcePath: outputPath, port, compile, route: baseHrefToRoute(baseHref) };
|
|
214
|
+
}
|
|
215
|
+
function baseHrefToRoute(baseHref) {
|
|
216
|
+
return baseHref.replace(/^\//, '').replace(/\/$/, '');
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compiler/compile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,iDAAoD;AACpD,uCAA6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,gBAAgB,GAAG,mBAAmB,CAAC,YAA4B,CAAE,CAAC;oBAC5E,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE;wBACjC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE;4BACzC,MAAM,yCAA0B,CAAC,UAAU,EAAE;gCACzC,CAAC,YAAY,CAAC,EAAE,gBAAgB;6BACnC,CAAC,CAAC;yBACN;qBACJ;iBACJ;YACL,CAAC,CAAC,CAAC;SACN;QACD,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;IAEP,KAAK,GAAG,GAAG,EAAE;QACT,IAAI,OAAO,EAAE;YACT,OAAO,CAAC,KAAK,EAAE,CAAC;SACnB;QACD,IAAI,YAAY,EAAE;YACd,YAAY,CAAC,IAAI,EAAE,CAAC;SACvB;IACL,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC5B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;AACvF,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACrC,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const STATIC_ASSETS_OUTPUT_DIR = "static-assets";
|
|
2
|
+
export declare const GLOBAL_STYLES_OUTPUT_DIR = "global-styles";
|
|
3
|
+
export declare const EXTENSION_ROUTES_FILE = "src/extension.routes.ts";
|
|
4
|
+
export declare const SHARED_EXTENSIONS_FILE = "src/shared-extensions.module.ts";
|
|
5
|
+
export declare const MODULES_OUTPUT_DIR = "src/extensions";
|
|
6
|
+
export declare const DEFAULT_BASE_HREF = "/admin/";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BASE_HREF = exports.MODULES_OUTPUT_DIR = exports.SHARED_EXTENSIONS_FILE = exports.EXTENSION_ROUTES_FILE = exports.GLOBAL_STYLES_OUTPUT_DIR = exports.STATIC_ASSETS_OUTPUT_DIR = void 0;
|
|
4
|
+
exports.STATIC_ASSETS_OUTPUT_DIR = 'static-assets';
|
|
5
|
+
exports.GLOBAL_STYLES_OUTPUT_DIR = 'global-styles';
|
|
6
|
+
exports.EXTENSION_ROUTES_FILE = 'src/extension.routes.ts';
|
|
7
|
+
exports.SHARED_EXTENSIONS_FILE = 'src/shared-extensions.module.ts';
|
|
8
|
+
exports.MODULES_OUTPUT_DIR = 'src/extensions';
|
|
9
|
+
exports.DEFAULT_BASE_HREF = '/admin/';
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/compiler/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,wBAAwB,GAAG,eAAe,CAAC;AAC3C,QAAA,wBAAwB,GAAG,eAAe,CAAC;AAC3C,QAAA,qBAAqB,GAAG,yBAAyB,CAAC;AAClD,QAAA,sBAAsB,GAAG,iCAAiC,CAAC;AAC3D,QAAA,kBAAkB,GAAG,gBAAgB,CAAC;AACtC,QAAA,iBAAiB,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BrandingOptions, StaticAssetExtension } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* A helper function to simplify the process of setting custom branding images.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```TypeScript
|
|
8
|
+
* compileUiExtensions({
|
|
9
|
+
* outputPath: path.join(__dirname, '../admin-ui'),
|
|
10
|
+
* extensions: [
|
|
11
|
+
* setBranding({
|
|
12
|
+
* smallLogoPath: path.join(__dirname, 'images/my-logo-sm.png'),
|
|
13
|
+
* largeLogoPath: path.join(__dirname, 'images/my-logo-lg.png'),
|
|
14
|
+
* faviconPath: path.join(__dirname, 'images/my-favicon.ico'),
|
|
15
|
+
* }),
|
|
16
|
+
* ],
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @docsCategory UiDevkit
|
|
21
|
+
* @docsPage helpers
|
|
22
|
+
*/
|
|
23
|
+
export declare function setBranding(options: BrandingOptions): StaticAssetExtension;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* ```TypeScript
|
|
10
|
+
* compileUiExtensions({
|
|
11
|
+
* outputPath: path.join(__dirname, '../admin-ui'),
|
|
12
|
+
* extensions: [
|
|
13
|
+
* setBranding({
|
|
14
|
+
* smallLogoPath: path.join(__dirname, 'images/my-logo-sm.png'),
|
|
15
|
+
* largeLogoPath: path.join(__dirname, 'images/my-logo-lg.png'),
|
|
16
|
+
* faviconPath: path.join(__dirname, 'images/my-favicon.ico'),
|
|
17
|
+
* }),
|
|
18
|
+
* ],
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @docsCategory UiDevkit
|
|
23
|
+
* @docsPage helpers
|
|
24
|
+
*/
|
|
25
|
+
function setBranding(options) {
|
|
26
|
+
const staticAssets = [];
|
|
27
|
+
if (options.smallLogoPath) {
|
|
28
|
+
staticAssets.push({
|
|
29
|
+
path: options.smallLogoPath,
|
|
30
|
+
rename: 'logo-75px.png',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (options.largeLogoPath) {
|
|
34
|
+
staticAssets.push({
|
|
35
|
+
path: options.largeLogoPath,
|
|
36
|
+
rename: 'logo-300px.png',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (options.faviconPath) {
|
|
40
|
+
staticAssets.push({
|
|
41
|
+
path: options.faviconPath,
|
|
42
|
+
rename: 'favicon.ico',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return { staticAssets };
|
|
46
|
+
}
|
|
47
|
+
exports.setBranding = setBranding;
|
|
48
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/compiler/helpers.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CAAC,OAAwB;IAChD,MAAM,YAAY,GAA4B,EAAE,CAAC;IACjD,IAAI,OAAO,CAAC,aAAa,EAAE;QACvB,YAAY,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,OAAO,CAAC,aAAa;YAC3B,MAAM,EAAE,eAAe;SAC1B,CAAC,CAAC;KACN;IACD,IAAI,OAAO,CAAC,aAAa,EAAE;QACvB,YAAY,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,OAAO,CAAC,aAAa;YAC3B,MAAM,EAAE,gBAAgB;SAC3B,CAAC,CAAC;KACN;IACD,IAAI,OAAO,CAAC,WAAW,EAAE;QACrB,YAAY,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,OAAO,CAAC,WAAW;YACzB,MAAM,EAAE,aAAa;SACxB,CAAC,CAAC;KACN;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;AAC5B,CAAC;AArBD,kCAqBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./compile"), exports);
|
|
14
|
+
__exportStar(require("./helpers"), exports);
|
|
15
|
+
__exportStar(require("./types"), exports);
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/compiler/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.copyGlobalStyleFile = exports.setupScaffold = void 0;
|
|
23
|
+
/* tslint:disable:no-console */
|
|
24
|
+
const child_process_1 = require("child_process");
|
|
25
|
+
const fs = __importStar(require("fs-extra"));
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const constants_1 = require("./constants");
|
|
28
|
+
const translations_1 = require("./translations");
|
|
29
|
+
const utils_1 = require("./utils");
|
|
30
|
+
async function setupScaffold(outputPath, extensions) {
|
|
31
|
+
deleteExistingExtensionModules(outputPath);
|
|
32
|
+
copyAdminUiSource(outputPath);
|
|
33
|
+
const adminUiExtensions = extensions.filter(utils_1.isAdminUiExtension);
|
|
34
|
+
const normalizedExtensions = utils_1.normalizeExtensions(adminUiExtensions);
|
|
35
|
+
await copyExtensionModules(outputPath, normalizedExtensions);
|
|
36
|
+
const staticAssetExtensions = extensions.filter(utils_1.isStaticAssetExtension);
|
|
37
|
+
await copyStaticAssets(outputPath, staticAssetExtensions);
|
|
38
|
+
const globalStyleExtensions = extensions.filter(utils_1.isGlobalStylesExtension);
|
|
39
|
+
await addGlobalStyles(outputPath, globalStyleExtensions);
|
|
40
|
+
const allTranslationFiles = translations_1.getAllTranslationFiles(extensions.filter(utils_1.isTranslationExtension));
|
|
41
|
+
await translations_1.mergeExtensionTranslations(outputPath, allTranslationFiles);
|
|
42
|
+
utils_1.copyUiDevkit(outputPath);
|
|
43
|
+
try {
|
|
44
|
+
await checkIfNgccWasRun();
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
const cmd = utils_1.shouldUseYarn() ? 'yarn ngcc' : 'npx ngcc';
|
|
48
|
+
utils_1.logger.log(`An error occurred when running ngcc. Try removing node_modules, re-installing, and then manually running "${cmd}" in the project root.`);
|
|
49
|
+
}
|
|
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
|
+
* Copies all files from the extensionPaths of the configured extensions into the
|
|
61
|
+
* admin-ui source tree.
|
|
62
|
+
*/
|
|
63
|
+
async function copyExtensionModules(outputPath, extensions) {
|
|
64
|
+
const extensionRoutesSource = generateLazyExtensionRoutes(extensions);
|
|
65
|
+
fs.writeFileSync(path.join(outputPath, constants_1.EXTENSION_ROUTES_FILE), extensionRoutesSource, 'utf8');
|
|
66
|
+
const sharedExtensionModulesSource = generateSharedExtensionModule(extensions);
|
|
67
|
+
fs.writeFileSync(path.join(outputPath, constants_1.SHARED_EXTENSIONS_FILE), sharedExtensionModulesSource, 'utf8');
|
|
68
|
+
for (const extension of extensions) {
|
|
69
|
+
const dest = path.join(outputPath, constants_1.MODULES_OUTPUT_DIR, extension.id);
|
|
70
|
+
fs.copySync(extension.extensionPath, dest);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function copyStaticAssets(outputPath, extensions) {
|
|
74
|
+
for (const extension of extensions) {
|
|
75
|
+
if (Array.isArray(extension.staticAssets)) {
|
|
76
|
+
for (const asset of extension.staticAssets) {
|
|
77
|
+
await utils_1.copyStaticAsset(outputPath, asset);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function addGlobalStyles(outputPath, extensions) {
|
|
83
|
+
const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
|
|
84
|
+
await fs.remove(globalStylesDir);
|
|
85
|
+
await fs.ensureDir(globalStylesDir);
|
|
86
|
+
const imports = [];
|
|
87
|
+
for (const extension of extensions) {
|
|
88
|
+
const styleFiles = Array.isArray(extension.globalStyles)
|
|
89
|
+
? extension.globalStyles
|
|
90
|
+
: [extension.globalStyles];
|
|
91
|
+
for (const styleFile of styleFiles) {
|
|
92
|
+
await copyGlobalStyleFile(outputPath, styleFile);
|
|
93
|
+
imports.push(path.basename(styleFile, path.extname(styleFile)));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const globalStylesSource = `@import "./styles/styles";\n` +
|
|
97
|
+
imports.map(file => `@import "./${constants_1.GLOBAL_STYLES_OUTPUT_DIR}/${file}";`).join('\n');
|
|
98
|
+
const globalStylesFile = path.join(outputPath, 'src', 'global-styles.scss');
|
|
99
|
+
await fs.writeFile(globalStylesFile, globalStylesSource, 'utf-8');
|
|
100
|
+
}
|
|
101
|
+
async function copyGlobalStyleFile(outputPath, stylePath) {
|
|
102
|
+
const globalStylesDir = path.join(outputPath, 'src', constants_1.GLOBAL_STYLES_OUTPUT_DIR);
|
|
103
|
+
const fileBasename = path.basename(stylePath);
|
|
104
|
+
const styleOutputPath = path.join(globalStylesDir, fileBasename);
|
|
105
|
+
await fs.copyFile(stylePath, styleOutputPath);
|
|
106
|
+
}
|
|
107
|
+
exports.copyGlobalStyleFile = copyGlobalStyleFile;
|
|
108
|
+
function generateLazyExtensionRoutes(extensions) {
|
|
109
|
+
const routes = [];
|
|
110
|
+
for (const extension of extensions) {
|
|
111
|
+
for (const module of extension.ngModules) {
|
|
112
|
+
if (module.type === 'lazy') {
|
|
113
|
+
routes.push(` {
|
|
114
|
+
path: 'extensions/${module.route}',
|
|
115
|
+
loadChildren: () => import('${getModuleFilePath(extension.id, module)}').then(m => m.${module.ngModuleName}),
|
|
116
|
+
}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return `export const extensionRoutes = [${routes.join(',\n')}];\n`;
|
|
121
|
+
}
|
|
122
|
+
function generateSharedExtensionModule(extensions) {
|
|
123
|
+
return `import { NgModule } from '@angular/core';
|
|
124
|
+
import { CommonModule } from '@angular/common';
|
|
125
|
+
${extensions
|
|
126
|
+
.map(e => e.ngModules
|
|
127
|
+
.filter(m => m.type === 'shared')
|
|
128
|
+
.map(m => `import { ${m.ngModuleName} } from '${getModuleFilePath(e.id, m)}';\n`)
|
|
129
|
+
.join(''))
|
|
130
|
+
.join('')}
|
|
131
|
+
|
|
132
|
+
@NgModule({
|
|
133
|
+
imports: [CommonModule, ${extensions
|
|
134
|
+
.map(e => e.ngModules
|
|
135
|
+
.filter(m => m.type === 'shared')
|
|
136
|
+
.map(m => m.ngModuleName)
|
|
137
|
+
.join(', '))
|
|
138
|
+
.join(', ')}],
|
|
139
|
+
})
|
|
140
|
+
export class SharedExtensionsModule {}
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
function getModuleFilePath(id, module) {
|
|
144
|
+
return `./extensions/${id}/${path.basename(module.ngModuleFileName, '.ts')}`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Copy the Admin UI sources & static assets to the outputPath if it does not already
|
|
148
|
+
* exists there.
|
|
149
|
+
*/
|
|
150
|
+
function copyAdminUiSource(outputPath) {
|
|
151
|
+
const angularJsonFile = path.join(outputPath, 'angular.json');
|
|
152
|
+
const indexFile = path.join(outputPath, '/src/index.html');
|
|
153
|
+
if (fs.existsSync(angularJsonFile) && fs.existsSync(indexFile)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const scaffoldDir = path.join(__dirname, '../scaffold');
|
|
157
|
+
const adminUiSrc = path.join(require.resolve('@vendure/admin-ui'), '../../static');
|
|
158
|
+
if (!fs.existsSync(scaffoldDir)) {
|
|
159
|
+
throw new Error(`Could not find the admin ui scaffold files at ${scaffoldDir}`);
|
|
160
|
+
}
|
|
161
|
+
if (!fs.existsSync(adminUiSrc)) {
|
|
162
|
+
throw new Error(`Could not find the @vendure/admin-ui sources. Looked in ${adminUiSrc}`);
|
|
163
|
+
}
|
|
164
|
+
// copy scaffold
|
|
165
|
+
fs.removeSync(outputPath);
|
|
166
|
+
fs.ensureDirSync(outputPath);
|
|
167
|
+
fs.copySync(scaffoldDir, outputPath);
|
|
168
|
+
// copy source files from admin-ui package
|
|
169
|
+
const outputSrc = path.join(outputPath, 'src');
|
|
170
|
+
fs.ensureDirSync(outputSrc);
|
|
171
|
+
fs.copySync(adminUiSrc, outputSrc);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Attempts to find out it the ngcc compiler has been run on the Angular packages, and if not,
|
|
175
|
+
* attemps to run it. This is done this way because attempting to run ngcc from a sub-directory
|
|
176
|
+
* where the angular libs are in a higher-level node_modules folder currently results in the error
|
|
177
|
+
* NG6002, see https://github.com/angular/angular/issues/35747.
|
|
178
|
+
*
|
|
179
|
+
* However, when ngcc is run from the root, it works.
|
|
180
|
+
*/
|
|
181
|
+
async function checkIfNgccWasRun() {
|
|
182
|
+
const coreUmdFile = require.resolve('@vendure/admin-ui/core');
|
|
183
|
+
if (!coreUmdFile) {
|
|
184
|
+
utils_1.logger.error(`Could not resolve the "@vendure/admin-ui/core" package!`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// ngcc creates a particular folder after it has been run once
|
|
188
|
+
const ivyDir = path.join(coreUmdFile, '../..', '__ivy_ngcc__');
|
|
189
|
+
if (fs.existsSync(ivyDir)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// Looks like ngcc has not been run, so attempt to do so.
|
|
193
|
+
const rootDir = coreUmdFile.split('node_modules')[0];
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
utils_1.logger.log('Running the Angular Ivy compatibility compiler (ngcc) on Vendure Admin UI dependencies ' +
|
|
196
|
+
'(this is only needed on the first run)...');
|
|
197
|
+
const cmd = utils_1.shouldUseYarn() ? 'yarn' : 'npx';
|
|
198
|
+
const ngccProcess = child_process_1.spawn(cmd, [
|
|
199
|
+
'ngcc',
|
|
200
|
+
'--properties es2015 browser module main',
|
|
201
|
+
'--first-only',
|
|
202
|
+
'--create-ivy-entry-points',
|
|
203
|
+
'-l=error',
|
|
204
|
+
], {
|
|
205
|
+
cwd: rootDir,
|
|
206
|
+
shell: true,
|
|
207
|
+
stdio: 'inherit',
|
|
208
|
+
});
|
|
209
|
+
ngccProcess.on('close', code => {
|
|
210
|
+
if (code !== 0) {
|
|
211
|
+
reject(code);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
resolve();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=scaffold.js.map
|