From 23c193b33b6e7613dd70f6b3428aa7ef90f455b8 Mon Sep 17 00:00:00 2001 From: Charles Lyding Date: Tue, 31 Jan 2017 11:19:14 -0500 Subject: [PATCH] refactor: convert blueprints to typescript --- .../blueprints/class/{index.js => index.ts} | 14 +++---- .../component/{index.js => index.ts} | 41 ++++++++++--------- .../directive/{index.js => index.ts} | 39 ++++++++++-------- .../blueprints/enum/{index.js => index.ts} | 13 +++--- .../interface/{index.js => index.ts} | 25 +++++------ .../blueprints/module/{index.js => index.ts} | 20 ++++----- .../blueprints/ng2/{index.js => index.ts} | 20 +++++---- .../blueprints/pipe/{index.js => index.ts} | 34 +++++++-------- .../blueprints/service/{index.js => index.ts} | 35 +++++++++------- .../ember-cli/lib/models/blueprint.js | 10 ++--- 10 files changed, 135 insertions(+), 116 deletions(-) rename packages/angular-cli/blueprints/class/{index.js => index.ts} (81%) rename packages/angular-cli/blueprints/component/{index.js => index.ts} (84%) rename packages/angular-cli/blueprints/directive/{index.js => index.ts} (78%) rename packages/angular-cli/blueprints/enum/{index.js => index.ts} (64%) rename packages/angular-cli/blueprints/interface/{index.js => index.ts} (65%) rename packages/angular-cli/blueprints/module/{index.js => index.ts} (82%) rename packages/angular-cli/blueprints/ng2/{index.js => index.ts} (83%) rename packages/angular-cli/blueprints/pipe/{index.js => index.ts} (79%) rename packages/angular-cli/blueprints/service/{index.js => index.ts} (75%) diff --git a/packages/angular-cli/blueprints/class/index.js b/packages/angular-cli/blueprints/class/index.ts similarity index 81% rename from packages/angular-cli/blueprints/class/index.js rename to packages/angular-cli/blueprints/class/index.ts index d76dac94653e..f3a631bbee5f 100644 --- a/packages/angular-cli/blueprints/class/index.js +++ b/packages/angular-cli/blueprints/class/index.ts @@ -3,22 +3,22 @@ const dynamicPathParser = require('../../utilities/dynamic-path-parser'); const Blueprint = require('../../ember-cli/lib/models/blueprint'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ { name: 'spec', type: Boolean } ], - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { - const rawName = options.args[1]; + locals: function (options: any) { + const rawName = options.args[1] as string; const nameParts = rawName.split('.') .filter(part => part.length !== 0); @@ -40,7 +40,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.spec.ts') < 0); @@ -61,4 +61,4 @@ module.exports = { } }; } -}; +}); diff --git a/packages/angular-cli/blueprints/component/index.js b/packages/angular-cli/blueprints/component/index.ts similarity index 84% rename from packages/angular-cli/blueprints/component/index.js rename to packages/angular-cli/blueprints/component/index.ts index 60abb7f238a0..2c858ca53662 100644 --- a/packages/angular-cli/blueprints/component/index.js +++ b/packages/angular-cli/blueprints/component/index.ts @@ -9,7 +9,7 @@ const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); const NodeHost = require('@angular-cli/ast-tools').NodeHost; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -25,7 +25,7 @@ module.exports = { { name: 'export', type: Boolean, default: false } ], - beforeInstall: function(options) { + beforeInstall: function(options: any) { if (options.module) { // Resolve path to module const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`; @@ -38,7 +38,7 @@ module.exports = { } else { try { this.pathToModule = findParentModule(this.project, this.dynamicPath.dir); - } catch(e) { + } catch (e) { if (!options.skipImport) { throw `Error locating module for declaration\n\t${e}`; } @@ -46,19 +46,20 @@ module.exports = { } }, - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; - var defaultPrefix = ''; + let defaultPrefix = ''; if (this.project.ngConfig && this.project.ngConfig.apps[0] && this.project.ngConfig.apps[0].prefix) { defaultPrefix = this.project.ngConfig.apps[0].prefix; } - var prefix = (this.options.prefix === 'false' || this.options.prefix === '') ? '' : (this.options.prefix || defaultPrefix); + let prefix = (this.options.prefix === 'false' || this.options.prefix === '') + ? '' : (this.options.prefix || defaultPrefix); prefix = prefix && `${prefix}-`; this.selector = stringUtils.dasherize(prefix + parsedPath.name); @@ -70,7 +71,7 @@ module.exports = { return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { this.styleExt = 'css'; if (this.project.ngConfig && this.project.ngConfig.defaults && @@ -114,7 +115,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && this.options.inlineTemplate) { fileList = fileList.filter(p => p.indexOf('.html') < 0); @@ -129,15 +130,15 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. return { __path__: () => { - var dir = this.dynamicPath.dir; + let dir = this.dynamicPath.dir; if (!options.locals.flat) { dir += path.sep + options.dasherizedModuleName; } - var srcDir = this.project.ngConfig.apps[0].root; + const srcDir = this.project.ngConfig.apps[0].root; this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length); this.generatePath = dir; return dir; @@ -148,12 +149,12 @@ module.exports = { }; }, - afterInstall: function(options) { + afterInstall: function(options: any) { if (options.dryRun) { return; } - const returns = []; + const returns: Array = []; const className = stringUtils.classify(`${options.entity.name}Component`); const fileName = stringUtils.dasherize(`${options.entity.name}.component`); const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath); @@ -162,17 +163,19 @@ module.exports = { if (!options.skipImport) { returns.push( astUtils.addDeclarationToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)) - .then((result) => { + .then((change: any) => change.apply(NodeHost)) + .then((result: any) => { if (options.export) { return astUtils.addExportToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)); + .then((change: any) => change.apply(NodeHost)); } return result; })); - this._writeStatusToUI(chalk.yellow, 'update', path.relative(this.project.root, this.pathToModule)); + this._writeStatusToUI(chalk.yellow, + 'update', + path.relative(this.project.root, this.pathToModule)); } return Promise.all(returns); } -}; +}); diff --git a/packages/angular-cli/blueprints/directive/index.js b/packages/angular-cli/blueprints/directive/index.ts similarity index 78% rename from packages/angular-cli/blueprints/directive/index.js rename to packages/angular-cli/blueprints/directive/index.ts index aee282a2435b..455c839e197b 100644 --- a/packages/angular-cli/blueprints/directive/index.js +++ b/packages/angular-cli/blueprints/directive/index.ts @@ -9,7 +9,7 @@ const NodeHost = require('@angular-cli/ast-tools').NodeHost; const Blueprint = require('../../ember-cli/lib/models/blueprint'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -21,7 +21,7 @@ module.exports = { { name: 'export', type: Boolean, default: false } ], - beforeInstall: function(options) { + beforeInstall: function(options: any) { if (options.module) { // Resolve path to module const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`; @@ -34,7 +34,7 @@ module.exports = { } else { try { this.pathToModule = findParentModule(this.project, this.dynamicPath.dir); - } catch(e) { + } catch (e) { if (!options.skipImport) { throw `Error locating module for declaration\n\t${e}`; } @@ -42,19 +42,20 @@ module.exports = { } }, - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; - var defaultPrefix = ''; + let defaultPrefix = ''; if (this.project.ngConfig && this.project.ngConfig.apps[0] && this.project.ngConfig.apps[0].prefix) { defaultPrefix = this.project.ngConfig.apps[0].prefix; } - var prefix = (this.options.prefix === 'false' || this.options.prefix === '') ? '' : (this.options.prefix || defaultPrefix); + let prefix = (this.options.prefix === 'false' || this.options.prefix === '') + ? '' : (this.options.prefix || defaultPrefix); prefix = prefix && `${prefix}-`; @@ -62,7 +63,7 @@ module.exports = { return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { options.spec = options.spec !== undefined ? options.spec : this.project.ngConfigObj.get('defaults.spec.directive'); @@ -75,7 +76,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.directive.spec.ts') < 0); @@ -84,11 +85,11 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. return { __path__: () => { - var dir = this.dynamicPath.dir; + let dir = this.dynamicPath.dir; if (!options.locals.flat) { dir += path.sep + options.dasherizedModuleName; } @@ -98,12 +99,12 @@ module.exports = { }; }, - afterInstall: function(options) { + afterInstall: function(options: any) { if (options.dryRun) { return; } - const returns = []; + const returns: Array = []; const className = stringUtils.classify(`${options.entity.name}Directive`); const fileName = stringUtils.dasherize(`${options.entity.name}.directive`); const fullGeneratePath = path.join(this.project.root, this.generatePath); @@ -114,17 +115,19 @@ module.exports = { if (!options.skipImport) { returns.push( astUtils.addDeclarationToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)) - .then((result) => { + .then((change: any) => change.apply(NodeHost)) + .then((result: any) => { if (options.export) { return astUtils.addExportToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)); + .then((change: any) => change.apply(NodeHost)); } return result; })); - this._writeStatusToUI(chalk.yellow, 'update', path.relative(this.project.root, this.pathToModule)); + this._writeStatusToUI(chalk.yellow, + 'update', + path.relative(this.project.root, this.pathToModule)); } return Promise.all(returns); } -}; +}); diff --git a/packages/angular-cli/blueprints/enum/index.js b/packages/angular-cli/blueprints/enum/index.ts similarity index 64% rename from packages/angular-cli/blueprints/enum/index.js rename to packages/angular-cli/blueprints/enum/index.ts index d4e5b8bce2d8..120b6737fab8 100644 --- a/packages/angular-cli/blueprints/enum/index.js +++ b/packages/angular-cli/blueprints/enum/index.ts @@ -1,17 +1,18 @@ const stringUtils = require('ember-cli-string-utils'); -var dynamicPathParser = require('../../utilities/dynamic-path-parser'); +const dynamicPathParser = require('../../utilities/dynamic-path-parser'); +const Blueprint = require('../../ember-cli/lib/models/blueprint'); -module.exports = { +export default Blueprint.extend({ description: '', - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { this.fileName = stringUtils.dasherize(options.entity.name); return { @@ -33,4 +34,4 @@ module.exports = { } }; } -}; +}); diff --git a/packages/angular-cli/blueprints/interface/index.js b/packages/angular-cli/blueprints/interface/index.ts similarity index 65% rename from packages/angular-cli/blueprints/interface/index.js rename to packages/angular-cli/blueprints/interface/index.ts index f14afb9525d0..6de7f773163d 100644 --- a/packages/angular-cli/blueprints/interface/index.js +++ b/packages/angular-cli/blueprints/interface/index.ts @@ -1,33 +1,34 @@ const stringUtils = require('ember-cli-string-utils'); -var dynamicPathParser = require('../../utilities/dynamic-path-parser'); +const dynamicPathParser = require('../../utilities/dynamic-path-parser'); +const Blueprint = require('../../ember-cli/lib/models/blueprint'); -module.exports = { +export default Blueprint.extend({ description: '', - + anonymousOptions: [ '' ], - - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { - var interfaceType = options.args [2] + locals: function (options: any) { + const interfaceType = options.args[2]; this.fileName = stringUtils.dasherize(options.entity.name); if (interfaceType) { - this.fileName += '.' + interfaceType; + this.fileName += '.' + interfaceType; } - var prefix = ''; + let prefix = ''; if (this.project.ngConfig && this.project.ngConfig.defaults && this.project.ngConfig.defaults.prefixInterfaces) { prefix = 'I'; } - return { + return { dynamicPath: this.dynamicPath.dir, flat: options.flat, fileName: this.fileName, @@ -47,4 +48,4 @@ module.exports = { } }; } -}; +}); diff --git a/packages/angular-cli/blueprints/module/index.js b/packages/angular-cli/blueprints/module/index.ts similarity index 82% rename from packages/angular-cli/blueprints/module/index.js rename to packages/angular-cli/blueprints/module/index.ts index c10ae855352f..5d6f15ee54d2 100644 --- a/packages/angular-cli/blueprints/module/index.js +++ b/packages/angular-cli/blueprints/module/index.ts @@ -3,7 +3,7 @@ const Blueprint = require('../../ember-cli/lib/models/blueprint'); const dynamicPathParser = require('../../utilities/dynamic-path-parser'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -11,15 +11,15 @@ module.exports = { { name: 'routing', type: Boolean, default: false } ], - normalizeEntityName: function (entityName) { + normalizeEntityName: function (entityName: string) { this.entityName = entityName; - var parsedPath = dynamicPathParser(this.project, entityName); + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { options.spec = options.spec !== undefined ? options.spec : this.project.ngConfigObj.get('defaults.spec.module'); @@ -32,7 +32,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (!this.options || !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0); @@ -44,7 +44,7 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. this.dasherizedModuleName = options.dasherizedModuleName; return { @@ -57,7 +57,7 @@ module.exports = { }; }, - afterInstall: function (options) { + afterInstall: function (options: any) { if (this.options && this.options.routing) { // Component folder needs to be `/{moduleName}/{ComponentName}` @@ -67,8 +67,8 @@ module.exports = { // as `this.dynamicPath.dir` will be the same as `this.dynamicPath.appRoot` // 2. If it does have `/` (like `parent/mod-name`), it'll be `/parent/mod-name/mod-name` // as `this.dynamicPath.dir` minus `this.dynamicPath.appRoot` will be `/parent` - var moduleDir = - this.dynamicPath.dir.replace(this.dynamicPath.appRoot, '') + path.sep + this.dasherizedModuleName; + const moduleDir = this.dynamicPath.dir.replace(this.dynamicPath.appRoot, '') + + path.sep + this.dasherizedModuleName; options.entity.name = moduleDir + path.sep + this.dasherizedModuleName; options.flat = true; @@ -80,4 +80,4 @@ module.exports = { return Blueprint.load(path.join(__dirname, '../component')).install(options); } } -}; +}); diff --git a/packages/angular-cli/blueprints/ng2/index.js b/packages/angular-cli/blueprints/ng2/index.ts similarity index 83% rename from packages/angular-cli/blueprints/ng2/index.js rename to packages/angular-cli/blueprints/ng2/index.ts index c917ab1adae6..b2bcccf94c97 100644 --- a/packages/angular-cli/blueprints/ng2/index.js +++ b/packages/angular-cli/blueprints/ng2/index.ts @@ -3,7 +3,7 @@ const path = require('path'); const stringUtils = require('ember-cli-string-utils'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -16,21 +16,23 @@ module.exports = { { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] } ], - beforeInstall: function(options) { + beforeInstall: function(options: any) { if (options.ignoredUpdateFiles && options.ignoredUpdateFiles.length > 0) { - return Blueprint.ignoredUpdateFiles = Blueprint.ignoredUpdateFiles.concat(options.ignoredUpdateFiles); + return Blueprint.ignoredUpdateFiles = + Blueprint.ignoredUpdateFiles.concat(options.ignoredUpdateFiles); } }, - locals: function(options) { + locals: function(options: any) { this.styleExt = options.style; this.version = require(path.resolve(__dirname, '../../package.json')).version; - // set this.tests to opposite of skipTest options, meaning if tests are being skipped then the default.spec.BLUEPRINT will be false + // set this.tests to opposite of skipTest options, + // meaning if tests are being skipped then the default.spec.BLUEPRINT will be false this.tests = options.skipTests ? false : true; // Split/join with / not path.sep as reference to typings require forward slashes. const relativeRootPath = options.sourceDir.split('/').map(() => '..').join('/'); - const fullAppName = stringUtils.dasherize(options.entity.name) + const fullAppName = (stringUtils.dasherize(options.entity.name) as string) .replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase()) .replace(/^./, (l) => l.toUpperCase()); @@ -51,7 +53,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && !this.options.routing) { fileList = fileList.filter(p => p.indexOf('app-routing.module.ts') < 0); @@ -73,7 +75,7 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. return { __path__: () => { @@ -84,4 +86,4 @@ module.exports = { } }; } -}; +}); diff --git a/packages/angular-cli/blueprints/pipe/index.js b/packages/angular-cli/blueprints/pipe/index.ts similarity index 79% rename from packages/angular-cli/blueprints/pipe/index.js rename to packages/angular-cli/blueprints/pipe/index.ts index e7555f52e31b..8d37e0d05b67 100644 --- a/packages/angular-cli/blueprints/pipe/index.js +++ b/packages/angular-cli/blueprints/pipe/index.ts @@ -9,7 +9,7 @@ const NodeHost = require('@angular-cli/ast-tools').NodeHost; const Blueprint = require('../../ember-cli/lib/models/blueprint'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -20,7 +20,7 @@ module.exports = { { name: 'export', type: Boolean, default: false } ], - beforeInstall: function(options) { + beforeInstall: function(options: any) { if (options.module) { // Resolve path to module const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`; @@ -33,7 +33,7 @@ module.exports = { } else { try { this.pathToModule = findParentModule(this.project, this.dynamicPath.dir); - } catch(e) { + } catch (e) { if (!options.skipImport) { throw `Error locating module for declaration\n\t${e}`; } @@ -41,14 +41,14 @@ module.exports = { } }, - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { options.spec = options.spec !== undefined ? options.spec : this.project.ngConfigObj.get('defaults.spec.pipe'); @@ -60,7 +60,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.pipe.spec.ts') < 0); @@ -69,11 +69,11 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. return { __path__: () => { - var dir = this.dynamicPath.dir; + let dir = this.dynamicPath.dir; if (!options.locals.flat) { dir += path.sep + options.dasherizedModuleName; } @@ -83,12 +83,12 @@ module.exports = { }; }, - afterInstall: function(options) { + afterInstall: function(options: any) { if (options.dryRun) { return; } - const returns = []; + const returns: Array = []; const className = stringUtils.classify(`${options.entity.name}Pipe`); const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`); const fullGeneratePath = path.join(this.project.root, this.generatePath); @@ -99,17 +99,19 @@ module.exports = { if (!options.skipImport) { returns.push( astUtils.addDeclarationToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)) - .then((result) => { + .then((change: any) => change.apply(NodeHost)) + .then((result: any) => { if (options.export) { return astUtils.addExportToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost)); + .then((change: any) => change.apply(NodeHost)); } return result; })); - this._writeStatusToUI(chalk.yellow, 'update', path.relative(this.project.root, this.pathToModule)); + this._writeStatusToUI(chalk.yellow, + 'update', + path.relative(this.project.root, this.pathToModule)); } return Promise.all(returns); } -}; +}); diff --git a/packages/angular-cli/blueprints/service/index.js b/packages/angular-cli/blueprints/service/index.ts similarity index 75% rename from packages/angular-cli/blueprints/service/index.js rename to packages/angular-cli/blueprints/service/index.ts index 2707fe1ddce1..bc1366e8f186 100644 --- a/packages/angular-cli/blueprints/service/index.js +++ b/packages/angular-cli/blueprints/service/index.ts @@ -1,3 +1,5 @@ +import { oneLine } from 'common-tags'; + const path = require('path'); const fs = require('fs'); const chalk = require('chalk'); @@ -8,7 +10,7 @@ const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); const getFiles = Blueprint.prototype.files; -module.exports = { +export default Blueprint.extend({ description: '', availableOptions: [ @@ -17,7 +19,7 @@ module.exports = { { name: 'module', type: String, aliases: ['m'] } ], - beforeInstall: function(options) { + beforeInstall: function(options: any) { if (options.module) { // Resolve path to module const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`; @@ -30,14 +32,14 @@ module.exports = { } }, - normalizeEntityName: function (entityName) { - var parsedPath = dynamicPathParser(this.project, entityName); + normalizeEntityName: function (entityName: string) { + const parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function (options) { + locals: function (options: any) { options.spec = options.spec !== undefined ? options.spec : this.project.ngConfigObj.get('defaults.spec.service'); @@ -49,7 +51,7 @@ module.exports = { }, files: function() { - var fileList = getFiles.call(this); + let fileList = getFiles.call(this) as Array; if (this.options && !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.service.spec.ts') < 0); @@ -58,11 +60,11 @@ module.exports = { return fileList; }, - fileMapTokens: function (options) { + fileMapTokens: function (options: any) { // Return custom template variables here. return { __path__: () => { - var dir = this.dynamicPath.dir; + let dir = this.dynamicPath.dir; if (!options.locals.flat) { dir += path.sep + options.dasherizedModuleName; } @@ -72,11 +74,14 @@ module.exports = { }; }, - afterInstall(options) { - const returns = []; + afterInstall(options: any) { + const returns: Array = []; if (!this.pathToModule) { - const warningMessage = 'Service is generated but not provided, it must be provided to be used'; + const warningMessage = oneLine` + Service is generated but not provided, + it must be provided to be used + `; this._writeStatusToUI(chalk.yellow, 'WARNING', warningMessage); } else { const className = stringUtils.classify(`${options.entity.name}Service`); @@ -87,10 +92,12 @@ module.exports = { const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; returns.push( astUtils.addProviderToModule(this.pathToModule, className, importPath) - .then(change => change.apply(NodeHost))); - this._writeStatusToUI(chalk.yellow, 'update', path.relative(this.project.root, this.pathToModule)); + .then((change: any) => change.apply(NodeHost))); + this._writeStatusToUI(chalk.yellow, + 'update', + path.relative(this.project.root, this.pathToModule)); } return Promise.all(returns); } -}; +}); diff --git a/packages/angular-cli/ember-cli/lib/models/blueprint.js b/packages/angular-cli/ember-cli/lib/models/blueprint.js index 98b49636222a..a5ab7e5cdba5 100644 --- a/packages/angular-cli/ember-cli/lib/models/blueprint.js +++ b/packages/angular-cli/ember-cli/lib/models/blueprint.js @@ -1202,17 +1202,17 @@ Blueprint.lookup = function(name, options) { @return {Blueprint} blueprint instance */ Blueprint.load = function(blueprintPath) { - var constructorPath = path.resolve(blueprintPath, 'index.js'); + var constructorPath = path.join(path.resolve(blueprintPath), 'index'); var blueprintModule; var Constructor = Blueprint; if (fs.lstatSync(blueprintPath).isDirectory()) { - - if (existsSync(constructorPath)) { - blueprintModule = require(constructorPath); - + blueprintModule = require(constructorPath); + if (blueprintModule) { if (typeof blueprintModule === 'function') { Constructor = blueprintModule; + } else if (typeof blueprintModule.default === 'function') { + Constructor = blueprintModule.default } else { Constructor = Blueprint.extend(blueprintModule); }