Răsfoiți Sursa

refactor: Rework the admin-ui package structure

Michael Bromley 6 ani în urmă
părinte
comite
aad30d61e2

+ 1 - 1
package.json

@@ -17,7 +17,7 @@
     "version": "yarn check-imports && yarn build && yarn generate-changelog && git add CHANGELOG.md",
     "dev-server:start": "cd packages/dev-server && yarn start",
     "dev-server:populate": "cd packages/dev-server && yarn populate",
-    "test:all": "yarn test:admin-ui && yarn test:common && yarn test:core && yarn test:email-plugin && yarn test:elasticsearch-plugin && yarn test:e2e",
+    "test:all": "yarn test:admin-ui && cd ../ && yarn test:common && yarn test:core && yarn test:email-plugin && yarn test:elasticsearch-plugin && yarn test:e2e",
     "test:common": "jest --config packages/common/jest.config.js",
     "test:core": "jest --config packages/core/jest.config.js",
     "test:email-plugin": "jest --config packages/email-plugin/jest.config.js --maxWorkers=1",

+ 1 - 2
packages/admin-ui-plugin/src/ui-app-compiler.service.ts

@@ -1,6 +1,5 @@
 import { Injectable } from '@nestjs/common';
-import { compileAdminUiApp } from '@vendure/admin-ui/devkit/compile';
-import { watchAdminUiApp, Watcher } from '@vendure/admin-ui/devkit/watch';
+import { compileAdminUiApp, watchAdminUiApp, Watcher } from '@vendure/admin-ui/devkit';
 import { AdminUiExtension } from '@vendure/common/lib/shared-types';
 import { Logger } from '@vendure/core';
 import crypto from 'crypto';

+ 1 - 3
packages/admin-ui/.gitignore

@@ -14,9 +14,7 @@
 /src/app/extensions/extensions.module.ts.temp
 
 # compiled devkit files
-/devkit/*.js
-/devkit/*.d.ts
-/devkit/*.js.map
+/devkit
 
 # IDEs and editors
 /.idea

+ 0 - 12
packages/admin-ui/devkit/extensions.module.ts.template

@@ -1,12 +0,0 @@
-import { CommonModule } from '@angular/common';
-import { NgModule } from '@angular/core';
-
-/**
- * This is a placeholder module for UI extensions provided by the AdminUiPlugin `extensions` option.
- * When the {@link compileUiExtensions} function is executed, this module gets temporarily replaced
- * by a generated module which includes all of the configured extension modules.
- */
-@NgModule({
-    imports: [CommonModule],
-})
-export class ExtensionsModule {}

+ 0 - 12
packages/admin-ui/devkit/index.ts

@@ -1,12 +0,0 @@
-// This is the "public API" of the admin-ui package, used by plugins which want to define
-// extensions to the admin UI and need to import components (services, modules etc) from the admin-ui.
-
-export { JobQueueService } from '../src/app/core/providers/job-queue/job-queue.service';
-export { LocalStorageService } from '../src/app/core/providers/local-storage/local-storage.service';
-export { NotificationService } from '../src/app/core/providers/notification/notification.service';
-export { DataModule } from '../src/app/data/data.module';
-export { DataService } from '../src/app/data/providers/data.service';
-export { ServerConfigService } from '../src/app/data/server-config';
-export { ModalService } from '../src/app/shared/providers/modal/modal.service';
-export { SharedModule } from '../src/app/shared/shared.module';
-export * from '../src/app/shared/shared-declarations';

+ 21 - 7
packages/admin-ui/devkit/common.ts → packages/admin-ui/src/devkit/common.ts

@@ -14,13 +14,6 @@ export function isInVendureMonorepo(): boolean {
     return fs.existsSync(path.join(__dirname, '../../dev-server'));
 }
 
-/**
- * Restores the placeholder ExtensionsModule file from a template.
- */
-export function restoreExtensionsModule() {
-    fs.copyFileSync(path.join(__dirname, 'extensions.module.ts.template'), originalExtensionsModuleFile);
-}
-
 /**
  * Deletes the contents of the /modules directory, which contains the plugin
  * extension modules copied over during the last compilation.
@@ -62,6 +55,27 @@ export function restoreOriginalExtensionsModule() {
     restoreExtensionsModule();
 }
 
+/**
+ * Restores the placeholder ExtensionsModule file from a template.
+ */
+export function restoreExtensionsModule() {
+    const source = `
+import { CommonModule } from '@angular/common';
+import { NgModule } from '@angular/core';
+
+/**
+ * This is a placeholder module for UI extensions provided by the AdminUiPlugin \`extensions\` option.
+ * When the {@link compileUiExtensions} function is executed, this module gets temporarily replaced
+ * by a generated module which includes all of the configured extension modules.
+ */
+@NgModule({
+    imports: [CommonModule],
+})
+export class ExtensionsModule {}
+`;
+    fs.writeFileSync(originalExtensionsModuleFile, source, 'utf-8');
+}
+
 function generateExtensionModuleTsSource(modules: Array<{ className: string; path: string }>): string {
     return `/** This file is generated by the build() function. Do not edit. */
 import { CommonModule } from '@angular/common';

+ 0 - 0
packages/admin-ui/devkit/compile.ts → packages/admin-ui/src/devkit/compile.ts


+ 2 - 0
packages/admin-ui/src/devkit/index.ts

@@ -0,0 +1,2 @@
+export * from './compile';
+export * from './watch';

+ 0 - 0
packages/admin-ui/devkit/watch.ts → packages/admin-ui/src/devkit/watch.ts


+ 12 - 0
packages/admin-ui/src/index.ts

@@ -0,0 +1,12 @@
+// This is the "public API" of the admin-ui package, used by plugins which want to define
+// extensions to the admin UI and need to import components (services, modules etc) from the admin-ui.
+
+export { JobQueueService } from './app/core/providers/job-queue/job-queue.service';
+export { LocalStorageService } from './app/core/providers/local-storage/local-storage.service';
+export { NotificationService } from './app/core/providers/notification/notification.service';
+export { DataModule } from './app/data/data.module';
+export { DataService } from './app/data/providers/data.service';
+export { ServerConfigService } from './app/data/server-config';
+export { ModalService } from './app/shared/providers/modal/modal.service';
+export { SharedModule } from './app/shared/shared.module';
+export * from './app/shared/shared-declarations';

+ 1 - 2
packages/admin-ui/tsconfig.devkit.json

@@ -15,8 +15,7 @@
     ]
   },
   "files": [
-    "devkit/compile.ts",
-    "devkit/watch.ts"
+    "src/devkit/index.ts"
   ],
   "exclude": [
     "src/**/*"

+ 1 - 1
packages/admin-ui/tsconfig.json

@@ -25,7 +25,7 @@
     ],
     "paths": {
       "shared/*": ["../common/lib/*"],
-      "@vendure/admin-ui/*": ["./*"]
+      "@vendure/admin-ui/src/*": ["./src/*"]
     }
   }
 }

+ 1 - 1
packages/core/package.json

@@ -97,6 +97,6 @@
     "rimraf": "^2.6.3",
     "sql.js": "^1.0.0",
     "sqlite3": "^4.0.6",
-    "typescript": "~3.5.3"
+    "typescript": "~3.6.2"
   }
 }

+ 4 - 0
packages/core/src/api/config/generate-list-options.ts

@@ -67,6 +67,10 @@ export function generateListOptions(typeDefsOrSchema: string | GraphQLSchema): G
                 query.args.push({
                     name: 'options',
                     type: listOptionsInput,
+                    description: null,
+                    defaultValue: null,
+                    extensions: null,
+                    astNode: null,
                 });
             }
 

+ 14 - 7
packages/core/src/api/config/graphql-custom-fields.ts

@@ -31,9 +31,11 @@ export function addGraphQLCustomFields(
     }
 
     for (const entityName of Object.keys(customFieldConfig)) {
-        const customEntityFields = (customFieldConfig[entityName as keyof CustomFields] || []).filter(config => {
-            return (publicOnly === true) ? config.public !== false : true;
-        });
+        const customEntityFields = (customFieldConfig[entityName as keyof CustomFields] || []).filter(
+            config => {
+                return publicOnly === true ? config.public !== false : true;
+            },
+        );
 
         const localeStringFields = customEntityFields.filter(field => field.type === 'localeString');
         const nonLocaleStringFields = customEntityFields.filter(field => field.type !== 'localeString');
@@ -204,10 +206,18 @@ export function addOrderLineCustomFieldsInput(
     addItemToOrderMutation.args.push({
         name: 'customFields',
         type: input,
+        description: null,
+        defaultValue: null,
+        extensions: null,
+        astNode: null,
     });
     adjustOrderLineMutation.args.push({
         name: 'customFields',
         type: input,
+        description: null,
+        defaultValue: null,
+        extensions: null,
+        astNode: null,
     });
 
     return new GraphQLSchema(schemaConfig);
@@ -218,10 +228,7 @@ type GraphQLFieldType = 'DateTime' | 'String' | 'Int' | 'Float' | 'Boolean' | 'I
 /**
  * Maps an array of CustomFieldConfig objects into a string of SDL fields.
  */
-function mapToFields(
-    fieldDefs: CustomFieldConfig[],
-    typeFn: (fieldType: CustomFieldType) => string,
-): string {
+function mapToFields(fieldDefs: CustomFieldConfig[], typeFn: (fieldType: CustomFieldType) => string): string {
     return fieldDefs.map(field => `${field.name}: ${typeFn(field.type)}`).join('\n');
 }
 

+ 1 - 2
packages/core/src/entity/product/product.entity.ts

@@ -1,6 +1,5 @@
 import { DeepPartial } from '@vendure/common/lib/shared-types';
-import { doc } from 'prettier';
-import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany } from 'typeorm';
+import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany } from 'typeorm';
 
 import { ChannelAware, SoftDeletable } from '../../common/types/common-types';
 import { LocaleString, Translatable, Translation } from '../../common/types/locale-types';

+ 2 - 2
packages/core/src/i18n/i18n.service.ts

@@ -28,8 +28,8 @@ export class I18nService implements OnModuleInit {
     onModuleInit() {
         return i18next
             .use(i18nextMiddleware.LanguageDetector)
-            .use(Backend)
-            .use(ICU)
+            .use(Backend as any)
+            .use(ICU as any)
             .init({
                 preload: ['en', 'de'],
                 fallbackLng: 'en',

+ 1 - 0
packages/dev-server/dev-config.ts

@@ -74,6 +74,7 @@ export const devConfig: VendureConfig = {
         AdminUiPlugin.init({
             port: 5001,
             extensions: UiPlugin.uiExtensions,
+            watch: true,
         }),
     ],
 };

+ 5 - 3
packages/dev-server/ui-plugin/module/ui-plugin.module.ts

@@ -1,6 +1,6 @@
 import { Component, NgModule } from '@angular/core';
 import { RouterModule } from '@angular/router';
-import { ModalService, SharedModule } from '@vendure/admin-ui/devkit';
+import { ModalService, SharedModule } from '@vendure/admin-ui/src';
 
 @Component({
     selector: 'plugin-test-component',
@@ -17,9 +17,11 @@ export class TestComponent {
             .dialog({
                 title: 'Did it work?',
                 buttons: [{ label: 'Yes!!!!', returnValue: true, type: 'primary' }],
-                // tslint:disable-next-line:no-console
             })
-            .subscribe(val => console.log(val));
+            .subscribe(val => {
+                // tslint:disable-next-line:no-console
+                console.log(val);
+            });
     }
 }
 

+ 12 - 7
packages/email-plugin/src/dev-mailbox.ts

@@ -1,11 +1,10 @@
+import { LanguageCode } from '@vendure/common/lib/generated-types';
 import { Channel, RequestContext } from '@vendure/core';
 import express from 'express';
 import fs from 'fs-extra';
 import http from 'http';
 import path from 'path';
 
-import { LanguageCode } from '../../common/lib/generated-types';
-
 import { EmailEventHandler } from './event-listener';
 import { EmailPluginDevModeOptions, EventWithContext } from './types';
 
@@ -14,7 +13,10 @@ import { EmailPluginDevModeOptions, EventWithContext } from './types';
  */
 export class DevMailbox {
     server: http.Server;
-    private handleMockEventFn: (handler: EmailEventHandler<string, any>, event: EventWithContext) => void | undefined;
+    private handleMockEventFn: (
+        handler: EmailEventHandler<string, any>,
+        event: EventWithContext,
+    ) => void | undefined;
 
     serve(options: EmailPluginDevModeOptions) {
         const { outputPath, handlers, mailboxPort } = options;
@@ -36,19 +38,22 @@ export class DevMailbox {
                 const handler = handlers.find(h => h.type === type);
                 if (!handler || !handler.mockEvent) {
                     res.statusCode = 404;
-                    res.send({ success: false, error: `No mock event registered for type "${type}"`});
+                    res.send({ success: false, error: `No mock event registered for type "${type}"` });
                     return;
                 }
                 try {
-                    await this.handleMockEventFn(handler, { ...handler.mockEvent, ctx: this.createRequestContext(languageCode) });
+                    await this.handleMockEventFn(handler, {
+                        ...handler.mockEvent,
+                        ctx: this.createRequestContext(languageCode as LanguageCode),
+                    });
                     res.send({ success: true });
                 } catch (e) {
                     res.statusCode = 500;
-                    res.send({success: false, error: e.message });
+                    res.send({ success: false, error: e.message });
                 }
                 return;
             } else {
-                res.send({success: false, error: `Mock email generation not set up.`});
+                res.send({ success: false, error: `Mock email generation not set up.` });
             }
         });
         server.get('/item/:id', async (req, res) => {

Fișier diff suprimat deoarece este prea mare
+ 431 - 360
yarn.lock


Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff