Explorar o código

feat(server): Export AdminUiPlugin, include in default init config

Closes #50
Michael Bromley %!s(int64=7) %!d(string=hai) anos
pai
achega
8aa0dff369

+ 5 - 1
server/build/gulpfile.ts

@@ -26,7 +26,11 @@ function buildAdminUi() {
         {
             cwd: path.join(__dirname, '../../admin-ui'),
         },
-        error => console.log(error),
+        error => {
+            if (error) {
+                console.log(error);
+            }
+        },
     );
 }
 

+ 12 - 12
server/cli/assets/sample-products.csv

@@ -1,12 +1,12 @@
-name           , slug           , description                                                                                                                                                                                                                                                                  , assets                              , optionGroups       , optionValues    , sku         , price   , taxCategory , variantAssets
-Spiky Cactus   , spiky-cactus   , "A spiky yet elegant house cactus - perfect for the home or office. Origin and habitat: Probably native only to the Andes of Peru"                                                                                                                                           , charles-deluvio-695736-unsplash.jpg ,                    ,                 , SC011001    , 15.50   , standard    ,
-Running Shoe   , running-shoe   , "With its ultra-light, uber-responsive magic foam and a carbon fiber plate that feels like it’s propelling you forward, the Running Shoe is ready to push you to victories both large and small"                                                                             , chuttersnap-584518-unsplash.jpg     , shoe size          , Size 40         , RS0040      , 99.99   , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , Size 42         , RS0042      , 99.99   , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , Size 44         , RS0044      , 99.99   , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , Size 46         , RS0046      , 99.99   , standard    ,
-Laptop         , laptop         , "Now equipped with seventh-generation Intel Core processors, Laptop is snappier than ever. From daily tasks like launching apps and opening files to more advanced computing, you can power through your day thanks to faster SSDs and Turbo Boost processing up to 3.6GHz." , derick-david-409858-unsplash.jpg    , "screen size, RAM" , "13 inch, 8GB"  , L2201308    , 1299.00 , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , "15 inch, 8GB"  , L2201508    , 1399.00 , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , "13 inch, 16GB" , L2201316    , 2199.00 , standard    ,
-               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                    , "15 inch, 16GB" , L2201516    , 2299.00 , standard    ,
-Instant Camera , instant-camera , "With its nostalgic design and simple point-and-shoot functionality, the Instant Camera is the perfect pick to get started with instant photography."                                                                                                                        , eniko-kis-663725-unsplash.jpg       ,                    ,                 , IC22MWDD    , 174.99  , standard    ,
-Road Bike      , road-bike      , "Featuring a full carbon chassis - complete with cyclocross-specific carbon fork - and a component setup geared for hard use on the race circuit, it's got the low weight, exceptional efficiency and brilliant handling you'll need to stay at the front of the pack."      , mikkel-bech-748940-unsplash.jpg     ,                    ,                 , RB000844334 , 2499.00 , standard    ,
+name           , slug           , description                                                                                                                                                                                                                                                                  , assets                              , facets                    , optionGroups       , optionValues    , sku         , price   , taxCategory , variantAssets , variantFacets
+Spiky Cactus   , spiky-cactus   , "A spiky yet elegant house cactus - perfect for the home or office. Origin and habitat: Probably native only to the Andes of Peru"                                                                                                                                           , charles-deluvio-695736-unsplash.jpg , category:home & garden    ,                    ,                 , SC011001    , 15.50   , standard    ,               ,
+Running Shoe   , running-shoe   , "With its ultra-light, uber-responsive magic foam and a carbon fiber plate that feels like it’s propelling you forward, the Running Shoe is ready to push you to victories both large and small"                                                                             , chuttersnap-584518-unsplash.jpg     , category:sports equipment , shoe size          , Size 40         , RS0040      , 99.99   , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , Size 42         , RS0042      , 99.99   , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , Size 44         , RS0044      , 99.99   , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , Size 46         , RS0046      , 99.99   , standard    ,               ,
+Laptop         , laptop         , "Now equipped with seventh-generation Intel Core processors, Laptop is snappier than ever. From daily tasks like launching apps and opening files to more advanced computing, you can power through your day thanks to faster SSDs and Turbo Boost processing up to 3.6GHz." , derick-david-409858-unsplash.jpg    , category:electronics      , "screen size, RAM" , "13 inch, 8GB"  , L2201308    , 1299.00 , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , "15 inch, 8GB"  , L2201508    , 1399.00 , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , "13 inch, 16GB" , L2201316    , 2199.00 , standard    ,               ,
+               ,                ,                                                                                                                                                                                                                                                                              ,                                     ,                           ,                    , "15 inch, 16GB" , L2201516    , 2299.00 , standard    ,               ,
+Instant Camera , instant-camera , "With its nostalgic design and simple point-and-shoot functionality, the Instant Camera is the perfect pick to get started with instant photography."                                                                                                                        , eniko-kis-663725-unsplash.jpg       , category:electronics      ,                    ,                 , IC22MWDD    , 174.99  , standard    ,               ,
+Road Bike      , road-bike      , "Featuring a full carbon chassis - complete with cyclocross-specific carbon fork - and a component setup geared for hard use on the race circuit, it's got the low weight, exceptional efficiency and brilliant handling you'll need to stay at the front of the pack."      , mikkel-bech-748940-unsplash.jpg     , category:sports equipment ,                    ,                 , RB000844334 , 2499.00 , standard    ,               ,

+ 13 - 5
server/cli/assets/vendure-config.hbs

@@ -1,4 +1,5 @@
 {{#if isTs }}import{{ else }}const{{/if}} {
+    AdminUiPlugin,
     examplePaymentHandler,
     DefaultAssetServerPlugin,
     DefaultEmailPlugin,
@@ -12,7 +13,6 @@ const path = require('path');
 {{/if}}
 
 {{#if isTs}}export {{/if}}const config{{#if isTs}}: VendureConfig{{/if}} = {
-    defaultChannelToken: 'default-channel',
     authOptions: {
         sessionSecret: '{{ sessionSecret }}',
     },
@@ -20,11 +20,18 @@ const path = require('path');
     apiPath: 'api',
     dbConnectionOptions: {
         type: '{{ dbType }}',
+        {{#if requiresConnection}}
         synchronize: true, // turn this off for production
-        logging: false,
-        database: '{{ dbName }}',
-        {{#if isSQLite}}
         {{else}}
+        synchronize: false, // not working with SQLite/SQL.js, see https://github.com/typeorm/typeorm/issues/2576
+        {{/if}}
+        logging: false,
+        database: {{#if isSQLjs}}new Uint8Array([]){{else}}'{{ normalizedDbName }}'{{/if}},
+        {{#if isSQLjs}}
+        location: '{{ normalizedDbName }}',
+        autoSave: true,
+        {{/if}}
+        {{#if requiresConnection}}
         host: '{{ dbHost }}',
         port: {{ dbPort }},
         username: '{{ dbUserName }}',
@@ -42,13 +49,14 @@ const path = require('path');
         new DefaultAssetServerPlugin({
             route: 'assets',
             assetUploadDir: path.join(__dirname, 'vendure/assets'),
-            port: 4000,
+            port: 3001,
         }),
         new DefaultEmailPlugin({
             templatePath: path.join(__dirname, 'vendure/email/templates'),
             devMode: true,
         }),
         new DefaultSearchPlugin(),
+        new AdminUiPlugin({ port: 3002 }),
     ],
 };
 {{#if isTs}}

+ 23 - 7
server/cli/init.ts

@@ -41,19 +41,20 @@ export async function init(): Promise<string> {
                     { title: 'MySQL / MariaDB', value: 'mysql' },
                     { title: 'Postgres', value: 'postgres' },
                     { title: 'SQLite', value: 'sqlite' },
+                    { title: 'SQL.js', value: 'sqljs' },
                     { title: 'MS SQL Server', value: 'mssql' },
                     { title: 'Oracle', value: 'oracle' },
                 ],
                 initial: 0 as any,
             },
             {
-                type: (() => (dbType === 'sqlite' ? null : 'text')) as any,
+                type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 name: 'dbHost',
                 message: `What's the database host address?`,
                 initial: '192.168.99.100',
             },
             {
-                type: (() => (dbType === 'sqlite' ? null : 'text')) as any,
+                type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 name: 'dbPort',
                 message: `What port is the database listening on?`,
                 initial: (() => defaultPort(dbType)) as any,
@@ -62,20 +63,22 @@ export async function init(): Promise<string> {
                 type: 'text',
                 name: 'dbName',
                 message: () =>
-                    dbType === 'sqlite'
-                        ? `What is the path to the SQLite database file?`
+                    dbType === 'sqlite' || dbType === 'sqljs'
+                        ? `What is the path to the database file?`
                         : `What's the name of the database?`,
                 initial: (() =>
-                    dbType === 'sqlite' ? path.join(__dirname, 'vendure.sqlite') : 'vendure') as any,
+                    dbType === 'sqlite' || dbType === 'sqljs'
+                        ? path.join(process.cwd(), 'vendure.sqlite')
+                        : 'vendure') as any,
             },
             {
-                type: (() => (dbType === 'sqlite' ? null : 'text')) as any,
+                type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 name: 'dbUserName',
                 message: `What's the database user name?`,
                 initial: 'root',
             },
             {
-                type: (() => (dbType === 'sqlite' ? null : 'password')) as any,
+                type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'password')) as any,
                 name: 'dbPassword',
                 message: `What's the database password?`,
             },
@@ -138,6 +141,12 @@ async function createFilesForBootstrap(answers: any): Promise<string> {
         ...answers,
         isTs: answers.language === 'ts',
         isSQLite: answers.dbType === 'sqlite',
+        isSQLjs: answers.dbType === 'sqljs',
+        requiresConnection: answers.dbType !== 'sqlite' && answers.dbType !== 'sqljs',
+        normalizedDbName:
+            answers.dbType === 'sqlite' || answers.dbType === 'sqljs'
+                ? normalizeFilePath(answers.dbName)
+                : answers.dbName,
         sessionSecret: Math.random()
             .toString(36)
             .substr(3),
@@ -151,3 +160,10 @@ async function createFilesForBootstrap(answers: any): Promise<string> {
 
     return filePath('index');
 }
+
+/**
+ * Escape backslashed for Windows file paths.
+ */
+function normalizeFilePath(filePath: string): string {
+    return String.raw`${filePath}`.replace(/\\/g, '\\\\');
+}

+ 2 - 1
server/src/plugin/default-search-plugin/fulltext-search.service.ts

@@ -121,6 +121,7 @@ export class FulltextSearchService {
         FindOptionsUtils.applyFindManyOptionsOrConditionsToQueryBuilder(qb, {
             relations: this.variantRelations,
         });
+        FindOptionsUtils.joinEagerRelations(qb, qb.alias, this.connection.getMetadata(ProductVariant));
         const variants = await qb.where('variants_product.deletedAt IS NULL').getMany();
         await this.connection.getRepository(SearchIndexItem).delete({ languageCode });
         await this.saveSearchIndexItems(languageCode, variants);
@@ -187,7 +188,7 @@ export class FulltextSearchService {
         input: SearchInput,
     ): SelectQueryBuilder<SearchIndexItem> {
         const { term, facetIds } = input;
-        qb.where('true');
+        qb.where('1 = 1');
         if (term && term.length > this.minTermLength) {
             qb.addSelect(`IF (sku LIKE :like_term, 10, 0)`, 'sku_score')
                 .addSelect(

+ 1 - 0
server/src/plugin/index.ts

@@ -3,3 +3,4 @@ export * from './default-asset-server-plugin/default-asset-preview-strategy';
 export * from './default-asset-server-plugin/default-asset-storage-strategy';
 export * from './default-search-plugin/default-search-plugin';
 export * from './default-email-plugin/default-email-plugin';
+export * from './admin-ui-plugin/admin-ui-plugin';