Skip to content

Commit f5b2367

Browse files
committed
feat: scaffolding aurelia plugin project
supersedes #793, closes #658
1 parent 71504b5 commit f5b2367

File tree

42 files changed

+925
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+925
-63
lines changed

lib/commands/new/command.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,13 @@ ${cmd('--install-deps yarn')}, or ${cmd('--install-deps npm')}, or shorter form
187187
message += `Then run your new app in dev mode with ${runCommand}.\n`;
188188
}
189189

190-
message += `If you want to build your app for production, run ${cmd('au build --env prod')}.\n`;
191-
message += `If you need help, simply run ${cmd('au help')}.\n`;
190+
if (applicable(features, 'plugin')) {
191+
message += `If you want to build the plugin, run ${cmd('au build-plugin')}.\n`;
192+
message += 'Please read README.md file for more instructions.\n';
193+
} else {
194+
message += `If you want to build your app for production, run ${cmd('au build --env prod')}.\n`;
195+
message += `If you need help, simply run ${cmd('au help')}.\n`;
196+
}
192197

193198
await this.logTitle('Congratulations!');
194199
await this.logBody(`Your Project "${projectName}" Has Been Created!`);

lib/commands/new/command.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"description": "Creates a new project with the current working directory as the root of the project instead of creating a new project folder.",
1515
"type": "boolean"
1616
},
17+
{
18+
"name": "plugin",
19+
"description": "Creates a new Aurelia plugin project.",
20+
"type": "boolean"
21+
},
1722
{
1823
"name": "unattended",
1924
"description": "Creates project in unattended mode. It will fail if there is any conflicting file in target folder.",

lib/workflow/applicable.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ module.exports = function(features, condition) {
2828
})
2929
.join(' ');
3030

31-
// Eval expression like "! true || false"
32-
// eslint-disable-next-line no-new-func
33-
return (new Function(`return ${expression};`))();
31+
try {
32+
// Eval expression like "! true || false"
33+
// eslint-disable-next-line no-new-func
34+
return (new Function(`return ${expression};`))();
35+
} catch (e) {
36+
throw new Error(`Condition:${condition} error:${e.message}`);
37+
}
3438
};

lib/workflow/questionnaire.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
// We use value 'none' as a convention for no feature selected,
33
// because enquirer doesn't support empty string '' as a value.
44

5+
exports.pickPlugin = {
6+
// add "plugin" to feature set for pluginFlow.
7+
// because this only provides one choice (default choice), it
8+
// is never prompted to end user.
9+
choices: [{value: 'plugin'}]
10+
};
11+
512
exports.askBundler = {
613
message: 'Which bundler would you like to use?',
714
choices: [{
815
value: 'webpack',
916
message: 'Webpack',
10-
hint: 'A powerful and popular bundler for JavaScript.'
17+
hint: 'A powerful and popular bundler for JavaScript.',
18+
if: '!plugin'
1119
}, {
1220
value: 'cli-bundler',
1321
message: "CLI's built-in bundler with an AMD module loader",
@@ -24,11 +32,13 @@ exports.askLoader = {
2432
}, {
2533
value: 'alameda',
2634
message: 'Alameda',
27-
hint: 'Alameda is a modern version of RequireJS using promises and native es6 features (modern browsers only).'
35+
hint: 'Alameda is a modern version of RequireJS using promises and native es6 features (modern browsers only).',
36+
if: '!plugin'
2837
}, {
2938
value: 'systemjs',
3039
message: 'SystemJS',
31-
hint: 'SystemJS is Dynamic ES module loader, the most versatile module loader for JavaScript.'
40+
hint: 'SystemJS is Dynamic ES module loader, the most versatile module loader for JavaScript.',
41+
if: '!plugin'
3242
}],
3343
// This if condition is not an enquirer feature.
3444
// This is our convention, check ./applicable.js for acceptable expressions
@@ -60,7 +70,8 @@ exports.askPlatform = {
6070
}, {
6171
value: 'dotnet-core',
6272
message: '.NET Core',
63-
hint: 'A powerful, patterns-based way to build dynamic websites with .NET Core.'
73+
hint: 'A powerful, patterns-based way to build dynamic websites with .NET Core.',
74+
if: '!plugin'
6475
}]
6576
};
6677

@@ -95,7 +106,7 @@ exports.askMarkupProcessor = {
95106
};
96107

97108
exports.askCssProcessor = {
98-
message: 'What css processor would you like to use?',
109+
message: 'What css preprocessor would you like to use?',
99110
choices: [{
100111
value: 'none',
101112
message: 'None',
@@ -206,7 +217,7 @@ exports.askPluginScaffold = {
206217
choices: [{
207218
value: 'plugin-scaffold-minimum',
208219
message: 'None',
209-
hint: 'Just a bare minimum Aurelia plugin.'
220+
hint: 'Just a bare minimum Aurelia plugin with one custom element.'
210221
}, {
211222
value: 'plugin-scaffold-basic',
212223
message: 'Basic',

lib/workflow/select-features.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const _ = require('lodash');
21
const runQuestionnaire = require('./run-questionnaire');
32
const {
3+
pickPlugin,
44
askBundler,
55
askLoader,
66
askHttp,
@@ -43,9 +43,6 @@ module.exports = async function(preselectedFeatures = [], opts = {}, _debug = []
4343
if (flow === 'app') {
4444
features = await appFlow(features, flowUnattended, _debug);
4545
} else if (flow === 'plugin') {
46-
// Plugin skeleton is only based on cli-bundler.
47-
// Don't allow user to overwrite cli-bundler with webpack
48-
_.pull(features, 'webpack');
4946
features = await pluginFlow(features, flowUnattended, _debug);
5047
} else {
5148
throw new Error(`Workflow "${flow}" is not recognizable.`);
@@ -62,9 +59,9 @@ const PRESETS = {
6259
'default-esnext': {flow: 'app', recommendedFeatures: ['jest', 'vscode'], unattended: true},
6360
'default-typescript': {flow: 'app', recommendedFeatures: ['jest', 'typescript', 'vscode'], unattended: true},
6461
'custom-app': {flow: 'app'},
65-
'default-plugin-esnext': {flow: 'plugin', recommendedFeatures: ['cli-bundler', 'requirejs', 'jest', 'vscode'], unattended: true},
66-
'default-plugin-typescript': {flow: 'plugin', recommendedFeatures: ['cli-bundler', 'requirejs', 'jest', 'typescript', 'vscode'], unattended: true},
67-
'custom-plugin': {flow: 'plugin', recommendedFeatures: ['cli-bundler', 'requirejs']}
62+
'default-plugin-esnext': {flow: 'plugin', recommendedFeatures: ['jest', 'vscode'], unattended: true},
63+
'default-plugin-typescript': {flow: 'plugin', recommendedFeatures: ['jest', 'typescript', 'vscode'], unattended: true},
64+
'custom-plugin': {flow: 'plugin'}
6865
};
6966

7067
async function selectWorkFlow(opts, _debug) {
@@ -76,36 +73,35 @@ async function selectWorkFlow(opts, _debug) {
7673
} else {
7774
const ans = await runQuestionnaire([], [{
7875
message: 'Would you like to use the default setup or customize your choices?',
79-
choices: [{
80-
value: 'default-esnext',
81-
message: 'Default ESNext App',
82-
hint: 'A basic app with Babel and Webpack.'
83-
}, {
84-
value: 'default-typescript',
85-
message: 'Default TypeScript App',
86-
hint: 'A basic app with TypeScript and Webpack.'
87-
}, {
88-
value: 'custom-app',
89-
message: 'Custom App',
90-
hint: 'Select bundler, loader, transpiler, CSS pre-processor and more.'
91-
}
92-
/* TODO enable plugin flow after providing the plugin skeleton
93-
{
94-
role: 'separator'
95-
}, {
96-
value: 'default-plugin-esnext',
97-
message: 'Default ESNext Aurelia Plugin',
98-
hint: 'A basic Aurelia plugin with Babel'
99-
}, {
100-
value: 'default-plugin-typescript',
101-
message: 'Default TypeScript Aurelia Plugin',
102-
hint: 'A basic Aurelia plugin with TypeScript'
103-
}, {
104-
value: 'custom-plugin',
105-
message: 'Custom Aurelia Plugin',
106-
hint: 'Select transpiler, CSS pre-processor and more.'
107-
} */
108-
]
76+
choices: opts.plugin ?
77+
// plugin flows
78+
[{
79+
value: 'default-plugin-esnext',
80+
message: 'Default ESNext Aurelia Plugin',
81+
hint: 'A basic Aurelia plugin with Babel'
82+
}, {
83+
value: 'default-plugin-typescript',
84+
message: 'Default TypeScript Aurelia Plugin',
85+
hint: 'A basic Aurelia plugin with TypeScript'
86+
}, {
87+
value: 'custom-plugin',
88+
message: 'Custom Aurelia Plugin',
89+
hint: 'Select transpiler, CSS pre-processor and more.'
90+
}] :
91+
// app flows
92+
[{
93+
value: 'default-esnext',
94+
message: 'Default ESNext App',
95+
hint: 'A basic app with Babel and Webpack.'
96+
}, {
97+
value: 'default-typescript',
98+
message: 'Default TypeScript App',
99+
hint: 'A basic app with TypeScript and Webpack.'
100+
}, {
101+
value: 'custom-app',
102+
message: 'Custom App',
103+
hint: 'Select bundler, loader, transpiler, CSS pre-processor and more.'
104+
}]
109105
}], false, _debug);
110106

111107
workflow = ans[0];
@@ -133,6 +129,10 @@ async function appFlow(features, unattended, _debug) {
133129

134130
async function pluginFlow(features, unattended, _debug) {
135131
return await runQuestionnaire(features, [
132+
pickPlugin,
133+
askBundler,
134+
askLoader,
135+
askPlatform,
136136
askTranspiler,
137137
askMarkupProcessor,
138138
askCssProcessor,

skeleton/cli-bundler/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To change dev server port, do `au run --port 8888`.
1212
To install new npm packages automatically, do `au run --auto-install`
1313
// @endif
1414

15+
// @if !feat.plugin
1516
## Build for production
1617

1718
Run `au build --env prod`.
19+
// @endif

skeleton/cli-bundler/aurelia_project/aurelia.json

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,77 @@
66
["@babel/plugin-transform-modules-amd", {"loose": true}]
77
]
88
},
9-
"source": "src/**/*.js",
9+
10+
"source": [
11+
// @if feat.plugin
12+
"dev-app/**/*.js",
13+
// @endif
14+
"src/**/*.js"
15+
],
1016
// @endif
1117

1218
// @if feat.typescript
1319
"dtsSource": ["./types/**/*.d.ts"],
14-
"source": "src/**/*.ts",
20+
"source": [
21+
// @if feat.plugin
22+
"dev-app/**/*.ts",
23+
// @endif
24+
"src/**/*.ts"
25+
],
1526
// @endif
1627
},
1728
"markupProcessor": {
18-
"source": "src/**/*.html"
29+
"source": [
30+
// @if feat.plugin
31+
"dev-app/**/*.html",
32+
// @endif
33+
"src/**/*.html"
34+
],
1935
},
2036
"cssProcessor": {
2137
// @if ! (feat.less || feat.sass || feat.stylus)
22-
"source": "src/**/*.css"
38+
"source": [
39+
// @if feat.plugin
40+
"dev-app/**/*.css",
41+
// @endif
42+
"src/**/*.css"
43+
],
2344
// @endif
2445

2546
// @if feat.less
26-
"source": "src/**/*.less"
47+
"source": [
48+
// @if feat.plugin
49+
"dev-app/**/*.less",
50+
// @endif
51+
"src/**/*.less"
52+
],
2753
// @endif
2854

2955
// @if feat.sass
30-
"source": "src/**/*.scss"
56+
"source": [
57+
// @if feat.plugin
58+
"dev-app/**/*.scss",
59+
// @endif
60+
"src/**/*.scss"
61+
],
3162
// @endif
3263

3364
// @if feat.stylus
34-
"source": "src/**/*.styl"
65+
"source": [
66+
// @if feat.plugin
67+
"dev-app/**/*.styl",
68+
// @endif
69+
"src/**/*.styl"
70+
],
3571
// @endif
3672
},
3773
"jsonProcessor": {
38-
"source": "src/**/*.json"
74+
"source": [
75+
// @if feat.plugin
76+
"dev-app/**/*.json",
77+
// @endif
78+
"src/**/*.json"
79+
],
3980
},
4081
// @if feat.karma
4182
"unitTestRunner": {

skeleton/cli-bundler/aurelia_project/tasks/process-css.ext

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,36 @@ export default function processCSS() {
7878
// @endif
7979
.pipe(build.bundle());
8080
}
81+
82+
// @if feat.plugin
83+
export function pluginCSS(dest) {
84+
return function processPluginCSS() {
85+
return gulp.src(project.plugin.source.css)
86+
// @if feat.less || feat.stylus
87+
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
88+
// @endif
89+
// @if feat.less
90+
.pipe(less())
91+
// @endif
92+
// @if feat.sass
93+
.pipe(sass().on('error', sass.logError))
94+
// @endif
95+
// @if feat.stylus
96+
.pipe(stylus())
97+
// @endif
98+
// @if feat['postcss-basic']
99+
.pipe(postcss([
100+
autoprefixer({browsers: ['last 2 version']})
101+
]))
102+
// @endif
103+
// @if feat['postcss-typical']
104+
.pipe(postcss([
105+
autoprefixer({browsers: ['last 2 version']}),
106+
postcssUrl({url: 'inline', encodeType: 'base64'}),
107+
cssnano()
108+
]))
109+
// @endif
110+
.pipe(gulp.dest(dest));
111+
};
112+
}
113+
// @endif

skeleton/cli-bundler/aurelia_project/tasks/process-json.ext

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ export default function processJson() {
1212
return gulp.src(project.jsonProcessor.source, {since: gulp.lastRun(processJson)})
1313
.pipe(build.bundle());
1414
}
15+
16+
// @if feat.plugin
17+
export function pluginJson(dest) {
18+
return function processPluginJson() {
19+
return gulp.src(project.plugin.source.json)
20+
.pipe(gulp.dest(dest));
21+
};
22+
}
23+
// @endif

skeleton/cli-bundler/aurelia_project/tasks/process-markup.ext

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,28 @@ export default function processMarkup() {
3939
// @endif
4040
.pipe(build.bundle());
4141
}
42+
43+
// @if feat.plugin
44+
export function pluginMarkup(dest) {
45+
return function processPluginMarkup() {
46+
return gulp.src(project.plugin.source.html)
47+
// @if feat['htmlmin-min'] || feat['htmlmin-max']
48+
.pipe(htmlmin({
49+
// @if feat['htmlmin-max']
50+
collapseInlineTagWhitespace: true,
51+
collapseBooleanAttributes: true,
52+
removeAttributeQuotes: true,
53+
removeScriptTypeAttributes: true,
54+
removeStyleLinkTypeAttributes: true,
55+
// @endif
56+
removeComments: true,
57+
collapseWhitespace: true,
58+
minifyCSS: true,
59+
minifyJS: true,
60+
ignoreCustomFragments: [/\${.*?}/g] // ignore interpolation expressions
61+
}))
62+
// @endif
63+
.pipe(gulp.dest(dest));
64+
};
65+
}
66+
// @endif

0 commit comments

Comments
 (0)