Skip to content

Commit

Permalink
feat(all): add webpack
Browse files Browse the repository at this point in the history
closes #184
closes #260

chore(webpack): clean up tasks, update command json

chore(webpack): cleanup

chore(new): ask for loader/bundler in custo

chore(webpack): add asp.net core support

chore(webpack): replace existing csproj if present

fix(project-item): ask for file replacement in sequence

in "au new" the CLI asks the user to replace existing file. When there are multiple files that already exist, the CLI only asks the user whether to replace the file for one of those files. This is due to the fact that the .create() method of child project-item's are called in parallel, not in sequence.

chore(webpack): improve instructions for aspnet core

chore(all): fixed minor scaffolding issues

chore(webpack): more user information

chore(webpack): add tasks for karma & jest
  • Loading branch information
JeroenVinke committed Jul 14, 2017
1 parent 1507919 commit 2c08625
Show file tree
Hide file tree
Showing 90 changed files with 1,967 additions and 477 deletions.
142 changes: 142 additions & 0 deletions build/tasks/generate-projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
require('aurelia-polyfills');
const gulp = require('gulp');
const Container = require('aurelia-dependency-injection').Container;
const definition = require('../../lib/commands/new/new-application.json');
const WorkflowEngine = require('../../lib/workflow/workflow-engine').WorkflowEngine;
const ProjectCreate = require('../../lib/workflow/activities/project-create');
const UI = require('../../lib/ui').UI;
const ConsoleUI = require('../../lib/ui').ConsoleUI;
const fs = require('fs');
const LogManager = require('aurelia-logging');
const Logger = require('../../lib/logger').Logger;

gulp.task('generate-projects', function(done) {
LogManager.addAppender(new Logger(new ConsoleUI()));
LogManager.setLevel('debug');

const ui = new ConsoleUI();

ui.question('Where would you like to create the projects?')
.then(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
process.chdir(dir);

return createProjectsInSeries(require('./skeletons.json'))
.then(() => {
console.log('Created all projects');
done();
})
.catch(e => {
console.log(e);
done();
});
});
});

function createProjectsInSeries(instructions) {
let i = -1;
function createP() {
i++;

if (i < instructions.length) {
return createProject(instructions[i]).then(createP);
}

return Promise.resolve();
}

return createP();
}

function createProject(answers) {
let container = new Container();
let engine = new WorkflowEngine(
definition,
container
);

container.registerInstance(UI, new ConsoleUI());
container.unregister('project-install');
container.registerInstance('project-install', new AutoProjectInstall());
container.unregister('project-create');
container.registerSingleton('project-create', AutoProjectCreate);
container.unregister('input-text');
container.registerInstance('input-text', new AutoInputText(answers));
container.unregister('input-select');
container.registerInstance('input-select', new AutoInputSelect(answers));
container.unregister('input-multiselect');
container.registerInstance('input-multiselect', new AutoInputMultiSelect(answers));

return engine.start()
.then(() => console.log('Finished creating project'))
.catch(e => {
console.log('error while creating project');
console.log(e);
throw e;
});
}

class AutoInputSelect {
constructor(answers) {
this._answers = answers;
}

execute(context) {
let answer = this._answers[this.id];

if (!answer) {
answer = this.options[0].value;
}

context.state[this.stateProperty] = answer;
context.next(this.nextActivity);
}
}

class AutoInputMultiSelect {
constructor(answers) {
this._answers = answers;
}

execute(context) {
let answer = this._answers[this.id];

if (!answer) {
answer = [this.options[0].value];
}

context.state[this.stateProperty] = answer;
context.next(this.nextActivity);
}
}

class AutoInputText {
constructor(answers) {
this._answers = answers;
}

execute(context) {
let answer = this._answers[this.id];

if (!answer) {
throw new Error('AutoInputText has no answer for activityId ' + this.id);
}

context.state[this.stateProperty] = answer;
context.next(this.nextActivity);
}
}

class AutoProjectCreate extends ProjectCreate {
projectConfirmation() {
return Promise.resolve({ value: 'yes' });
}
}

class AutoProjectInstall {
execute(context) {
context.next(this.nextActivity);
}
}
47 changes: 47 additions & 0 deletions build/tasks/skeletons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[{
"200": "skeleton-requirejs-esnext",
"300": "default-esnext"
}, {
"200": "skeleton-requirejs-typescript",
"300": "default-typescript"
},{
"200": "skeleton-systemjs-esnext",
"300": "custom",
"600": "systemjs"
}, {
"200": "skeleton-systemjs-typescript",
"300": "custom",
"600": "systemjs",
"630": {
"id": "typescript",
"displayName": "TypeScript",
"fileExtension": ".ts"
}
}, {
"200": "skeleton-webpack-esnext",
"300": "custom",
"600": "webpack",
"680": [{
"id": "karma",
"displayName": "Karma"
}, {
"id": "jest",
"displayName": "Jest"
}]
}, {
"200": "skeleton-webpack-typescript",
"300": "custom",
"600": "webpack",
"630": {
"id": "typescript",
"displayName": "TypeScript",
"fileExtension": ".ts"
},
"680": [{
"id": "karma",
"displayName": "Karma"
}, {
"id": "jest",
"displayName": "Jest"
}]
}]
54 changes: 54 additions & 0 deletions lib/build/webpack-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

module.exports = function reportReadiness(options) {
const uri = createDomain(options);
const yargs = require('yargs');
const argv = yargs.argv;
argv.color = require('supports-color');
const open = require('opn');
const useColor = argv.color;

let startSentence = `Project is running at ${colorInfo(useColor, uri)}`;

if (options.socket) {
startSentence = `Listening to socket at ${colorInfo(useColor, options.socket)}`;
}
console.log((argv.progress ? '\n' : '') + startSentence);

console.log(`webpack output is served from ${colorInfo(useColor, options.publicPath)}`);
const contentBase = Array.isArray(options.contentBase) ? options.contentBase.join(', ') : options.contentBase;

if (contentBase) {
console.log(`Content not from webpack is served from ${colorInfo(useColor, contentBase)}`);
}

if (options.historyApiFallback) {
console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || '/index.html')}`);
}

if (options.open) {
open(uri).catch(function() {
console.log('Unable to open browser. If you are running in a headless environment, please do not use the open flag.');
});
}
};

function createDomain(opts) {
const protocol = opts.https ? 'https' : 'http';
const url = require('url');

// the formatted domain (url without path) of the webpack server
return opts.public ? `${protocol}://${opts.public}` : url.format({
protocol: protocol,
hostname: opts.host,
port: opts.socket ? 0 : opts.port.toString()
});
}

function colorInfo(useColor, msg) {
if (useColor) {
// Make text blue and bold, so it *pops*
return `\u001b[1m\u001b[33m${msg}\u001b[39m\u001b[22m`;
}
return msg;
}
10 changes: 8 additions & 2 deletions lib/commands/help/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ module.exports = class {
getLocalCommandText() {
let commands = [
require('../generate/command.json'),
require('../import/command.json'),
require('../install/command.json'),
require('./command.json')
];

let bundler = this.project.model.bundler;
if (!bundler || bundler.id === 'cli') {
commands = commands.concat([
require('../import/command.json'),
require('../install/command.json')
]);
}

return this.project.getTaskMetadata().then(metadata => {
return string.buildFromMetadata(metadata.concat(commands), this.ui.getWidth());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
project.addToTasks(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
project.addToTasks(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
project.addToTasks(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
project.addToTasks(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
project.addToTasks(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
if (project.model.transpiler.id !== 'typescript') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const ProjectItem = require('../../../project-item').ProjectItem;
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
if (project.model.transpiler.id !== 'typescript') {
Expand Down
File renamed without changes.
Loading

0 comments on commit 2c08625

Please sign in to comment.