Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
iliakan committed Jun 27, 2018
1 parent fcba3b9 commit 56b8bd8
Show file tree
Hide file tree
Showing 123 changed files with 636 additions and 727 deletions.
11 changes: 3 additions & 8 deletions bin/server.js
@@ -1,31 +1,26 @@
#!/usr/bin/env node

const config = require('config');
const co = require('co');
const app = require('app');
const log = require('log')();

co(function*() {

yield* app.waitBootAndListen(config.server.host, config.server.port);

app.waitBootAndListen(config.server.host, config.server.port).then(() => {
log.info("App is listening");

}).catch(function(err) {
log.error(err);
process.exit(1); // fatal error, could not boot!
});

// отслеживаем unhandled ошибки
// https://iojs.org/api/process.html#process_event_rejectionhandled
var unhandledRejections = [];
let unhandledRejections = [];
process.on('unhandledRejection', function(reason, p) {
p.trackRejectionId = Math.random();

setTimeout(function() { // 100 ms to catch up and handle rejection
if (p.trackRejectionId) { // if not rejectionHandled yet, report
unhandledRejections.push(p);
var report = {
let report = {
err: reason,
trackRejectionId: p.trackRejectionId,
length: unhandledRejections.length
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions cache/pack.versions.json
@@ -0,0 +1 @@
{"footer":"/pack/footer.js?edb029e47f90da7ef027","head":"/pack/head.js?edb029e47f90da7ef027","styles":["/pack/styles.js?edb029e47f90da7ef027","/pack/styles.css?2e4f8132ebec0fb8c5aca3229f00f5ef"],"tutorial":"/pack/tutorial.js?edb029e47f90da7ef027"}
2 changes: 1 addition & 1 deletion dev
Expand Up @@ -9,7 +9,7 @@ export NODE_ENV=development
export ASSET_VERSIONING=query
export WATCH=1
export SITE_HOST=http://javascript.local
export PORT=80
export PORT=3000

npm --silent run gulp dev | bunyan -o short -l debug

2 changes: 1 addition & 1 deletion edit
Expand Up @@ -7,7 +7,7 @@ BRANCH="${1:-$NODE_LANG}"
export NODE_LANG=$BRANCH
export NODE_ENV=production
export TUTORIAL_EDIT=1
export PORT=80
export PORT=3000

npm --silent run -- gulp edit --root /js/javascript-tutorial-$BRANCH

24 changes: 5 additions & 19 deletions gulpfile.js
Expand Up @@ -9,7 +9,6 @@ const path = require('path');
const fs = require('fs');
const assert = require('assert');
const runSequence = require('run-sequence');
const ll = require('gulp-ll');

const config = require('config');

Expand All @@ -25,9 +24,9 @@ const jsSources = [


function lazyRequireTask(path) {
var args = [].slice.call(arguments, 1);
let args = [].slice.call(arguments, 1);
return function(callback) {
var task = require(path).apply(this, args);
let task = require(path).apply(this, args);

return task(callback);
};
Expand Down Expand Up @@ -61,16 +60,14 @@ function requireModuleTasks(moduleName) {

}

ll.tasks('nodemon', 'client:webpack', 'server');

// usage: gulp db:load --from fixture/init --harmony
gulp.task('db:load', lazyRequireTask('./tasks/dbLoad'));
gulp.task('db:clear', lazyRequireTask('./tasks/dbClear'));

gulp.task("nodemon", lazyRequireTask('./tasks/nodemon', {
// shared client/server code has require('template.jade) which precompiles template on run
// so I have to restart server to pickup the template change
ext: "js,jade",
ext: "js,pug",

nodeArgs: process.env.NODE_DEBUG ? ['--debug'] : [],
script: "./bin/server.js",
Expand All @@ -95,7 +92,7 @@ gulp.task("client:livereload", lazyRequireTask("./tasks/livereload", {

requireModuleTasks('tutorial');

var testSrcs = ['{handlers,modules}/**/test/**/*.js'];
let testSrcs = ['{handlers,modules}/**/test/**/*.js'];
// on Travis, keys are required for E2E Selenium tests
// for PRs there are no keys, so we disable E2E
if (!process.env.TEST_E2E || process.env.CI && process.env.TRAVIS_SECURE_ENV_VARS=="false") {
Expand Down Expand Up @@ -129,17 +126,6 @@ gulp.task("client:sync-resources", lazyRequireTask('./tasks/syncResources', {
assets: 'public'
}));

// show errors if encountered
gulp.task('client:compile-css',
lazyRequireTask('./tasks/compileCss', {
src: './styles/base.styl',
dst: './public/styles',
publicDst: process.env.STATIC_HOST + '/styles/', // from browser point of view
manifest: path.join(config.manifestRoot, 'styles.versions.json'),
assetVersioning: config.assetVersioning
})
);


gulp.task('client:minify', lazyRequireTask('./tasks/minify'));
gulp.task('client:resize-retina-images', lazyRequireTask('./tasks/resizeRetinaImages'));
Expand All @@ -158,7 +144,7 @@ gulp.task('edit', ['tutorial:importWatch', "client:sync-resources", 'client:live


gulp.task('dev', function(callback) {
runSequence("client:sync-resources", ['nodemon', 'client:livereload', 'client:webpack', 'watch'], callback);
runSequence("tutorial:import", "client:sync-resources", ['nodemon', 'client:livereload', 'client:webpack', 'watch'], callback);
});

gulp.on('err', function(gulpErr) {
Expand Down
4 changes: 2 additions & 2 deletions handlers/404.js
@@ -1,9 +1,9 @@

exports.init = function(app) {
// by default if the router didn't find anything => it yields to next middleware
// by default if the router didn't find anything => it awaits to next middleware
// so I throw error here manually
app.use(function* (next) {
yield* next;
await next;

if (this.status == 404) {
// still nothing found? let default errorHandler show 404
Expand Down
2 changes: 1 addition & 1 deletion handlers/accessLogger.js
Expand Up @@ -19,7 +19,7 @@ exports.init = function(app) {
}, "--> %s %s", req.method, req.originalUrl || req.url);

try {
yield next;
await next;
} catch (err) {
// log uncaught downstream errors
log(this, start, err);
Expand Down
4 changes: 2 additions & 2 deletions handlers/bodyParser.js
Expand Up @@ -23,14 +23,14 @@ BodyParser.prototype.middleware = function() {
if (!self.ignore.check(this.path)) {
this.log.debug("bodyParser will parse");

yield* self.parser.call(this, next);
await self.parser.call(this, next);

this.log.debug("bodyParser done parse");
} else {
this.log.debug("bodyParser skip");
}

yield* next;
await next;
};
};

Expand Down
2 changes: 1 addition & 1 deletion handlers/conditional.js
Expand Up @@ -13,7 +13,7 @@ exports.init = function(app) {

// set expires to this.expires
app.use(function* (next) {
yield *next;
await *next;

if (!this.expires) return;

Expand Down
6 changes: 3 additions & 3 deletions handlers/csrfCheck.js
Expand Up @@ -12,7 +12,7 @@ CsrfChecker.prototype.middleware = function() {
return function*(next) {
// skip these methods
if (this.method === 'GET' || this.method === 'HEAD' || this.method === 'OPTIONS') {
return yield* next;
return await next;
}

var checkCsrf = true;
Expand All @@ -38,7 +38,7 @@ CsrfChecker.prototype.middleware = function() {
this.log.debug("csrf skip");
}

yield* next;
await next;
};
};

Expand All @@ -56,7 +56,7 @@ exports.init = function(app) {

try {
// first, do the middleware, maybe authorize user in the process
yield* next;
await next;
} finally {
// then if we have a user, set XSRF token
if (this.req.user) {
Expand Down
6 changes: 6 additions & 0 deletions handlers/dev/index.js
@@ -0,0 +1,6 @@
var mountHandlerMiddleware = require('lib/mountHandlerMiddleware');

exports.init = function(app) {
app.use( mountHandlerMiddleware('/dev', __dirname) );
};

19 changes: 19 additions & 0 deletions handlers/dev/router.js
@@ -0,0 +1,19 @@
var Router = require('koa-router');

var router = module.exports = new Router();

router.get('/', async function(ctx) {
ctx.body = ctx.render('index');

});

router.get('/die', async function(ctx) {
setTimeout(function() {
throw new Error("die");
}, 10);
});

router.get('/test', async function(ctx) {
ctx.body = Math.round(Date.now() / 1000 / 60);
});

19 changes: 19 additions & 0 deletions handlers/dev/tasks/convert.js
@@ -0,0 +1,19 @@
var co = require('co');
var fs = require('fs');
var path = require('path');
var log = require('log')();
var gutil = require('gulp-util');
var glob = require('glob');
let exec = require('mz/child_process').exec;
let ini = require('ini');

module.exports = function(options) {

return function() {

return async function() {
console.log("TEST");

}();
};
};
12 changes: 12 additions & 0 deletions handlers/dev/templates/index.pug
@@ -0,0 +1,12 @@

extends /layouts/main

block append variables
- var sitetoolbar = true
- var title = "Test page"


block content

+b.test
+e.hello HELLO

0 comments on commit 56b8bd8

Please sign in to comment.