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

improve component blueprint for octane #218

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95b71c3
improve component blueprint for octane
BryanCrotaz Nov 8, 2020
eb10f74
remove unnecessary element definition
BryanCrotaz Nov 8, 2020
6fbeb4e
Update blueprints/component/files/__root__/__path__/__name__.ts
BryanCrotaz Nov 15, 2020
3111707
remove module unification files
BryanCrotaz Nov 15, 2020
6055241
remove ember-cli-shims and add peer dependencies
BryanCrotaz Nov 15, 2020
b9e0ad2
use node 12 to build on travis
BryanCrotaz Nov 15, 2020
25f77b0
fix no-prototype-builtins
BryanCrotaz Nov 15, 2020
71a2331
fix typo
BryanCrotaz Nov 15, 2020
8a74fee
add extraneous modules
BryanCrotaz Nov 15, 2020
7bf4065
move extraneous packages to dependencies
BryanCrotaz Nov 15, 2020
48fb02d
fix no-undef
BryanCrotaz Nov 15, 2020
ad17126
run with node 12 on appveyor
BryanCrotaz Nov 15, 2020
bb3bd3f
remove comment
BryanCrotaz Nov 15, 2020
018efdc
Merge branch master into octane-3
BryanCrotaz Nov 16, 2020
eedab5d
tidy up
BryanCrotaz Nov 16, 2020
1931c0a
Merge remote-tracking branch 'upstream/master' into octane-3
BryanCrotaz Nov 17, 2020
c1b73fb
yarn lock clean up
BryanCrotaz Nov 17, 2020
71dae68
remove jquery from generated tests
BryanCrotaz Nov 17, 2020
5123288
use ember-cli-htmlbars for testing this addon
BryanCrotaz Nov 17, 2020
83bbd00
Update node-tests/fixtures/component/component-nested.ts
BryanCrotaz Nov 17, 2020
e59a57f
Update node-tests/fixtures/component/component.ts
BryanCrotaz Nov 17, 2020
f4c3748
Update node-tests/fixtures/component/component-addon.ts
BryanCrotaz Nov 17, 2020
cead5d8
Update node-tests/fixtures/component/component-addon-nested.ts
BryanCrotaz Nov 17, 2020
cf0761b
clean up fixtures
BryanCrotaz Nov 17, 2020
5682b8c
fix linting and clean packages
BryanCrotaz Nov 17, 2020
7569313
remove unit tests for components
BryanCrotaz Nov 24, 2020
38ee3cd
update fixtures to remove unit tests
BryanCrotaz Nov 24, 2020
5b262cd
remove tests for unit testing components
BryanCrotaz Nov 24, 2020
4fe2936
fix helper test import of hbs
BryanCrotaz Nov 24, 2020
7f3d40c
use correct component name in tests
BryanCrotaz Nov 24, 2020
d7c98e4
generate correct component name
BryanCrotaz Nov 24, 2020
fd0febb
correct the component name creation
BryanCrotaz Nov 24, 2020
a878d30
fix component name generation
BryanCrotaz Nov 24, 2020
c0a09b9
bring in default blueprints from ember.js
BryanCrotaz Nov 24, 2020
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env node */
module.exports = {
root: true,
parserOptions: {
Expand Down
48 changes: 48 additions & 0 deletions blueprints/-addon-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const stringUtil = require('ember-cli-string-utils');
const path = require('path');
const inflector = require('inflection');

module.exports = {
description: 'Generates an import wrapper.',

fileMapTokens: function () {
return {
__name__: function (options) {
return options.dasherizedModuleName;
},
__path__: function (options) {
return inflector.pluralize(options.locals.blueprintName);
},
__root__: function (options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
},
};
},

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 blueprintName = options.originBlueprintName;
let modulePathSegments = [
addonName,
inflector.pluralize(options.originBlueprintName),
fileName,
];

if (blueprintName.match(/-addon/)) {
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
}

return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName,
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
76 changes: 76 additions & 0 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'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');
const useEditionDetector = require('../edition-detector');

module.exports = useEditionDetector({
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 %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
54 changes: 54 additions & 0 deletions blueprints/component-class-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'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');
const useEditionDetector = require('../edition-detector');

module.exports = useEditionDetector({
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 @@
export { default } from '<%= modulePath %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= importComponent %>
<%= importTemplate %>
export default <%= defaultExport %>
175 changes: 175 additions & 0 deletions blueprints/component-class/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
'use strict';

const path = require('path');
const SilentError = require('silent-error');
const stringUtil = require('ember-cli-string-utils');
const pathUtil = require('ember-cli-path-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const { EOL } = require('os');
const { has } = require('@ember/edition-utils');

const OCTANE = has('octane');

// TODO: this should be reading from the @ember/canary-features module
// need to refactor broccoli/features.js to be able to work more similarly
// to https://github.com/emberjs/data/pull/6231
const EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = true;

// intentionally avoiding use-edition-detector
module.exports = {
description: 'Generates a component class.',

availableOptions: [
{
name: 'path',
type: String,
default: 'components',
aliases: [{ 'no-path': '' }],
},
{
name: 'component-class',
type: ['@ember/component', '@glimmer/component', '@ember/component/template-only'],
default: OCTANE ? '@glimmer/component' : '@ember/component',
aliases: [
{ cc: '@ember/component' },
{ gc: '@glimmer/component' },
{ tc: '@ember/component/template-only' },
],
},
{
name: 'component-structure',
type: OCTANE ? ['flat', 'nested', 'classic'] : ['classic'],
default: OCTANE ? 'flat' : 'classic',
aliases: OCTANE ? [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }] : [{ cs: 'classic' }],
},
],

init() {
this._super && this._super.init.apply(this, arguments);
let isOctane = has('octane');

this.availableOptions.forEach((option) => {
if (option.name === 'component-class') {
if (isOctane) {
option.default = '@glimmer/component';
} else {
option.default = '@ember/component';
}
} else if (option.name === 'component-structure') {
if (isOctane) {
option.type = ['flat', 'nested', 'classic'];
option.default = 'flat';
option.aliases = [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }];
} else {
option.type = ['classic'];
option.default = 'classic';
option.aliases = [{ cs: 'classic' }];
}
}
});

this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = EMBER_GLIMMER_SET_COMPONENT_TEMPLATE || isOctane;
},

install() {
if (!this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) {
throw new SilentError(
'Usage of `ember generate component-class` is only available on canary'
);
}

return this._super.install.apply(this, arguments);
},

fileMapTokens(options) {
let commandOptions = this.options;

if (commandOptions.pod) {
return {
__path__() {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
},
__name__() {
return 'component';
},
};
} else if (
commandOptions.componentStructure === 'classic' ||
commandOptions.componentStructure === 'flat'
) {
return {
__path__() {
return 'components';
},
};
} else if (commandOptions.componentStructure === 'nested') {
return {
__path__() {
return `components/${options.dasherizedModuleName}`;
},
__name__() {
return 'index';
},
};
}
},

normalizeEntityName(entityName) {
return normalizeEntityName(
entityName.replace(/\.js$/, '') //Prevent generation of ".js.js" files
);
},

locals(options) {
let sanitizedModuleName = options.entity.name.replace(/\//g, '-');
let classifiedModuleName = stringUtil.classify(sanitizedModuleName);

let templatePath = '';
let importComponent = '';
let importTemplate = '';
let defaultExport = '';

// if we're in an addon, build import statement
if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
if (options.pod) {
templatePath = './template';
} else {
templatePath =
pathUtil.getRelativeParentPath(options.entity.name) +
'templates/components/' +
stringUtil.dasherize(options.entity.name);
}
}

let componentClass = options.componentClass;

switch (componentClass) {
case '@ember/component':
importComponent = `import Component from '@ember/component';`;
if (templatePath) {
importTemplate = `import layout from '${templatePath}';${EOL}`;
defaultExport = `Component.extend({${EOL} layout${EOL}});`;
} else {
defaultExport = `Component.extend({${EOL}});`;
}
break;
case '@glimmer/component':
importComponent = `import Component from '@glimmer/component';`;
defaultExport = `class ${classifiedModuleName}Component extends Component {\n}`;
break;
case '@ember/component/template-only':
importComponent = `import templateOnly from '@ember/component/template-only';`;
defaultExport = `templateOnly();`;
break;
}

return {
importTemplate,
importComponent,
defaultExport,
path: getPathOption(options),
componentClass,
};
},
};
Loading