Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update version vendure and fixed bug mac m1 #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

.idea
node_modules
static
dist
assets
__data__
package-lock.json
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

root = true

[*]
quote_type = single
max_line_length = 120
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
/dist
/static
__data__
.history
package-lock.json
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM node:14
FROM node:14.18.3-bullseye-slim

WORKDIR /usr/src/app

COPY package.json ./
COPY yarn.lock ./

RUN apt-get update
RUN apt-get install python build-essential -y
#COPY yarn.lock ./
RUN yarn
COPY . .
RUN chmod +x /usr/src/app/wait-for-it.sh
RUN yarn build
#RUN yarn build
4 changes: 3 additions & 1 deletion Dockerfile-storefront
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM node:14
FROM node:14.18.2-bullseye-slim
ARG STOREFRONT_VERSION
WORKDIR /usr/src/app

RUN apt-get update
RUN apt-get -y install curl unzip
RUN echo $STOREFRONT_VERSION
ARG ZIP_URL=https://github.com/vendure-ecommerce/storefront/archive/v$STOREFRONT_VERSION.zip
RUN curl "$ZIP_URL" -L -o storefront.zip
Expand Down
27 changes: 27 additions & 0 deletions migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';
import program from 'commander';

import { config } from './src/vendure-config';

program
.command('generate <name>')
.description('Generate a new migration file with the given name')
.action(name => {
return generateMigration(config, { name, outputDir: './migrations' });
});

program
.command('run')
.description('Run all pending migrations')
.action(() => {
return runMigrations(config);
});

program
.command('revert')
.description('Revert the last applied migration')
.action(() => {
return revertLastMigration(config);
});

program.parse(process.argv);
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
"license": "MIT",
"scripts": {
"build": "tsc",
"run:server": "node dist/index.js",
"run:worker": "node dist/index-worker.js"
"run:server": "ts-node ./src/index.ts",
"run:worker": "ts-node ./src/index-worker.ts",
"start": "concurrently npm:run:*",
"migration:generate": "ts-node migration generate",
"migration:run": "ts-node migration run",
"migration:revert": "ts-node migration revert"
},
"dependencies": {
"@vendure/admin-ui-plugin": "^1.0.0",
"@vendure/asset-server-plugin": "^1.0.0",
"@vendure/core": "^1.0.0",
"@vendure/email-plugin": "^1.0.0",
"pg": "^8.4.1",
"typescript": "4.0.3"
"@vendure/admin-ui-plugin": "1.4.6",
"@vendure/asset-server-plugin": "1.4.6",
"@vendure/core": "1.4.6",
"@vendure/email-plugin": "1.4.6",
"@vendure/testing": "1.4.6",
"@vendure/create": "1.4.6",
"pg": "8.7.3",
"typescript": "4.3.5",
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.1",
"@types/node": "^14.6.0",
"@vendure/create": "^1.0.0",
"@vendure/testing": "^1.0.0",
"fs-extra": "^9.0.1"
"concurrently": "^7.0.0",
"ts-node": "10.5.0"
}
}
9 changes: 4 additions & 5 deletions src/index-worker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { bootstrapWorker } from '@vendure/core';

import { setupServer } from './setup';
import { config } from './vendure-config';
import { setupWorker } from './setup';

setupWorker()
setupServer(false)
.then(() => bootstrapWorker(config))
.then(worker => worker.startJobQueue())
.then((worker) => worker.startJobQueue())
.catch((err) => {
// tslint:disable-next-line:no-console
console.log(err);
process.exit(1);
});
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { bootstrap } from '@vendure/core';

import { config } from './vendure-config';
import { setupServer } from './setup';
import { config } from './vendure-config';

setupServer()
.then(() => bootstrap(config))
.catch((err) => {
// tslint:disable-next-line:no-console
console.log(err);
process.exit(1);
});
55 changes: 31 additions & 24 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { bootstrap, defaultConfig, mergeConfig, VendureConfig, JobQueueService } from '@vendure/core';
import { bootstrap, defaultConfig, JobQueueService, mergeConfig, VendureConfig } from '@vendure/core';
import { populate } from '@vendure/core/cli';
import { clearAllTables, populateCustomers } from '@vendure/testing';
import path from 'path';
import fs from 'fs-extra';
import path from 'path';

import { config } from './vendure-config';

Expand All @@ -18,10 +18,13 @@ export async function setupWorker() {
}
}

export async function setupServer() {
export async function setupServer(populateInitial = true) {
console.log('isInitialRun:', isInitialRun());
if (isInitialRun()) {
console.log('Initial run - populating test data...');

await createDirectoryStructure();
await copyEmailTemplates();
const populateConfig = mergeConfig(
defaultConfig,
mergeConfig(config, {
Expand All @@ -33,29 +36,33 @@ export async function setupServer() {
importAssetsDir: path.join(require.resolve('@vendure/create'), '../assets/images'),
},
customFields: {},
}),
})
);

const initialData = require(path.join(require.resolve('@vendure/create'), '../assets/initial-data.json'));
await createDirectoryStructure();
await copyEmailTemplates();
await clearAllTablesWithPolling(populateConfig);
const app = await populate(
() => bootstrap(populateConfig).then(async _app => {
await _app.get(JobQueueService).start();
return _app;
}),
initialData,
path.join(require.resolve('@vendure/create'), '../assets/products.csv'),
);
try {
console.log('populating customers...');
await populateCustomers(10, populateConfig, true);
config.authOptions.requireVerification = true;
return app.close();
} catch (err) {
console.log(err);
process.exit(1);
if (populateInitial) {
const initialData = require(path.join(require.resolve('@vendure/create'), '../assets/initial-data.json'));

await clearAllTablesWithPolling(populateConfig);

const app = await populate(
() =>
bootstrap(populateConfig).then(async (_app) => {
await _app.get(JobQueueService).start();
return _app;
}),
initialData,
path.join(require.resolve('@vendure/create'), '../assets/products.csv')
);

try {
console.log('populating customers...');
await populateCustomers(app, 10, console.log);
config.authOptions.requireVerification = true;
return app.close();
} catch (err) {
console.log(err);
process.exit(1);
}
}
}
}
Expand Down
30 changes: 14 additions & 16 deletions src/vendure-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultJobQueuePlugin, DefaultSearchPlugin, dummyPaymentHandler, VendureConfig, } from '@vendure/core';
import { AssetServerPlugin } from '@vendure/asset-server-plugin';
import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
import { AssetServerPlugin } from '@vendure/asset-server-plugin';
import { DefaultJobQueuePlugin, DefaultSearchPlugin, dummyPaymentHandler, VendureConfig } from '@vendure/core';
import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
import path from 'path';

Expand Down Expand Up @@ -28,14 +28,13 @@ export const config: VendureConfig = {
identifier: 'superadmin',
password: 'superadmin',
},
requireVerification: true,
cookieOptions: {
secret: process.env.COOKIE_SECRET || '3r8wq8jdo92',
secret: process.env.COOKIE_SECRET || 'cookie-secret',
},
},
dbConnectionOptions: {
type: 'postgres',
synchronize: false, // turn this off for production
synchronize: true, // turn this off for production
logging: false,
database: 'vendure',
host: process.env.DATABASE_HOST || 'localhost',
Expand All @@ -54,26 +53,25 @@ export const config: VendureConfig = {
assetUploadDir: path.join(__dirname, '../static/assets'),
assetUrlPrefix: 'http://localhost:3000/assets/',
}),
DefaultJobQueuePlugin,
DefaultSearchPlugin,
AdminUiPlugin.init({
route: 'admin',
port: 3002,
}),
DefaultJobQueuePlugin.init({ useDatabaseForBuffer: true }),
DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: true }),
EmailPlugin.init({
route: 'mailbox',
devMode: true,
outputPath: path.join(__dirname, '../static/email/test-emails'),
route: 'mailbox',
handlers: defaultEmailHandlers,
templatePath: path.join(__dirname, '../static/email/templates'),
globalTemplateVars: {
// The following variables will change depending on your storefront implementation
fromAddress: '"example" <noreply@example.com>',
verifyEmailAddressUrl: 'http://localhost:8080/verify',
passwordResetUrl: 'http://localhost:8080/password-reset',
changeEmailAddressUrl: 'http://localhost:8080/verify-email-address-change'
verifyEmailAddressUrl: 'http://localhost:4000/account/verify',
passwordResetUrl: 'http://localhost:4000/account/reset-password',
changeEmailAddressUrl: 'http://localhost:8080/verify-email-address-change',
},
}),
AdminUiPlugin.init({
route: 'admin',
port: 3002,
}),
],
};

14 changes: 5 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"noLib": false,
"skipLibCheck": true,
"lib": ["es2017", "esnext.asynciterable"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"strict": true,
"strictPropertyInitialization": false,
"sourceMap": true,
"newLine": "LF",
"declaration": true,
"outDir": "./dist"
}
"sourceMap": false,
"outDir": "./dist",
"baseUrl": "./"
},
"exclude": ["node_modules", "migration.ts"]
}