Skip to content

Commit

Permalink
fix(webpack): new release check
Browse files Browse the repository at this point in the history
Additionally small refactor in package manager to easily export NPM
and Yarn. Added a new method `run` in base package manager.
  • Loading branch information
Sayan751 committed Jul 31, 2019
1 parent 76ffaef commit a217fec
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build/tasks/release-checks/suite-steps.js
Expand Up @@ -65,6 +65,8 @@ module.exports = function(suite) {


if (applicable(features, 'webpack')) { if (applicable(features, 'webpack')) {
steps.push( steps.push(
new tests.webpack.AuBuildDoesNotThrowCommandLineErrors(),
new tests.webpack.AuBuildStartsWebpackInWatchMode(),
new tests.webpack.AuRunDoesNotThrowCommandLineErrors(), new tests.webpack.AuRunDoesNotThrowCommandLineErrors(),
new tests.webpack.AuRunLaunchesServer(), new tests.webpack.AuRunLaunchesServer(),
new tests.webpack.AuRunRendersPage(), new tests.webpack.AuRunRendersPage(),
Expand Down
64 changes: 64 additions & 0 deletions build/tasks/release-checks/tests/webpack/au-build.js
@@ -0,0 +1,64 @@
const Test = require('../test');
const ExecuteCommand = require('../../tasks/execute-command');
const path = require('path');
const fs = require('fs');

class AuBuildDoesNotThrowCommandLineErrors extends Test {
constructor() {
super('au build does not throw commandline errors');
}

onOutput(message) {
this.debug(message);

if (message.toLowerCase().indexOf('error') > -1) {
this.executeCommand.stop();
this.fail();
} else if (isBuildCompletedMessage(message)) {
this.success();
this.executeCommand.stop();
}
}

execute() {
this.executeCommand = new ExecuteCommand('au', ['build'], (msg) => this.onOutput(msg));
return this.executeCommand.executeAsNodeScript();
}
}

class AuBuildStartsWebpackInWatchMode extends Test {
constructor(fileToChange) {
super('au build --watch starts webpack in watch mode');

this.fileToChange = fileToChange || path.join('src', 'app.html');
this.firstBuildCompleted = false;
}

onOutput(message) {
this.debug(message);

if (message.toLowerCase().indexOf('error') > -1) {
this.executeCommand.stop();
this.fail();
} else if (message.indexOf('webpack is watching the files') > -1) {
this.success();
this.executeCommand.stop();
}
}

execute(context) {
this.context = context;

this.executeCommand = new ExecuteCommand('au', ['build', '--watch'], (msg) => this.onOutput(msg));
return this.executeCommand.executeAsNodeScript();
}
}

function isBuildCompletedMessage(msg) {
return msg.indexOf('Built at') > -1;
}

module.exports = {
AuBuildDoesNotThrowCommandLineErrors,
AuBuildStartsWebpackInWatchMode
};
3 changes: 2 additions & 1 deletion build/tasks/release-checks/tests/webpack/index.js
@@ -1,3 +1,4 @@
module.exports = { module.exports = {
...require('./au-run') ...require('./au-run'),
...require('./au-build')
}; };
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -8,3 +8,5 @@ exports.ProjectItem = require('./project-item').ProjectItem;
exports.build = require('./build'); exports.build = require('./build');
exports.Configuration = require('./configuration').Configuration; exports.Configuration = require('./configuration').Configuration;
exports.reportWebpackReadiness = require('./build/webpack-reporter'); exports.reportWebpackReadiness = require('./build/webpack-reporter');
exports.NPM = require('./package-managers/npm').NPM;
exports.Yarn = require('./package-managers/yarn').Yarn;
6 changes: 5 additions & 1 deletion lib/package-managers/base-package-manager.js
Expand Up @@ -7,10 +7,14 @@ exports.BasePackageManager = class {
} }


install(packages = [], workingDirectory = process.cwd(), command = 'install') { install(packages = [], workingDirectory = process.cwd(), command = 'install') {
return this.run(command, packages, workingDirectory);
}

run(command, args = [], workingDirectory = process.cwd()) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
spawn( spawn(
this.getExecutablePath(workingDirectory), this.getExecutablePath(workingDirectory),
[command, ...packages], [command, ...args],
{ stdio: 'inherit', cwd: workingDirectory } { stdio: 'inherit', cwd: workingDirectory }
) )
.on('close', resolve) .on('close', resolve)
Expand Down
4 changes: 2 additions & 2 deletions skeleton/webpack/aurelia_project/tasks/build.ext
@@ -1,8 +1,8 @@
import { NPM } from 'aurelia-cli/lib/package-managers/npm'; import { NPM } from 'aurelia-cli';


export default function() { export default function() {
console.log('`au build` is an alias of the `npm run build`, you may use either of those; see README for more details.'); console.log('`au build` is an alias of the `npm run build`, you may use either of those; see README for more details.');


const args = process.argv.slice(3); const args = process.argv.slice(3);
return (new NPM()).install(['--', ...args], process.cwd(), 'run'); return (new NPM()).run('run', ['build', '--', ...args]);
} }
4 changes: 2 additions & 2 deletions skeleton/webpack/aurelia_project/tasks/run.ext
@@ -1,8 +1,8 @@
import { NPM } from 'aurelia-cli/lib/package-managers/npm'; import { NPM } from 'aurelia-cli';


export default function() { export default function() {
console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.'); console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.');


const args = process.argv.slice(3); const args = process.argv.slice(3);
return (new NPM()).install(['--', ...args], process.cwd(), 'start'); return (new NPM()).run('start',['--', ...args]);
} }

0 comments on commit a217fec

Please sign in to comment.