+Aurelia +Paket +FAKE
Interim commit; there may still be leftover files from the Aurelia tutorial
This commit is contained in:
11
src/app/aurelia_project/tasks/build.json
Normal file
11
src/app/aurelia_project/tasks/build.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "build",
|
||||
"description": "Builds and processes all application assets.",
|
||||
"flags": [
|
||||
{
|
||||
"name": "env",
|
||||
"description": "Sets the build environment.",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
26
src/app/aurelia_project/tasks/build.ts
Normal file
26
src/app/aurelia_project/tasks/build.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as gulp from 'gulp';
|
||||
import transpile from './transpile';
|
||||
import processMarkup from './process-markup';
|
||||
import processCSS from './process-css';
|
||||
import copyFiles from './copy-files';
|
||||
import {build} from 'aurelia-cli';
|
||||
import * as project from '../aurelia.json';
|
||||
|
||||
export default gulp.series(
|
||||
readProjectConfiguration,
|
||||
gulp.parallel(
|
||||
transpile,
|
||||
processMarkup,
|
||||
processCSS,
|
||||
copyFiles
|
||||
),
|
||||
writeBundles
|
||||
);
|
||||
|
||||
function readProjectConfiguration() {
|
||||
return build.src(project);
|
||||
}
|
||||
|
||||
function writeBundles() {
|
||||
return build.dest();
|
||||
}
|
||||
45
src/app/aurelia_project/tasks/copy-files.ts
Normal file
45
src/app/aurelia_project/tasks/copy-files.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as gulp from 'gulp';
|
||||
import * as path from 'path';
|
||||
import * as minimatch from 'minimatch';
|
||||
import * as changedInPlace from 'gulp-changed-in-place';
|
||||
import * as project from '../aurelia.json';
|
||||
|
||||
export default function copyFiles(done) {
|
||||
if (typeof project.build.copyFiles !== 'object') {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const instruction = getNormalizedInstruction();
|
||||
const files = Object.keys(instruction);
|
||||
|
||||
return gulp.src(files)
|
||||
.pipe(changedInPlace({ firstPass: true }))
|
||||
.pipe(gulp.dest(x => {
|
||||
const filePath = prepareFilePath(x.path);
|
||||
const key = files.find(f => minimatch(filePath, f));
|
||||
return instruction[key];
|
||||
}));
|
||||
}
|
||||
|
||||
function getNormalizedInstruction() {
|
||||
const files = project.build.copyFiles;
|
||||
let normalizedInstruction = {};
|
||||
|
||||
for (let key in files) {
|
||||
normalizedInstruction[path.posix.normalize(key)] = files[key];
|
||||
}
|
||||
|
||||
return normalizedInstruction;
|
||||
}
|
||||
|
||||
function prepareFilePath(filePath) {
|
||||
let preparedPath = filePath.replace(process.cwd(), '').substring(1);
|
||||
|
||||
//if we are running on windows we have to fix the path
|
||||
if (/^win/.test(process.platform)) {
|
||||
preparedPath = preparedPath.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return preparedPath;
|
||||
}
|
||||
10
src/app/aurelia_project/tasks/process-css.ts
Normal file
10
src/app/aurelia_project/tasks/process-css.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as gulp from 'gulp';
|
||||
import * as changedInPlace from 'gulp-changed-in-place';
|
||||
import * as project from '../aurelia.json';
|
||||
import {build} from 'aurelia-cli';
|
||||
|
||||
export default function processCSS() {
|
||||
return gulp.src(project.cssProcessor.source)
|
||||
.pipe(changedInPlace({firstPass:true}))
|
||||
.pipe(build.bundle());
|
||||
};
|
||||
17
src/app/aurelia_project/tasks/process-markup.ts
Normal file
17
src/app/aurelia_project/tasks/process-markup.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as gulp from 'gulp';
|
||||
import * as htmlmin from 'gulp-htmlmin';
|
||||
import * as changedInPlace from 'gulp-changed-in-place';
|
||||
import * as project from '../aurelia.json';
|
||||
import {build} from 'aurelia-cli';
|
||||
|
||||
export default function processMarkup() {
|
||||
return gulp.src(project.markupProcessor.source)
|
||||
.pipe(changedInPlace({firstPass:true}))
|
||||
.pipe(htmlmin({
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
minifyCSS: true,
|
||||
minifyJS: true
|
||||
}))
|
||||
.pipe(build.bundle());
|
||||
}
|
||||
16
src/app/aurelia_project/tasks/run.json
Normal file
16
src/app/aurelia_project/tasks/run.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "run",
|
||||
"description": "Builds the application and serves up the assets via a local web server, watching files for changes as you work.",
|
||||
"flags": [
|
||||
{
|
||||
"name": "env",
|
||||
"description": "Sets the build environment.",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "watch",
|
||||
"description": "Watches source files for changes and refreshes the app automatically.",
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
73
src/app/aurelia_project/tasks/run.ts
Normal file
73
src/app/aurelia_project/tasks/run.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import * as gulp from 'gulp';
|
||||
import * as browserSync from 'browser-sync';
|
||||
import * as historyApiFallback from 'connect-history-api-fallback/lib';
|
||||
import * as project from '../aurelia.json';
|
||||
import build from './build';
|
||||
import {CLIOptions} from 'aurelia-cli';
|
||||
|
||||
function onChange(path) {
|
||||
console.log(`File Changed: ${path}`);
|
||||
}
|
||||
|
||||
function reload(done) {
|
||||
browserSync.reload();
|
||||
done();
|
||||
}
|
||||
|
||||
let serve = gulp.series(
|
||||
build,
|
||||
done => {
|
||||
browserSync({
|
||||
online: false,
|
||||
open: false,
|
||||
port: 9000,
|
||||
logLevel: 'silent',
|
||||
server: {
|
||||
baseDir: [project.platform.baseDir],
|
||||
middleware: [historyApiFallback(), function(req, res, next) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
next();
|
||||
}]
|
||||
}
|
||||
}, function (err, bs) {
|
||||
if (err) return done(err);
|
||||
let urls = bs.options.get('urls').toJS();
|
||||
console.log(`Application Available At: ${urls.local}`);
|
||||
console.log(`BrowserSync Available At: ${urls.ui}`);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
let refresh = gulp.series(
|
||||
build,
|
||||
reload
|
||||
);
|
||||
|
||||
let watch = function(refreshCb, onChangeCb) {
|
||||
return function(done) {
|
||||
gulp.watch(project.transpiler.source, refreshCb).on('change', onChangeCb);
|
||||
gulp.watch(project.markupProcessor.source, refreshCb).on('change', onChangeCb);
|
||||
gulp.watch(project.cssProcessor.source, refreshCb).on('change', onChangeCb);
|
||||
|
||||
//see if there are static files to be watched
|
||||
if (typeof project.build.copyFiles === 'object') {
|
||||
const files = Object.keys(project.build.copyFiles);
|
||||
gulp.watch(files, refreshCb).on('change', onChangeCb);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let run;
|
||||
|
||||
if (CLIOptions.hasFlag('watch')) {
|
||||
run = gulp.series(
|
||||
serve,
|
||||
watch(refresh, onChange)
|
||||
);
|
||||
} else {
|
||||
run = serve;
|
||||
}
|
||||
|
||||
export { run as default, watch };
|
||||
|
||||
16
src/app/aurelia_project/tasks/test.json
Normal file
16
src/app/aurelia_project/tasks/test.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "test",
|
||||
"description": "Runs all unit tests and reports the results.",
|
||||
"flags": [
|
||||
{
|
||||
"name": "env",
|
||||
"description": "Sets the build environment.",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "watch",
|
||||
"description": "Watches test files for changes and re-runs the tests automatically.",
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
40
src/app/aurelia_project/tasks/test.ts
Normal file
40
src/app/aurelia_project/tasks/test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as gulp from 'gulp';
|
||||
import {Server as Karma} from 'karma';
|
||||
import {CLIOptions} from 'aurelia-cli';
|
||||
import build from './build';
|
||||
import {watch} from './run';
|
||||
import * as path from 'path';
|
||||
|
||||
function log(message) {
|
||||
console.log(message); //eslint-disable-line no-console
|
||||
}
|
||||
|
||||
function onChange(path) {
|
||||
log(`File Changed: ${path}`);
|
||||
}
|
||||
|
||||
let karma = done => {
|
||||
new Karma({
|
||||
configFile: path.join(__dirname, '/../../karma.conf.js'),
|
||||
singleRun: !CLIOptions.hasFlag('watch')
|
||||
}, done).start();
|
||||
};
|
||||
|
||||
let unit;
|
||||
|
||||
if (CLIOptions.hasFlag('watch')) {
|
||||
unit = gulp.series(
|
||||
build,
|
||||
gulp.parallel(
|
||||
watch(build, onChange),
|
||||
karma
|
||||
)
|
||||
);
|
||||
} else {
|
||||
unit = gulp.series(
|
||||
build,
|
||||
karma
|
||||
);
|
||||
}
|
||||
|
||||
export default unit;
|
||||
44
src/app/aurelia_project/tasks/transpile.ts
Normal file
44
src/app/aurelia_project/tasks/transpile.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as gulp from 'gulp';
|
||||
import * as changedInPlace from 'gulp-changed-in-place';
|
||||
import * as plumber from 'gulp-plumber';
|
||||
import * as sourcemaps from 'gulp-sourcemaps';
|
||||
import * as notify from 'gulp-notify';
|
||||
import * as rename from 'gulp-rename';
|
||||
import * as ts from 'gulp-typescript';
|
||||
import * as project from '../aurelia.json';
|
||||
import {CLIOptions, build} from 'aurelia-cli';
|
||||
import * as eventStream from 'event-stream';
|
||||
|
||||
function configureEnvironment() {
|
||||
let env = CLIOptions.getEnvironment();
|
||||
|
||||
return gulp.src(`aurelia_project/environments/${env}.ts`)
|
||||
.pipe(changedInPlace({firstPass:true}))
|
||||
.pipe(rename('environment.ts'))
|
||||
.pipe(gulp.dest(project.paths.root));
|
||||
}
|
||||
|
||||
var typescriptCompiler = typescriptCompiler || null;
|
||||
|
||||
function buildTypeScript() {
|
||||
typescriptCompiler = ts.createProject('tsconfig.json', {
|
||||
"typescript": require('typescript')
|
||||
});
|
||||
|
||||
let dts = gulp.src(project.transpiler.dtsSource);
|
||||
|
||||
let src = gulp.src(project.transpiler.source)
|
||||
.pipe(changedInPlace({firstPass: true}));
|
||||
|
||||
return eventStream.merge(dts, src)
|
||||
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(typescriptCompiler())
|
||||
.pipe(sourcemaps.write({ sourceRoot: 'src' }))
|
||||
.pipe(build.bundle());
|
||||
}
|
||||
|
||||
export default gulp.series(
|
||||
configureEnvironment,
|
||||
buildTypeScript
|
||||
);
|
||||
Reference in New Issue
Block a user