Skip to content

Commit b918ac3

Browse files
committed
feat(new-application): add scaffolding feature for navigation skeleton
1 parent 076a59d commit b918ac3

36 files changed

+1632
-24
lines changed

lib/commands/new/buildsystems/cli/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ module.exports = function(project, options) {
108108
}
109109
}
110110

111+
for (let featureName in model.features) {
112+
project.addFeature(featureName, project, model, options);
113+
}
114+
111115
project.addToSource(
112-
ProjectItem.resource('main.ext', 'src/main-cli.ext', model.transpiler)
116+
ProjectItem.resource('main.ext', 'src/main-cli.template.ext', model.transpiler)
117+
.asTemplate(model)
113118
).addToTasks(
114119
ProjectItem.resource('build.ext', 'tasks/build.ext', model.transpiler),
115120
ProjectItem.resource('build.json', 'tasks/build.json'),

lib/commands/new/buildsystems/cli/loaders/require.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ module.exports = function(project, options) {
2424
project.addToClientDependencies(
2525
'requirejs',
2626
'text'
27+
)
28+
.addToContent(ProjectItem.resource('index.html', 'content/index.template.html')
29+
.asTemplate(model, { type: model.markupProcessor })
2730
);
28-
29-
if (model.platform.id === 'web') {
30-
project.addToContent(ProjectItem.resource('index.html', 'content/require.index.html'));
31-
}
3231
};

lib/commands/new/buildsystems/cli/loaders/system.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ module.exports = function(project, options) {
2828
project.addToClientDependencies(
2929
'systemjs',
3030
'systemjs-plugin-text'
31-
).addToContent(ProjectItem.resource('index.html', 'content/system.index.html'));
31+
)
32+
.addToContent(ProjectItem.resource('index.html', 'content/index.template.html')
33+
.asTemplate(model, { type: model.markupProcessor })
34+
);
3235
};

lib/commands/new/buildsystems/cli/platforms/aspnetcore.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = function(project) {
77
project.configureDist(ProjectItem.directory('scripts'));
88
project.configurePort(5000);
99
project.projectOutput.add(
10-
ProjectItem.resource('index.html', `content/${project.model.loader.id}.index.html`).askUserIfExists()
10+
ProjectItem.resource('index.html', `content/index.template.html`)
11+
.asTemplate(project.model, { type: project.model.markupProcessor })
12+
.askUserIfExists()
1113
);
1214
project.configureDefaultSetup();
1315
};

lib/commands/new/buildsystems/webpack/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ module.exports = function(project, options) {
3030
let configureEditor = require(`./editors/${model.editor.id}`);
3131
configureEditor(project);
3232

33+
for (let featureName in model.features) {
34+
project.addFeature(featureName, project, model, options);
35+
}
36+
3337
project.addToSource(
34-
ProjectItem.resource('main.ext', 'src/main-webpack.ext', model.transpiler)
38+
ProjectItem.resource('main.ext', 'src/main-webpack.template.ext', model.transpiler)
39+
.asTemplate(model)
3540
).addToTasks(
3641
ProjectItem.resource('build.ext', 'tasks/build-webpack.ext', project.model.transpiler),
3742
ProjectItem.resource('build.json', 'tasks/build.json'),

lib/commands/new/new-application.json

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@
6464
"integrationTestRunner": {
6565
"id": "none",
6666
"displayName": "None"
67-
}
67+
},
68+
"features": [
69+
{
70+
"id": "none",
71+
"displayName": "None"
72+
}
73+
]
6874
}
6975
},
7076
{
@@ -106,7 +112,7 @@
106112
"branches": [
107113
{
108114
"case": "default-esnext",
109-
"nextActivity": 1000
115+
"nextActivity": 950
110116
},
111117
{
112118
"case": "default-typescript",
@@ -121,7 +127,7 @@
121127
{
122128
"type": "state-assign",
123129
"id": 500,
124-
"nextActivity": 1000,
130+
"nextActivity": 950,
125131
"state": {
126132
"transpiler": {
127133
"id": "typescript",
@@ -223,13 +229,16 @@
223229
"coverage": false
224230
}
225231
},
226-
"unitTestRunners": [{
227-
"id": "jest",
228-
"displayName": "Jest"
229-
}, {
230-
"id": "karma",
231-
"displayName": "Karma"
232-
}],
232+
"unitTestRunners": [
233+
{
234+
"id": "jest",
235+
"displayName": "Jest"
236+
},
237+
{
238+
"id": "karma",
239+
"displayName": "Karma"
240+
}
241+
],
233242
"testFramework": {
234243
"id": "jasmine",
235244
"displayName": "Jasmine"
@@ -495,7 +504,7 @@
495504
{
496505
"id": 900,
497506
"type": "input-select",
498-
"nextActivity": 1000,
507+
"nextActivity": 950,
499508
"question": "What is your default code editor?",
500509
"stateProperty": "editor",
501510
"options": [
@@ -541,6 +550,47 @@
541550
}
542551
]
543552
},
553+
{
554+
"id": 950,
555+
"type": "input-multiselect",
556+
"nextActivity": 1000,
557+
"question": "Which features do you want scaffolded into your project?",
558+
"stateProperty": "features",
559+
"options": [
560+
{
561+
"displayName": "None",
562+
"description": "Just give me an empty project.",
563+
"value": {
564+
"id": "none",
565+
"displayName": "None"
566+
}
567+
},
568+
{
569+
"displayName": "Navigation",
570+
"description": "Add a router and some sample routes. (Also adds Bootstrap and Font Awesome.)",
571+
"value": {
572+
"id": "navigation",
573+
"displayName": "Navigation"
574+
}
575+
},
576+
{
577+
"displayName": "Bootstrap",
578+
"description": "Install and setup Bootstrap styles and features.",
579+
"value": {
580+
"id": "bootstrap",
581+
"displayName": "Bootstrap"
582+
}
583+
},
584+
{
585+
"displayName": "Font Awesome",
586+
"description": "Install and setup Font Awesome icons and styles.",
587+
"value": {
588+
"id": "fontAwesome",
589+
"displayName": "Font Awesome"
590+
}
591+
}
592+
]
593+
},
544594
{
545595
"type": "project-create",
546596
"id": 1000,

lib/commands/new/project-template.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ exports.ProjectTemplate = class {
7373
this.environments,
7474
this.aureliaJSON
7575
);
76+
77+
this.addedFeatures = {};
7678
}
7779

7880
get name() {
@@ -183,8 +185,10 @@ exports.ProjectTemplate = class {
183185

184186
configureDefaultSetup() {
185187
this.addToSource(
186-
ProjectItem.resource('app.ext', 'src/app.ext', this.model.transpiler),
187-
ProjectItem.resource('app.ext', 'src/app.ext', this.model.markupProcessor),
188+
ProjectItem.resource('app.ext', 'src/app.template.ext', this.model.transpiler)
189+
.asTemplate(this.model),
190+
ProjectItem.resource('app.ext', 'src/app.template.ext', this.model.markupProcessor)
191+
.asTemplate(this.model, { type: this.model.markupProcessor }),
188192
ProjectItem.resource('environment.ext', 'environments/dev.js', this.model.transpiler)
189193
).addToResources(
190194
ProjectItem.resource('index.ext', 'src/resources/index.ext', this.model.transpiler)
@@ -309,6 +313,31 @@ exports.ProjectTemplate = class {
309313
return this;
310314
}
311315

316+
addToAureliaDependencies() {
317+
this.model.build.bundles[1].dependencies.push(...arguments);
318+
return this;
319+
}
320+
321+
addToAureliaPrepend() {
322+
this.model.build.bundles[1].prepend.push(...arguments);
323+
return this;
324+
}
325+
326+
addToCopyFiles(files) {
327+
this.model.build.copyFiles = Object.assign({}, this.model.copyFiles, files);
328+
return this;
329+
}
330+
331+
addFeature(featureName, project, model, options) {
332+
if (this.addedFeatures[featureName]) {
333+
return ;
334+
}
335+
this.addedFeatures[featureName] = true;
336+
model.features[featureName] = featureName;
337+
let feature = require(`../../resources/features/${featureName}`);
338+
feature(project, model, options);
339+
}
340+
312341
renderManualInstructions() {
313342
let instructions = this.manualInstructions.getText();
314343
if (instructions) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Aurelia</title>
6+
<!-- @if features.navigation='navigation' -->
7+
<link rel="stylesheet" href="styles/styles.css">
8+
<!-- @endif -->
9+
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
</head>
11+
12+
<body aurelia-app="main">
13+
<!-- @if build.loader.type='require' -->
14+
<script src="scripts/vendor-bundle.js" data-main="aurelia-bootstrapper"></script>
15+
<!-- @endif -->
16+
<!-- @if build.loader.type='system' -->
17+
<script src="scripts/vendor-bundle.js"></script>
18+
<script>SystemJS.import("aurelia-bootstrapper").catch(function(err) { console.log(err); })</script>
19+
<!-- @endif -->
20+
</body>
21+
</html>

lib/resources/content/webpack.config.template.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ module.exports = ({ production, server, extractCss, coverage, analyze, karma } =
200200
...when(!karma, new DuplicatePackageCheckerPlugin()),
201201
new AureliaPlugin(),
202202
new ProvidePlugin({
203-
'Promise': 'bluebird'
204-
}),
203+
'Promise': 'bluebird',
204+
// @if features.jquery='jquery'
205+
$: 'jquery',
206+
jQuery: 'jquery',
207+
// @endif
208+
}),
205209
new ModuleDependenciesPlugin({
206210
'aurelia-testing': ['./compile-spy', './view-spy']
207211
}),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
const ProjectItem = require('../../project-item').ProjectItem;
3+
4+
module.exports = function (project, model, options) {
5+
project.addToDependencies(
6+
'whatwg-fetch@^2.0.3',
7+
'aurelia-fetch-client@^1.0.0'
8+
);
9+
if (model.bundler.id !== 'webpack') {
10+
project.addToAureliaDependencies(
11+
'aurelia-fetch-client',
12+
// 'whatwg-fetch'
13+
).addToAureliaPrepend(
14+
'node_modules/whatwg-fetch/fetch.js'
15+
);
16+
}
17+
};

0 commit comments

Comments
 (0)