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

Commit fd88b5b

Browse files
authored
Merge pull request #8 from simonihmig/mu-blueprints
Add MU component blueprint
2 parents 7873a3c + 38c2812 commit fd88b5b

File tree

16 files changed

+321
-66
lines changed

16 files changed

+321
-66
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
'ember-cli-build.js',
2424
'index.js',
2525
'testem.js',
26-
'blueprints/*/index.js',
26+
'blueprints/**/*.js',
2727
'config/**/*.js',
2828
'tests/dummy/config/**/*.js',
2929
'lib/**/*.js',

blueprints/-addon-import.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-env node */
21
'use strict';
32

43
var stringUtil = require('ember-cli-string-utils');

blueprints/component-test/index.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const isPackageMissing = require('ember-cli-is-package-missing');
66
const getPathOption = require('ember-cli-get-component-path-option');
77

88
const useTestFrameworkDetector = require('../test-framework-detector');
9+
const { isModuleUnificationProject } = require('../module-unification');
910

1011
module.exports = useTestFrameworkDetector({
1112
description: 'Generates a component integration or unit test.',
@@ -25,17 +26,46 @@ module.exports = useTestFrameworkDetector({
2526
],
2627

2728
fileMapTokens: function() {
28-
return {
29-
__testType__: function(options) {
30-
return options.locals.testType || 'integration';
31-
},
32-
__path__: function(options) {
33-
if (options.pod) {
34-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
29+
if (isModuleUnificationProject(this.project)) {
30+
return {
31+
__test__() {
32+
return 'component-test';
33+
},
34+
__root__(options) {
35+
if (options.inRepoAddon) {
36+
return path.join('packages', options.inRepoAddon, 'src');
37+
}
38+
return 'src';
39+
},
40+
__testType__(options) {
41+
if (options.locals.testType === 'unit') {
42+
throw new Error('The --unit flag isn\'t supported within a module unification app');
43+
}
44+
return '';
45+
},
46+
__path__(options) {
47+
if (options.pod) {
48+
throw new Error('Pods aren\'t supported within a module unification app');
49+
}
50+
return path.join('ui', 'components', options.dasherizedModuleName);
3551
}
36-
return 'components';
37-
}
38-
};
52+
};
53+
} else {
54+
return {
55+
__root__() {
56+
return 'tests';
57+
},
58+
__testType__(options) {
59+
return options.locals.testType || 'integration';
60+
},
61+
__path__(options) {
62+
if (options.pod) {
63+
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
64+
}
65+
return 'components';
66+
}
67+
};
68+
}
3969
},
4070
locals: function(options) {
4171
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);

blueprints/component-test/mocha-0.12-files/tests/__testType__/__path__/__test__.ts renamed to blueprints/component-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.ts

File renamed without changes.

blueprints/component-test/mocha-files/tests/__testType__/__path__/__test__.ts renamed to blueprints/component-test/mocha-files/__root__/__testType__/__path__/__test__.ts

File renamed without changes.

blueprints/component-test/qunit-files/tests/__testType__/__path__/__test__.ts renamed to blueprints/component-test/qunit-files/__root__/__testType__/__path__/__test__.ts

File renamed without changes.

blueprints/component-test/qunit-rfc-232-files/tests/__testType__/__path__/__test__.ts renamed to blueprints/component-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.ts

File renamed without changes.

blueprints/component/index.js

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const pathUtil = require('ember-cli-path-utils');
66
const validComponentName = require('ember-cli-valid-component-name');
77
const getPathOption = require('ember-cli-get-component-path-option');
88
const normalizeEntityName = require('ember-cli-normalize-entity-name');
9+
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
910

1011
module.exports = {
1112
description: 'Generates a component. Name must contain a hyphen.',
@@ -21,27 +22,54 @@ module.exports = {
2122
}
2223
],
2324

25+
filesPath: function() {
26+
let filesDirectory = 'files';
27+
28+
if (isModuleUnificationProject(this.project)) {
29+
filesDirectory = 'module-unification-files';
30+
}
31+
32+
return path.join(this.path, filesDirectory);
33+
},
34+
2435
fileMapTokens: function() {
25-
return {
26-
__path__: function(options) {
27-
if (options.pod) {
28-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
36+
if (isModuleUnificationProject(this.project)) {
37+
return {
38+
__root__(options) {
39+
if (options.inRepoAddon) {
40+
return path.join('packages', options.inRepoAddon, 'src');
41+
}
42+
if (options.inDummy) {
43+
return path.join('tests', 'dummy', 'src');
44+
}
45+
return 'src';
46+
},
47+
__path__(options) {
48+
return path.join('ui', 'components', options.dasherizedModuleName);
49+
},
50+
};
51+
} else {
52+
return {
53+
__path__: function(options) {
54+
if (options.pod) {
55+
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
56+
}
57+
return 'components';
58+
},
59+
__templatepath__: function(options) {
60+
if (options.pod) {
61+
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
62+
}
63+
return 'templates/components';
64+
},
65+
__templatename__: function(options) {
66+
if (options.pod) {
67+
return 'template';
68+
}
69+
return options.dasherizedModuleName;
2970
}
30-
return 'components';
31-
},
32-
__templatepath__: function(options) {
33-
if (options.pod) {
34-
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
35-
}
36-
return 'templates/components';
37-
},
38-
__templatename__: function(options) {
39-
if (options.pod) {
40-
return 'template';
41-
}
42-
return options.dasherizedModuleName;
43-
}
44-
};
71+
};
72+
}
4573
},
4674

4775
normalizeEntityName: function(entityName) {
@@ -51,19 +79,19 @@ module.exports = {
5179
},
5280

5381
locals: function(options) {
54-
let templatePath = '';
82+
let templatePath = '';
5583
let importTemplate = '';
56-
let contents = '';
84+
let contents = '';
5785
// if we're in an addon, build import statement
5886
if (options.project.isEmberCLIAddon() || options.inRepoAddon && !options.inDummy) {
5987
if (options.pod) {
60-
templatePath = './template';
88+
templatePath = './template';
6189
} else {
62-
templatePath = pathUtil.getRelativeParentPath(options.entity.name) +
90+
templatePath = pathUtil.getRelativeParentPath(options.entity.name) +
6391
'templates/components/' + stringUtil.dasherize(options.entity.name);
6492
}
65-
importTemplate = '// @ts-ignore: Ignore import of compiled template\nimport layout from \'' + templatePath + '\';\n';
66-
contents = '\n layout = layout;';
93+
importTemplate = '// @ts-ignore: Ignore import of compiled template\nimport layout from \'' + templatePath + '\';\n';
94+
contents = '\n layout = layout;';
6795
}
6896

6997
return {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Component from '@ember/component';
2+
3+
export default class <%= classifiedModuleName %> extends Component.extend({
4+
// anything which *must* be merged to prototype here
5+
}) {
6+
// normal class body definition here
7+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{yield}}

0 commit comments

Comments
 (0)