Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Update component blueprints to be Octane friendly #248

Open
wants to merge 4 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# unconventional js
/blueprints/*/files/
/blueprints/*/*files/**/*.js
/blueprints/*/*files/**/*.ts
/fixtures/**/*.d.ts
/vendor/

# compiled output
Expand Down
63 changes: 38 additions & 25 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,77 @@ module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
sourceType: 'module',
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
env: {
browser: true
},
rules: {
browser: true,
},
rules: {},
overrides: [
// blueprint generators
{
files: [
'blueprints/*.js',
'blueprints/**/index.js',
'lib/utilities/extend-from-application-entity.js',
],
rules: {
'ember/no-string-prototype-extensions': 'off',
},
},
// dummy files
{
files: ['tests/dummy/app/*.js'],
rules: {
'ember/no-classic-classes': 'off',
},
},
// node files
{
files: [
'./.eslintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/**/*.js',
'blueprints/*.js', // test-framework-detector.js
'blueprints/*/*.js', // index.js for each blueprint
'config/**/*.js',
'tests/dummy/config/**/*.js',
'lib/**/*.js',
'node-tests/**/*.js'
'node-tests/**/*.js', // mocha test files
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
'tests/dummy/app/**',
'node-tests/fixtures/**',
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
ecmaVersion: 2015,
},
env: {
browser: false,
node: true
node: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}),
},

// node tests
{
files: [
'node-tests/**/*.js'
],
files: ['node-tests/**/*.js'],
env: {
mocha: true
mocha: true,
},
rules: {
'node/no-unpublished-require': 'off'
}
}
]
'node/no-unpublished-require': 'off',
},
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/node_modules/

# misc
/.eslintcache
/.sass-cache
/connect.lock
/coverage/
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
blueprints/**/*files/**/*.js
blueprints/**/*files/**/*.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
75 changes: 75 additions & 0 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');

module.exports = {
description: 'Generates a component.',

fileMapTokens: function () {
return {
__path__: function (options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'components';
},
__name__: function (options) {
if (options.pod) {
return 'component';
}
return options.dasherizedModuleName;
},
__root__: function (options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
},
__templatepath__: function (options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'templates/components';
},
__templatename__: function (options) {
if (options.pod) {
return 'template';
}
return options.dasherizedModuleName;
},
};
},

normalizeEntityName: function (entityName) {
return normalizeEntityName(entityName);
},

locals: function (options) {
let addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
let addonName = stringUtil.dasherize(addonRawName);
let fileName = stringUtil.dasherize(options.entity.name);
let importPathName = [addonName, 'components', fileName].join('/');
let templatePath = '';

if (options.pod) {
importPathName = [addonName, 'components', fileName, 'component'].join('/');
}

if (this.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
if (options.pod) {
templatePath = './template';
} else {
templatePath = [addonName, 'templates/components', fileName].join('/');
}
}

return {
modulePath: importPathName,
templatePath,
path: getPathOption(options),
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
53 changes: 53 additions & 0 deletions blueprints/component-class-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');

module.exports = {
description: 'Generates a component class.',

fileMapTokens: function () {
return {
__path__: function (options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'components';
},
__name__: function (options) {
if (options.pod) {
return 'component';
}
return options.dasherizedModuleName;
},
__root__: function (options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
},
};
},

normalizeEntityName: function (entityName) {
return normalizeEntityName(entityName);
},

locals: function (options) {
let addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
let addonName = stringUtil.dasherize(addonRawName);
let fileName = stringUtil.dasherize(options.entity.name);
let importPathName = [addonName, 'components', fileName].join('/');

if (options.pod) {
importPathName = [addonName, 'components', fileName, 'component'].join('/');
}

return {
modulePath: importPathName,
path: getPathOption(options),
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= importComponent %>
<%= importTemplate %>
export default <%= defaultExport %>
Loading