diff --git a/templates/app/client/components/util.js b/templates/app/client/components/util.js
index 0a4da1766..242a9d942 100644
--- a/templates/app/client/components/util.js
+++ b/templates/app/client/components/util.js
@@ -29,6 +29,7 @@ export function urlParse(url) {
// Special treatment for IE, see http://stackoverflow.com/a/13405933 for details
if (a.host === '') {
+ // eslint-disable-next-line no-self-assign
a.href = a.href;
}
diff --git a/templates/app/gulpfile.babel.js b/templates/app/gulpfile.babel.js
index d062483d2..092a83ac6 100644
--- a/templates/app/gulpfile.babel.js
+++ b/templates/app/gulpfile.babel.js
@@ -7,7 +7,7 @@ import path from 'path';
import through2 from 'through2';
import gulpLoadPlugins from 'gulp-load-plugins';
import http from 'http';
-import open from 'open';
+import opn from 'opn';
import lazypipe from 'lazypipe';
import nodemon from 'nodemon';
import {Server as KarmaServer} from 'karma';
@@ -17,8 +17,8 @@ import {Instrumenter} from 'isparta';
import webpack from 'webpack';
import makeWebpackConfig from './webpack.make';
-var plugins = gulpLoadPlugins();
-var config;
+let plugins = gulpLoadPlugins();
+let config;
const clientPath = 'client';
const serverPath = 'server';
@@ -75,8 +75,8 @@ function checkAppReady(cb) {
// Call page until first success
function whenServerReady(cb) {
- var serverReady = false;
- var appReadyInterval = setInterval(() =>
+ let serverReady = false;
+ const appReadyInterval = setInterval(() =>
checkAppReady((ready) => {
if (!ready || serverReady) {
return;
@@ -290,7 +290,7 @@ gulp.task('clean:tmp', () => del(['.tmp/**/*'], {dot: true}));
gulp.task('start:client', cb => {
return require('./webpack.server').start(config.clientPort).then(() => {
- open(`http://localhost:${config.clientPort}`);
+ opn(`http://localhost:${config.clientPort}`);
cb();
});
});
@@ -503,8 +503,7 @@ gulp.task('revReplaceWebpack', function() {
gulp.task('copy:extras', () => {
return gulp.src([
`${clientPath}/favicon.ico`,
- `${clientPath}/robots.txt`,
- `${clientPath}/.htaccess`
+ `${clientPath}/robots.txt`
], { dot: true })
.pipe(gulp.dest(`${paths.dist}/${clientPath}`));
});
diff --git a/templates/app/karma.conf.js b/templates/app/karma.conf.js
index c1ccbaff1..a6cced8b4 100644
--- a/templates/app/karma.conf.js
+++ b/templates/app/karma.conf.js
@@ -56,7 +56,6 @@ module.exports = function(config) {
<%_ if(filters.jasmine) { _%>
require('karma-jasmine'),<% } %>
require('karma-spec-reporter'),
- require('karma-phantomjs-launcher'),
require('karma-script-launcher'),
require('karma-webpack'),
require('karma-sourcemap-loader')
@@ -92,7 +91,7 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
- browsers: ['PhantomJS'],
+ browsers: ['ChromeHeadless'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
diff --git a/templates/app/server/api/user(auth)/user.model(mongooseModels).js b/templates/app/server/api/user(auth)/user.model(mongooseModels).js
index dedb14fa8..27e6ac1d8 100644
--- a/templates/app/server/api/user(auth)/user.model(mongooseModels).js
+++ b/templates/app/server/api/user(auth)/user.model(mongooseModels).js
@@ -241,7 +241,7 @@ UserSchema.methods = {
var defaultIterations = 10000;
var defaultKeyLength = 64;
- var salt = new Buffer(this.salt, 'base64');
+ var salt = Buffer.from(this.salt, 'base64');
if(!callback) {
return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength, 'sha256')
diff --git a/templates/app/server/api/user(auth)/user.model(sequelizeModels).js b/templates/app/server/api/user(auth)/user.model(sequelizeModels).js
index 413769463..c1d41a18d 100644
--- a/templates/app/server/api/user(auth)/user.model(sequelizeModels).js
+++ b/templates/app/server/api/user(auth)/user.model(sequelizeModels).js
@@ -6,7 +6,7 @@ var validatePresenceOf = function(value) {
};
export default function(sequelize, DataTypes) {
- return sequelize.define('User', {
+ const User = sequelize.define('User', {
_id: {
type: DataTypes.INTEGER,
allowNull: false,
@@ -65,158 +65,153 @@ export default function(sequelize, DataTypes) {
* Pre-save hooks
*/
hooks: {
- beforeBulkCreate(users, fields, fn) {
- var totalUpdated = 0;
- users.forEach(user => {
- user.updatePassword(err => {
- if(err) {
- return fn(err);
- }
- totalUpdated += 1;
- if(totalUpdated === users.length) {
- return fn();
- }
- });
- });
+ beforeBulkCreate(users, fields) {
+ var promises = [];
+ users.forEach(user => promises.push(user.updatePassword()));
+ return Promise.all(promises);
},
- beforeCreate(user, fields, fn) {
- user.updatePassword(fn);
+ beforeCreate(user, fields) {
+ return user.updatePassword();
},
- beforeUpdate(user, fields, fn) {
+ beforeUpdate(user, fields) {
if(user.changed('password')) {
- return user.updatePassword(fn);
+ return user.updatePassword();
}
- fn();
+ return Promise.resolve(user);
}
},
- /**
- * Instance Methods
- */
- instanceMethods: {
- /**
- * Authenticate - check if the passwords are the same
- *
- * @param {String} password
- * @param {Function} callback
- * @return {Boolean}
- * @api public
- */
- authenticate(password, callback) {
- if(!callback) {
- return this.password === this.encryptPassword(password);
- }
+ });
- var _this = this;
- this.encryptPassword(password, function(err, pwdGen) {
- if(err) {
- callback(err);
- }
+ /**
+ * Instance Methods
+ */
+
+ /**
+ * Authenticate - check if the passwords are the same
+ *
+ * @param {String} password
+ * @param {Function} callback
+ * @return {Boolean}
+ * @api public
+ */
+ User.prototype.authenticate = function(password, callback) {
+ if(!callback) {
+ return this.password === this.encryptPassword(password);
+ }
- if(_this.password === pwdGen) {
- callback(null, true);
- }
- else {
- callback(null, false);
- }
- });
- },
+ var _this = this;
+ this.encryptPassword(password, function(err, pwdGen) {
+ if(err) {
+ callback(err);
+ }
- /**
- * Make salt
- *
- * @param {Number} [byteSize] - Optional salt byte size, default to 16
- * @param {Function} callback
- * @return {String}
- * @api public
- */
- makeSalt(...args) {
- let byteSize;
- let callback;
- let defaultByteSize = 16;
-
- if(typeof args[0] === 'function') {
- callback = args[0];
- byteSize = defaultByteSize;
- } else if(typeof args[1] === 'function') {
- callback = args[1];
- } else {
- throw new Error('Missing Callback');
- }
+ if(_this.password === pwdGen) {
+ callback(null, true);
+ } else {
+ callback(null, false);
+ }
+ });
+ };
+
+ /**
+ * Make salt
+ *
+ * @param {Number} [byteSize] - Optional salt byte size, default to 16
+ * @param {Function} callback
+ * @return {String}
+ * @api public
+ */
+ User.prototype.makeSalt = function(...args) {
+ let byteSize;
+ let callback;
+ let defaultByteSize = 16;
+
+ if(typeof args[0] === 'function') {
+ callback = args[0];
+ byteSize = defaultByteSize;
+ } else if(typeof args[1] === 'function') {
+ callback = args[1];
+ } else {
+ throw new Error('Missing Callback');
+ }
- if(!byteSize) {
- byteSize = defaultByteSize;
- }
+ if(!byteSize) {
+ byteSize = defaultByteSize;
+ }
- return crypto.randomBytes(byteSize, function(err, salt) {
- if(err) {
- callback(err);
- }
- return callback(null, salt.toString('base64'));
- });
- },
+ return crypto.randomBytes(byteSize, function(err, salt) {
+ if(err) {
+ callback(err);
+ }
+ return callback(null, salt.toString('base64'));
+ });
+ };
+
+ /**
+ * Encrypt password
+ *
+ * @param {String} password
+ * @param {Function} callback
+ * @return {String}
+ * @api public
+ */
+ User.prototype.encryptPassword = function(password, callback) {
+ if(!password || !this.salt) {
+ return callback ? callback(null) : null;
+ }
- /**
- * Encrypt password
- *
- * @param {String} password
- * @param {Function} callback
- * @return {String}
- * @api public
- */
- encryptPassword(password, callback) {
- if(!password || !this.salt) {
- return callback ? callback(null) : null;
- }
+ var defaultIterations = 10000;
+ var defaultKeyLength = 64;
+ var salt = Buffer.from(this.salt, 'base64');
- var defaultIterations = 10000;
- var defaultKeyLength = 64;
- var salt = new Buffer(this.salt, 'base64');
+ if(!callback) {
+ return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength, 'sha256')
+ .toString('base64');
+ }
- if(!callback) {
- return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength, 'sha256')
- .toString('base64');
+ return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, 'sha256',
+ function(err, key) {
+ if(err) {
+ callback(err);
}
+ return callback(null, key.toString('base64'));
+ });
+ };
+
+ /**
+ * Update password field
+ *
+ * @param {Function} fn
+ * @return {String}
+ * @api public
+ */
+ User.prototype.updatePassword = function() {
+ return new Promise((resolve, reject) => {
+ if (!this.password) {
+ return resolve(user);
+ }
- return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, 'sha256',
- function(err, key) {
- if(err) {
- callback(err);
- }
- return callback(null, key.toString('base64'));
- });
- },
+ if (!validatePresenceOf(this.password)<% if(filters.oauth) { %> && authTypes.indexOf(this.provider) === -1<% } %>) {
+ return reject(new Error('Invalid password'));
+ }
- /**
- * Update password field
- *
- * @param {Function} fn
- * @return {String}
- * @api public
- */
- updatePassword(fn) {
- // Handle new/update passwords
- if(!this.password) return fn(null);
-
- if(!validatePresenceOf(this.password)<% if(filters.oauth) { %> && authTypes.indexOf(this.provider) === -1<% } %>) {
- fn(new Error('Invalid password'));
+ // Make salt with a callback
+ return this.makeSalt((saltErr, salt) => {
+ if (saltErr) {
+ return reject(saltErr);
}
-
- // Make salt with a callback
- this.makeSalt((saltErr, salt) => {
- if(saltErr) {
- return fn(saltErr);
+ this.salt = salt;
+ return this.encryptPassword(this.password, (encryptErr, hashedPassword) => {
+ if (encryptErr) {
+ return reject(encryptErr);
}
- this.salt = salt;
- this.encryptPassword(this.password, (encryptErr, hashedPassword) => {
- if(encryptErr) {
- fn(encryptErr);
- }
- this.password = hashedPassword;
- fn(null);
- });
+ this.password = hashedPassword;
+ return resolve(this);
});
- }
- }
- });
+ });
+ });
+ };
+
+ return User;
};
diff --git a/templates/app/server/app.js b/templates/app/server/app.js
index b100cfd5b..f0f1a4982 100644
--- a/templates/app/server/app.js
+++ b/templates/app/server/app.js
@@ -38,7 +38,7 @@ function startServer() {
}
<% if(filters.sequelize) { %>
sqldb.sequelize.sync()<% if(filters.ws) { %>
- .then(wsInitPromise)
+ .then(() => wsInitPromise)
.then(primus => {
app.primus = primus;
})<% } %><% if(filters.models) { %>
diff --git a/templates/app/server/config/environment/development.js b/templates/app/server/config/environment/development.js
index 1a0705de6..2e4c9ac43 100644
--- a/templates/app/server/config/environment/development.js
+++ b/templates/app/server/config/environment/development.js
@@ -14,6 +14,7 @@ module.exports = {<% if (filters.mongoose) { %>
uri: 'sqlite://',
options: {
logging: false,
+ operatorsAliases: false,
storage: 'dev.sqlite',
define: {
timestamps: false
diff --git a/templates/app/server/config/environment/production.js b/templates/app/server/config/environment/production.js
index 87f58dacf..2c7d2aad6 100644
--- a/templates/app/server/config/environment/production.js
+++ b/templates/app/server/config/environment/production.js
@@ -27,6 +27,7 @@ module.exports = {
|| 'sqlite://',
options: {
logging: false,
+ operatorsAliases: false,
storage: 'dist.sqlite',
define: {
timestamps: false
diff --git a/templates/app/server/config/environment/test.js b/templates/app/server/config/environment/test.js
index dc05b53b2..4b2dcf2bf 100644
--- a/templates/app/server/config/environment/test.js
+++ b/templates/app/server/config/environment/test.js
@@ -12,6 +12,7 @@ module.exports = {
uri: 'sqlite://',
options: {
logging: false,
+ operatorsAliases: false,
storage: 'test.sqlite',
define: {
timestamps: false
diff --git a/templates/app/server/config/express.js b/templates/app/server/config/express.js
index dd1ebdcb8..50a09bf1b 100644
--- a/templates/app/server/config/express.js
+++ b/templates/app/server/config/express.js
@@ -65,7 +65,9 @@ export default function(app) {
mongooseConnection: mongoose.connection,
db: '<%= lodash.slugify(lodash.humanize(appname)) %>'
})<% } else if(filters.sequelize) { %>,
- store: new Store(sqldb.sequelize)<% } %>
+ store: new Store({
+ db: sqldb.sequelize
+ })<% } %>
}));
/**
diff --git a/templates/app/server/config/websockets(ws).js b/templates/app/server/config/websockets(ws).js
index 6f6750d08..85298d10c 100644
--- a/templates/app/server/config/websockets(ws).js
+++ b/templates/app/server/config/websockets(ws).js
@@ -25,7 +25,9 @@ function onConnect(spark) {
});
// Register the spark with each WebSocket event handler
- for(let register of registerFunctions) {
+ // For some reason this is needed:
+ // eslint-disable-next-line no-unused-vars
+ for(const register of registerFunctions) {
register(spark);
}
}
@@ -39,9 +41,7 @@ export function broadcast(message) {
}
export default function initWebSocketServer(server) {
- primus = new Primus(server, {
- transformer: 'uws',
- });
+ primus = new Primus(server, {});
primus.plugin('emit', primusEmit);
primus.on('connection', onConnect);
diff --git a/templates/app/tsconfig.client.test(ts).json b/templates/app/tsconfig.client.test(ts).json
index 65075f53b..3b044a0e5 100644
--- a/templates/app/tsconfig.client.test(ts).json
+++ b/templates/app/tsconfig.client.test(ts).json
@@ -1,5 +1,6 @@
{
"compilerOptions": {
+ "allowSyntheticDefaultImports": true,
"sourceMap": true,
"rootDir": "./client",
"module": "commonjs",
diff --git a/templates/app/webpack.make.js b/templates/app/webpack.make.js
index b517db56e..3b45ab190 100644
--- a/templates/app/webpack.make.js
+++ b/templates/app/webpack.make.js
@@ -39,7 +39,6 @@ module.exports = function makeWebpackConfig(options) {
if(!TEST) {
config.entry = {
app: './client/app/app.<%= scriptExt %>',
- polyfills: './client/app/polyfills.<%= scriptExt %>',
vendor: [
'lodash'
]
@@ -130,8 +129,9 @@ module.exports = function makeWebpackConfig(options) {
['babel-preset-env', {
// debug: true,
targets: {
- browsers: ['last 2 versions', 'not ie < 11'],
+ browsers: ['last 2 versions', 'not dead'],
},
+ debug: true,
modules: false,
}]
],
@@ -141,7 +141,6 @@ module.exports = function makeWebpackConfig(options) {
'transform-runtime',
'transform-decorators-legacy',
'transform-class-properties',
- 'transform-export-extensions',
].concat(TEST ? ['istanbul'] : []),
}
}].concat(DEV ? '@angularclass/hmr-loader' : []),
diff --git a/templates/endpoint/basename.integration.js b/templates/endpoint/basename.integration.js
index e28f2bfcc..fd6a1fb07 100644
--- a/templates/endpoint/basename.integration.js
+++ b/templates/endpoint/basename.integration.js
@@ -1,13 +1,11 @@
-/* globals describe, expect, it, beforeEach, afterEach */
-
-var app = require('<%= relativeRequire('server') %>');
+const app = require('<%= relativeRequire('server') %>');
import request from 'supertest';<% if(filters.models) { %>
-var new<%= classedName %>;<% } %>
+let new<%= classedName %>;<% } %>
describe('<%= classedName %> API:', function() {
describe('GET <%= route %>', function() {
- var <%= cameledName %>s;
+ let <%= cameledName %>s;
beforeEach(function(done) {
request(app)
@@ -54,7 +52,7 @@ describe('<%= classedName %> API:', function() {
});
describe('GET <%= route %>/:id', function() {
- var <%= cameledName %>;
+ let <%= cameledName %>;
beforeEach(function(done) {
request(app)
@@ -81,7 +79,7 @@ describe('<%= classedName %> API:', function() {
});
describe('PUT <%= route %>/:id', function() {
- var updated<%= classedName %>;
+ let updated<%= classedName %>;
beforeEach(function(done) {
request(app)
@@ -130,7 +128,7 @@ describe('<%= classedName %> API:', function() {
});
describe('PATCH <%= route %>/:id', function() {
- var patched<%= classedName %>;
+ let patched<%= classedName %>;
beforeEach(function(done) {
request(app)
diff --git a/templates/endpoint/basename.socket(ws).js b/templates/endpoint/basename.socket(ws).js
index 3e0c5d309..f0e0d625d 100644
--- a/templates/endpoint/basename.socket(ws).js
+++ b/templates/endpoint/basename.socket(ws).js
@@ -5,12 +5,13 @@
import <%= classedName %>Events from './<%= basename %>.events';
// Model events to emit
-var events = ['save', 'remove'];
+const events = ['save', 'remove'];
export function register(spark) {
// Bind model events to socket events
- for(let event of events) {
- var listener = createListener(`<%= cameledName %>:${event}`, spark);
+ /* eslint-disable-next-line no-unused-vars */
+ for(const event of events) {
+ const listener = createListener(`<%= cameledName %>:${event}`, spark);
<%= classedName %>Events.on(event, listener);
spark.on('disconnect', removeListener(event, listener));
diff --git a/templates/endpoint/index.spec.js b/templates/endpoint/index.spec.js
index 1ada84552..ef7ccf3f4 100644
--- a/templates/endpoint/index.spec.js
+++ b/templates/endpoint/index.spec.js
@@ -1,5 +1,3 @@
-/* globals sinon, describe, expect, it */
-
var proxyquire = require('proxyquire').noPreserveCache();
var <%= cameledName %>CtrlStub = {
diff --git a/test/fixtures/.yo-rc.json b/test/fixtures/.yo-rc.json
index b369cde2f..6d24f6785 100644
--- a/test/fixtures/.yo-rc.json
+++ b/test/fixtures/.yo-rc.json
@@ -14,7 +14,7 @@
"modelsNeedle": "// Insert models below",
"filters": {
"js": true,
- "babel": true,
+ "ts": true,
"flow": true,
"html": true,
"sass": true,
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 000000000..6b4541c81
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,68 @@
+{
+ "compilerOptions": {
+ /* Basic Options */
+ // "incremental": true, /* Enable incremental compilation */
+ "target": "ES2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
+ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
+ "lib": ["es2018"], /* Specify library files to be included in the compilation. */
+ // "allowJs": true, /* Allow javascript files to be compiled. */
+ // "checkJs": true, /* Report errors in .js files. */
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
+ // "outFile": "./", /* Concatenate and emit output to single file. */
+ // "outDir": "./", /* Redirect output structure to the directory. */
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
+ // "composite": true, /* Enable project compilation */
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
+ // "removeComments": true, /* Do not emit comments to output. */
+ // "noEmit": true, /* Do not emit outputs. */
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
+
+ /* Strict Type-Checking Options */
+ "strict": true, /* Enable all strict type-checking options. */
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
+ // "strictNullChecks": true, /* Enable strict null checks. */
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
+
+ /* Additional Checks */
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
+
+ /* Module Resolution Options */
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
+ "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
+ "paths": {
+ "*": [
+ "node_modules/*",
+ "src/types/*"
+ ]
+ }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
+ "typeRoots": ["./src/@types"], /* List of folders to include type definitions from. */
+ // "types": [], /* Type declaration files to be included in compilation. */
+ "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
+
+ /* Source Map Options */
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
+ "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
+
+ /* Experimental Options */
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
+ }
+}