Skip to content

Commit 4671d46

Browse files
authored
Merge pull request #20773 from Windvis/rfc-995-component-generator-cleanup
[Cleanup] Component blueprint cleanup
2 parents 0f9b3fc + 36242f3 commit 4671d46

File tree

4 files changed

+16
-439
lines changed

4 files changed

+16
-439
lines changed

blueprints/component-class/index.js

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
'use strict';
22

3-
const path = require('path');
43
const SilentError = require('silent-error');
54
const stringUtil = require('ember-cli-string-utils');
6-
const pathUtil = require('ember-cli-path-utils');
75
const getPathOption = require('ember-cli-get-component-path-option');
86
const normalizeEntityName = require('ember-cli-normalize-entity-name');
9-
const { EOL } = require('os');
107
const { has } = require('@ember/edition-utils');
118
const { generateComponentSignature } = require('../-utils');
129

@@ -44,9 +41,9 @@ module.exports = {
4441
},
4542
{
4643
name: 'component-structure',
47-
type: OCTANE ? ['flat', 'nested', 'classic'] : ['classic'],
48-
default: OCTANE ? 'flat' : 'classic',
49-
aliases: OCTANE ? [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }] : [{ cs: 'classic' }],
44+
type: ['flat', 'nested'],
45+
default: 'flat',
46+
aliases: [{ fs: 'flat' }, { ns: 'nested' }],
5047
},
5148
],
5249

@@ -71,15 +68,9 @@ module.exports = {
7168
option.default = '@ember/component';
7269
}
7370
} else if (option.name === 'component-structure') {
74-
if (isOctane) {
75-
option.type = ['flat', 'nested', 'classic'];
76-
option.default = 'flat';
77-
option.aliases = [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }];
78-
} else {
79-
option.type = ['classic'];
80-
option.default = 'classic';
81-
option.aliases = [{ cs: 'classic' }];
82-
}
71+
option.type = ['flat', 'nested'];
72+
option.default = 'flat';
73+
option.aliases = [{ fs: 'flat' }, { ns: 'nested' }];
8374
}
8475
});
8576

@@ -99,19 +90,7 @@ module.exports = {
9990
fileMapTokens(options) {
10091
let commandOptions = this.options;
10192

102-
if (commandOptions.pod) {
103-
return {
104-
__path__() {
105-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
106-
},
107-
__name__() {
108-
return 'component';
109-
},
110-
};
111-
} else if (
112-
commandOptions.componentStructure === 'classic' ||
113-
commandOptions.componentStructure === 'flat'
114-
) {
93+
if (commandOptions.componentStructure === 'flat') {
11594
return {
11695
__path__() {
11796
return 'components';
@@ -139,35 +118,17 @@ module.exports = {
139118
let sanitizedModuleName = options.entity.name.replace(/\//g, '-');
140119
let classifiedModuleName = stringUtil.classify(sanitizedModuleName);
141120

142-
let templatePath = '';
143121
let importComponent = '';
144122
let importTemplate = '';
145123
let defaultExport = '';
146124
let componentSignature = '';
147125

148-
// if we're in an addon, build import statement
149-
if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
150-
if (options.pod) {
151-
templatePath = './template';
152-
} else {
153-
templatePath =
154-
pathUtil.getRelativeParentPath(options.entity.name) +
155-
'templates/components/' +
156-
stringUtil.dasherize(options.entity.name);
157-
}
158-
}
159-
160126
let componentClass = options.componentClass;
161127

162128
switch (componentClass) {
163129
case '@ember/component':
164130
importComponent = `import Component from '@ember/component';`;
165-
if (templatePath) {
166-
importTemplate = `import layout from '${templatePath}';${EOL}`;
167-
defaultExport = `Component.extend({${EOL} layout${EOL}});`;
168-
} else {
169-
defaultExport = `Component.extend({});`;
170-
}
131+
defaultExport = `Component.extend({});`;
171132
break;
172133
case '@glimmer/component':
173134
importComponent = `import Component from '@glimmer/component';`;

blueprints/component/index.js

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
'use strict';
22

33
const chalk = require('chalk');
4-
const path = require('path');
54
const SilentError = require('silent-error');
65
const stringUtil = require('ember-cli-string-utils');
7-
const pathUtil = require('ember-cli-path-utils');
86
const getPathOption = require('ember-cli-get-component-path-option');
97
const normalizeEntityName = require('ember-cli-normalize-entity-name');
10-
const { EOL } = require('os');
118
const { has } = require('@ember/edition-utils');
129
const { generateComponentSignature } = require('../-utils');
1310

@@ -48,9 +45,9 @@ module.exports = {
4845
},
4946
{
5047
name: 'component-structure',
51-
type: OCTANE ? ['flat', 'nested', 'classic'] : ['classic'],
52-
default: OCTANE ? 'flat' : 'classic',
53-
aliases: OCTANE ? [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }] : [{ cs: 'classic' }],
48+
type: ['flat', 'nested'],
49+
default: 'flat',
50+
aliases: [{ fs: 'flat' }, { ns: 'nested' }],
5451
},
5552
],
5653

@@ -75,15 +72,9 @@ module.exports = {
7572
option.default = '@ember/component';
7673
}
7774
} else if (option.name === 'component-structure') {
78-
if (isOctane) {
79-
option.type = ['flat', 'nested', 'classic'];
80-
option.default = 'flat';
81-
option.aliases = [{ fs: 'flat' }, { ns: 'nested' }, { cs: 'classic' }];
82-
} else {
83-
option.type = ['classic'];
84-
option.default = 'classic';
85-
option.aliases = [{ cs: 'classic' }];
86-
}
75+
option.type = ['flat', 'nested'];
76+
option.default = 'flat';
77+
option.aliases = [{ fs: 'flat' }, { ns: 'nested' }];
8778
}
8879
});
8980

@@ -107,12 +98,6 @@ module.exports = {
10798
'Usage of --component-class argument to `ember generate component` is only available on canary'
10899
);
109100
}
110-
111-
if (options.componentStructure !== 'classic') {
112-
throw new SilentError(
113-
'Usage of --component-structure argument to `ember generate component` is only available on canary'
114-
);
115-
}
116101
}
117102

118103
return this._super.install.apply(this, arguments);
@@ -149,37 +134,7 @@ module.exports = {
149134
fileMapTokens(options) {
150135
let commandOptions = this.options;
151136

152-
if (commandOptions.pod) {
153-
return {
154-
__path__() {
155-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
156-
},
157-
__templatepath__() {
158-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
159-
},
160-
__templatename__() {
161-
return 'template';
162-
},
163-
};
164-
} else if (
165-
!this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE ||
166-
commandOptions.componentStructure === 'classic'
167-
) {
168-
return {
169-
__path__() {
170-
return 'components';
171-
},
172-
__templatepath__() {
173-
return 'templates/components';
174-
},
175-
__templatename__() {
176-
return options.dasherizedModuleName;
177-
},
178-
};
179-
} else if (
180-
this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE &&
181-
commandOptions.componentStructure === 'flat'
182-
) {
137+
if (this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE && commandOptions.componentStructure === 'flat') {
183138
return {
184139
__path__() {
185140
return 'components';
@@ -236,19 +191,6 @@ module.exports = {
236191
},
237192

238193
locals(options) {
239-
// if we're in an addon, build import statement
240-
let templatePath = '';
241-
if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
242-
if (options.pod) {
243-
templatePath = './template';
244-
} else {
245-
templatePath =
246-
pathUtil.getRelativeParentPath(options.entity.name) +
247-
'templates/components/' +
248-
stringUtil.dasherize(options.entity.name);
249-
}
250-
}
251-
252194
let componentClass = this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE
253195
? options.componentClass
254196
: '@ember/component';
@@ -264,12 +206,7 @@ module.exports = {
264206
switch (componentClass) {
265207
case '@ember/component':
266208
importComponent = `import Component from '@ember/component';`;
267-
if (templatePath) {
268-
importTemplate = `import layout from '${templatePath}';${EOL}`;
269-
defaultExport = `Component.extend({${EOL} layout${EOL}});`;
270-
} else {
271-
defaultExport = `Component.extend({});`;
272-
}
209+
defaultExport = `Component.extend({});`;
273210
break;
274211
case '@glimmer/component':
275212
importComponent = `import Component from '@glimmer/component';`;

node-tests/blueprints/component-class-test.js

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
44
const setupTestHooks = blueprintHelpers.setupTestHooks;
55
const emberNew = blueprintHelpers.emberNew;
66
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7-
const setupPodConfig = blueprintHelpers.setupPodConfig;
87
const modifyPackages = blueprintHelpers.modifyPackages;
98

109
const chai = require('ember-cli-blueprint-test-helpers/chai');
1110
const expect = chai.expect;
1211

1312
const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
14-
const fixture = require('../helpers/fixture');
1513

1614
const setupTestEnvironment = require('../helpers/setup-test-environment');
1715
const enableOctane = setupTestEnvironment.enableOctane;
@@ -54,23 +52,6 @@ describe('Blueprint: component-class', function () {
5452
});
5553
});
5654

57-
// classic default
58-
it('component-class foo --component-structure=classic --component-class=@ember/component', function () {
59-
return emberGenerateDestroy(
60-
[
61-
'component-class',
62-
'foo',
63-
'--component-structure',
64-
'classic',
65-
'--component-class',
66-
'@ember/component',
67-
],
68-
(_file) => {
69-
expect(_file('app/components/foo.js')).to.equal(emberComponentContents);
70-
}
71-
);
72-
});
73-
7455
// Octane default
7556
it('component-class foo --component-structure=flat --component-class=@glimmer/component', function () {
7657
return emberGenerateDestroy(
@@ -106,15 +87,6 @@ describe('Blueprint: component-class', function () {
10687
);
10788
});
10889

109-
it('component-class foo --component-structure=classic', function () {
110-
return emberGenerateDestroy(
111-
['component-class', '--component-structure', 'classic', 'foo'],
112-
(_file) => {
113-
expect(_file('app/components/foo.js')).to.equal(glimmerComponentContents);
114-
}
115-
);
116-
});
117-
11890
it('component-class foo --component-class=@ember/component', function () {
11991
return emberGenerateDestroy(
12092
['component-class', '--component-class', '@ember/component', 'foo'],
@@ -177,99 +149,6 @@ describe('Blueprint: component-class', function () {
177149
}
178150
);
179151
});
180-
181-
describe('with podModulePrefix', function () {
182-
beforeEach(function () {
183-
setupPodConfig({ podModulePrefix: true });
184-
});
185-
186-
it('component-class foo --pod', function () {
187-
return emberGenerateDestroy(['component-class', 'foo', '--pod'], (_file) => {
188-
expect(_file('app/pods/components/foo/component.js')).to.equal(
189-
fixture('component/component.js')
190-
);
191-
});
192-
});
193-
194-
it('component-class x-foo --pod', function () {
195-
return emberGenerateDestroy(['component-class', 'x-foo', '--pod'], (_file) => {
196-
expect(_file('app/pods/components/x-foo/component.js')).to.equal(
197-
fixture('component/component-dash.js')
198-
);
199-
});
200-
});
201-
202-
it('component-class foo/x-foo --pod', function () {
203-
return emberGenerateDestroy(['component-class', 'foo/x-foo', '--pod'], (_file) => {
204-
expect(_file('app/pods/components/foo/x-foo/component.js')).to.equal(
205-
fixture('component/component-nested.js')
206-
);
207-
});
208-
});
209-
210-
it('component-class x-foo --pod --path foo', function () {
211-
return emberGenerateDestroy(
212-
['component-class', 'x-foo', '--pod', '--path', 'foo'],
213-
(_file) => {
214-
expect(_file('app/pods/foo/x-foo/component.js')).to.equal(
215-
fixture('component/component-dash.js')
216-
);
217-
}
218-
);
219-
});
220-
221-
it('component-class foo/x-foo --pod --path bar', function () {
222-
return emberGenerateDestroy(
223-
['component-class', 'foo/x-foo', '--pod', '--path', 'bar'],
224-
(_file) => {
225-
expect(_file('app/pods/bar/foo/x-foo/component.js')).to.equal(
226-
fixture('component/component-nested.js')
227-
);
228-
}
229-
);
230-
});
231-
232-
it('component-class x-foo --pod --path bar/foo', function () {
233-
return emberGenerateDestroy(
234-
['component-class', 'x-foo', '--pod', '--path', 'bar/foo'],
235-
(_file) => {
236-
expect(_file('app/pods/bar/foo/x-foo/component.js')).to.equal(
237-
fixture('component/component-dash.js')
238-
);
239-
}
240-
);
241-
});
242-
243-
it('component-class foo/x-foo --pod --path bar/baz', function () {
244-
return emberGenerateDestroy(
245-
['component-class', 'foo/x-foo', '--pod', '--path', 'bar/baz'],
246-
(_file) => {
247-
expect(_file('app/pods/bar/baz/foo/x-foo/component.js')).to.equal(
248-
fixture('component/component-nested.js')
249-
);
250-
}
251-
);
252-
});
253-
254-
it('component-class x-foo --pod -no-path', function () {
255-
return emberGenerateDestroy(['component-class', 'x-foo', '--pod', '-no-path'], (_file) => {
256-
expect(_file('app/pods/x-foo/component.js')).to.equal(
257-
fixture('component/component-dash.js')
258-
);
259-
});
260-
});
261-
262-
it('component-class foo/x-foo --pod -no-path', function () {
263-
return emberGenerateDestroy(
264-
['component-class', 'foo/x-foo', '--pod', '-no-path'],
265-
(_file) => {
266-
expect(_file('app/pods/foo/x-foo/component.js')).to.equal(
267-
fixture('component/component-nested.js')
268-
);
269-
}
270-
);
271-
});
272-
});
273152
});
274153

275154
describe('in addon - octane', function () {

0 commit comments

Comments
 (0)