Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: upgrade to Angular 13 (#2028)
* feat: upgrade to Angular 13

* feat: switch to ESLint since TSLint has been deprecated

* feat: upgrade outdated Node.js packages and Node version within the Dockerfile
  • Loading branch information
arturovt committed Nov 26, 2021
1 parent f3f9f6a commit 75bef37
Show file tree
Hide file tree
Showing 48 changed files with 3,441 additions and 5,741 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,23 @@
{
"root": true,
"ignorePatterns": ["projects/**/*"],
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": ["tsconfig.json"],
"createDefaultProgram": true
},
"extends": [
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {}
},
{
"files": ["*.html"],
"extends": ["plugin:@angular-eslint/template/recommended"],
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,6 +26,7 @@
!.vscode/extensions.json

# misc
/.angular/cache
/.sass-cache
/connect.lock
/coverage
Expand Down
3 changes: 3 additions & 0 deletions .lintstagedrc.js
@@ -0,0 +1,3 @@
module.exports = {
'*.{js,ts,html,scss,md,json}': ['prettier --write'],
};
7 changes: 7 additions & 0 deletions .prettierrc
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"endOfLine": "lf",
"trailingComma": "es5",
"tabWidth": 2,
"arrowParens": "avoid"
}
3 changes: 2 additions & 1 deletion Dockerfile
@@ -1,8 +1,9 @@
FROM node:14
FROM node:14.18-alpine

WORKDIR /usr/src/app
COPY . /usr/src/app

ENV HUSKY_SKIP_INSTALL=true
RUN yarn --pure-lockfile --non-interactive --no-progress
RUN yarn build:prod

Expand Down
28 changes: 6 additions & 22 deletions angular.json
Expand Up @@ -16,13 +16,8 @@
"main": "src/main.ts",
"tsConfig": "./tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/assets", "src/favicon.ico"],
"styles": ["src/styles.scss"],
"scripts": [],
"aot": false,
"vendorChunk": true,
Expand Down Expand Up @@ -76,25 +71,14 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "./tsconfig.spec.json",
"scripts": [],
"styles": [
"src/styles.scss"
],
"assets": [
"src/assets",
"src/favicon.ico"
]
"styles": ["src/styles.scss"],
"assets": ["src/assets", "src/favicon.ico"]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"builder": "@angular-eslint/builder:lint",
"options": {
"tsConfig": [
"./tsconfig.app.json",
"./tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions karma.conf.js
Expand Up @@ -10,24 +10,25 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
require('@angular-devkit/build-angular/plugins/karma'),
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true,
},
angularCli: {
environment: 'dev'
environment: 'dev',
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
singleRun: false,
});
};
67 changes: 34 additions & 33 deletions package.json
Expand Up @@ -10,57 +10,64 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "husky install && ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
"postinstall": "husky install"
},
"private": true,
"dependencies": {
"@angular/animations": "^12.2.7",
"@angular/cdk": "^12.2.7",
"@angular/common": "^12.2.7",
"@angular/compiler": "^12.2.7",
"@angular/core": "^12.2.7",
"@angular/forms": "^12.2.7",
"@angular/material": "^12.2.7",
"@angular/platform-browser": "^12.2.7",
"@angular/platform-browser-dynamic": "^12.2.7",
"@angular/router": "^12.2.7",
"bcrypt": "^3.0.2",
"@angular/animations": "^13.0.2",
"@angular/cdk": "^13.0.2",
"@angular/common": "^13.0.2",
"@angular/compiler": "^13.0.2",
"@angular/core": "^13.0.2",
"@angular/forms": "^13.0.2",
"@angular/material": "^13.0.2",
"@angular/platform-browser": "^13.0.2",
"@angular/platform-browser-dynamic": "^13.0.2",
"@angular/router": "^13.0.2",
"bcrypt": "^5.0.1",
"body-parser": "^1.18.2",
"compression": "^1.7.2",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"dotenv": "^10.0.0",
"events": "^3.0.0",
"express": "^4.16.3",
"express-async-handler": "^1.1.3",
"express-jwt": "^5.3.1",
"express-validation": "^1.0.2",
"formidable": "^1.2.1",
"helmet": "^3.21.1",
"formidable": "^3.1.3",
"helmet": "^4.6.0",
"http-errors": "^1.6.3",
"joi": "^13.3.0",
"joi": "^17.4.2",
"jsonwebtoken": "^8.2.1",
"method-override": "^2.3.10",
"mongoose": "^5.7.5",
"method-override": "^3.0.0",
"mongoose": "^6.0.13",
"morgan": "^1.9.1",
"nodemon": "^1.17.5",
"nodemon": "^2.0.15",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"rxjs": "^7.0.1",
"swagger-ui-express": "^3.0.9",
"rxjs": "^7.4.0",
"swagger-ui-express": "^4.1.6",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.2.7",
"@angular/cli": "^12.2.7",
"@angular/compiler-cli": "^12.2.7",
"@angular/language-service": "^12.2.7",
"@angular-devkit/build-angular": "~13.0.3",
"@angular-eslint/builder": "13.0.1",
"@angular-eslint/eslint-plugin": "13.0.1",
"@angular-eslint/eslint-plugin-template": "13.0.1",
"@angular-eslint/schematics": "13.0.1",
"@angular-eslint/template-parser": "13.0.1",
"@angular/cli": "^13.0.3",
"@angular/compiler-cli": "^13.0.2",
"@angular/language-service": "^13.0.2",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~15.0.0",
"codelyzer": "^6.0.0",
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"concurrently": "^3.5.1",
"eslint": "^8.2.0",
"husky": "^7.0.2",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
Expand All @@ -72,12 +79,6 @@
"lint-staged": "^11.1.2",
"prettier": "^2.4.1",
"ts-node": "~6.1.0",
"tslint": "~6.1.0",
"typescript": "4.2.4"
},
"lint-staged": {
"*.{js,ts,html,scss}": [
"prettier --write"
]
"typescript": "4.4.4"
}
}
34 changes: 16 additions & 18 deletions server/config/config.js
Expand Up @@ -6,26 +6,24 @@ require('dotenv').config();
// define validation for all the env vars
const envVarsSchema = Joi.object({
NODE_ENV: Joi.string()
.allow(['development', 'production', 'test', 'provision'])
.allow('development', 'production', 'test', 'provision')
.default('development'),
SERVER_PORT: Joi.number()
.default(4040),
MONGOOSE_DEBUG: Joi.boolean()
.when('NODE_ENV', {
is: Joi.string().equal('development'),
then: Joi.boolean().default(true),
otherwise: Joi.boolean().default(false)
}),
JWT_SECRET: Joi.string().required()
SERVER_PORT: Joi.number().default(4040),
MONGOOSE_DEBUG: Joi.boolean().when('NODE_ENV', {
is: Joi.string().equal('development'),
then: Joi.boolean().default(true),
otherwise: Joi.boolean().default(false),
}),
JWT_SECRET: Joi.string()
.required()
.description('JWT Secret required to sign'),
MONGO_HOST: Joi.string().required()
.description('Mongo DB host url'),
MONGO_PORT: Joi.number()
.default(27017)
}).unknown()
MONGO_HOST: Joi.string().required().description('Mongo DB host url'),
MONGO_PORT: Joi.number().default(27017),
})
.unknown()
.required();

const { error, value: envVars } = Joi.validate(process.env, envVarsSchema);
const { error, value: envVars } = envVarsSchema.validate(process.env);
if (error) {
throw new Error(`Config validation error: ${error.message}`);
}
Expand All @@ -38,8 +36,8 @@ const config = {
frontend: envVars.MEAN_FRONTEND || 'angular',
mongo: {
host: envVars.MONGO_HOST,
port: envVars.MONGO_PORT
}
port: envVars.MONGO_PORT,
},
};

module.exports = config;
38 changes: 20 additions & 18 deletions server/config/express.js
Expand Up @@ -12,7 +12,7 @@ const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
const routes = require('../routes/index.route');
const config = require('./config');
const passport = require('./passport')
const passport = require('./passport');

const app = express();

Expand All @@ -22,25 +22,28 @@ if (config.env === 'development') {

// Choose what fronten framework to serve the dist from
var distDir = '../../dist/';
if (config.frontend == 'react'){
distDir ='../../node_modules/material-dashboard-react/dist'
}else{
distDir ='../../dist/' ;
}

//
app.use(express.static(path.join(__dirname, distDir)))
if (config.frontend == 'react') {
distDir = '../../node_modules/material-dashboard-react/dist';
} else {
distDir = '../../dist/';
}

//
app.use(express.static(path.join(__dirname, distDir)));
app.use(/^((?!(api)).)*/, (req, res) => {
res.sendFile(path.join(__dirname, distDir + '/index.html'));
});

console.log(distDir);
//React server
app.use(express.static(path.join(__dirname, '../../node_modules/material-dashboard-react/dist')))
//React server
app.use(
express.static(
path.join(__dirname, '../../node_modules/material-dashboard-react/dist')
)
);
app.use(/^((?!(api)).)*/, (req, res) => {
res.sendFile(path.join(__dirname, '../../dist/index.html'));
});

res.sendFile(path.join(__dirname, '../../dist/index.html'));
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Expand All @@ -64,21 +67,20 @@ app.use('/api/', routes);

// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new httpError(404)
const err = new httpError(404);
return next(err);
});

// error handler, send stacktrace only during development
app.use((err, req, res, next) => {

// customize Joi validation errors
if (err.isJoi) {
err.message = err.details.map(e => e.message).join("; ");
err.message = err.details.map(e => e.message).join('; ');
err.status = 400;
}

res.status(err.status || 500).json({
message: err.message
message: err.message,
});
next(err);
});
Expand Down
8 changes: 1 addition & 7 deletions server/config/mongoose.js
Expand Up @@ -6,12 +6,7 @@ const config = require('./config');

// connect to mongo db
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, {
keepAlive: 1,
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.connect(mongoUri, { keepAlive: 1 });
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`);
});
Expand All @@ -22,4 +17,3 @@ if (config.MONGOOSE_DEBUG) {
debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
});
}

0 comments on commit 75bef37

Please sign in to comment.