Large reorganization; switched from Browserify to Webpack, cleaner gulpfile, preparations for Polymer stack, moved old code aside, etc.

feature/core
Sven Slootweg 10 years ago
parent a00294188d
commit 500afa8b18

2
.gitignore vendored

@ -4,3 +4,5 @@ sasswatch.log
sasswatch.err
sasswatch.pid
node_modules
src/scss/*.css
src/scss/*.css.map

@ -6,7 +6,6 @@ cookieParser = require('cookie-parser');
bodyParser = require('body-parser');
routes = require('./routes/index');
users = require('./routes/users');
app = express();
@ -21,7 +20,6 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use (req, res, next) ->
err = new Error("Not Found")

@ -1,66 +0,0 @@
var app, bodyParser, cookieParser, express, favicon, logger, path, routes, users;
express = require('express');
path = require('path');
favicon = require('static-favicon');
logger = require('morgan');
cookieParser = require('cookie-parser');
bodyParser = require('body-parser');
routes = require('./routes/index');
users = require('./routes/users');
app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express["static"](path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use(function(req, res, next) {
var err;
err = new Error("Not Found");
err.status = 404;
return next(err);
});
if (app.get("env") === "development") {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
return res.render("error", {
message: err.message,
error: err
});
});
}
app.use(function(err, req, res, next) {
res.status(err.status || 500);
return res.render("error", {
message: err.message,
error: {}
});
});
module.exports = app;

@ -1,9 +0,0 @@
#!/usr/bin/env node
var debug = require('debug')('openNG');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});

@ -0,0 +1,8 @@
#!/usr/bin/env coffee
debug = require('debug')('openNG')
app = require('../app')
app.set('port', process.env.PORT ? 3000)
server = app.listen app.get('port'), ->
debug('Express server listening on port ' + server.address().port)

@ -1 +0,0 @@
module.exports = "hi";

@ -6,6 +6,7 @@ var gutil = require('gulp-util');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var coffee = require('gulp-coffee');
var sass = require("gulp-sass");
var cache = require('gulp-cached');
var remember = require('gulp-remember');
var plumber = require('gulp-plumber');
@ -13,66 +14,111 @@ var livereload = require('gulp-livereload');
var nodemon = require("gulp-nodemon");
var jade = require("gulp-jade");
var net = require("net");
var spy = require("through2-spy");
var webpack = require("gulp-webpack");
/* For Browserify task; see https://github.com/greypants/gulp-starter/blob/master/gulp/tasks/browserify.js */
var browserify = require('browserify');
var watchify = require('watchify');
var bundleLogger = require('./gulp.bundleLogger');
var handleErrors = require('./gulp.handleErrors');
var source = require('vinyl-source-stream');
task = {
"source": ["templateUtil.coffee", "routes/**/*.coffee", "models/**/*.coffee", "app.coffee", "util.coffee", "db.coffee"],
"frontend": ["./public/js/script.coffee"],
"jade": ["views/angular/**/*.jade"]
}
function namedLog(name) {
return function gutilLog(log) {
gc = gutil.colors;
gulp.task('coffee', function() {
return gulp.src(task.source, {base: "."})
.pipe(plumber())
.pipe(cache("coffee"))
.pipe(coffee({bare: true}).on('error', gutil.log)).on('data', gutil.log)
.pipe(remember("coffee"))
.pipe(gulp.dest("."));
});
items = ["[- " + gc.magenta(name) + " -]"];
gulp.task('browserify', function() {
var bundler = browserify({
cache: {}, packageCache: {}, fullPaths: true,
entries: task.frontend,
extensions: ['.coffee'],
debug: true
});
var bundle = function() {
bundleLogger.start();
console.log("Bundling...");
return bundler
.bundle()
.on('error', handleErrors)
.pipe(source('bundled.js'))
.pipe(gulp.dest('./public/js/'))
.on('end', bundleLogger.end);
};
if(global.isWatching) {
console.log("Starting Browserify watcher...");
bundler = watchify(bundler);
bundler.on('update', bundle);
for(i in arguments) {
items.push(arguments[i]);
}
gutil.log.apply(null, items);
}
}
return bundle();
});
tasks = {
coffee: [
{
name: "util",
source: ["templateUtil.coffee"],
base: ".",
destination: "."
}, {
name: "elements",
source: ["./src/elements/**/*.coffee"],
base: "./src/elements",
destination: "./public/elements"
}
],
jade: [
{
name: "views",
source: ["./views/client/**/*.jade"],
base: "./views/client",
destination: "./public/views"
}, {
name: "elements",
source: ["./src/elements/**/*.jade"],
base: "./src/elements",
destination: "./public/elements"
}
],
sass: [
{
name: "elements",
source: ["./src/elements/**/*.scss"],
base: "./src/elements",
destination: "./public/elements"
}
]
}
function concatName(type, name) {
return type + "-" + name;
}
for (var type in tasks) {
var subTasks = tasks[type];
for (var i in subTasks) {
var subTask = subTasks[i];
(function(type, subTask) {
var taskName = concatName(type, subTask.name);
gulp.task(taskName, function() {
var processor;
switch(type) {
case "coffee":
processor = coffee({bare: true});
break;
case "jade":
processor = jade({locals: require("./templateUtil")});
break;
case "sass":
processor = sass();
break;
}
gulp.task("jade", function() {
return gulp.src(task.jade, {base: "./views/angular"})
.pipe(plumber())
.pipe(cache("jade"))
.pipe(jade({locals: require("./templateUtil")}))
.pipe(remember("jade"))
.pipe(gulp.dest("public/templates"))
return gulp.src(subTask.source, {base: subTask.base})
.pipe(plumber())
.pipe(cache(taskName))
.pipe(processor.on('error', gutil.log))
.pipe(spy.obj(namedLog(taskName)))
.pipe(remember(taskName))
.pipe(gulp.dest(subTask.destination));
});
})(type, subTask);
}
}
gulp.task('webpack', function(){
return gulp.src("./src/coffee/index.coffee")
.pipe(webpack({
watch: true,
module: {
loaders: [{ test: /\.coffee$/, loader: "coffee-loader" }]
},
resolve: { extensions: ["", ".web.coffee", ".web.js", ".coffee", ".js"] }
}))
.pipe(rename("bundle.js"))
.pipe(gulp.dest("./public/js"));
});
function checkServerUp(){
@ -90,16 +136,34 @@ function checkServerUp(){
}, 70);
}
var startupTasks = [];
var watchTasks = [];
for (var type in tasks) {
var subTasks = tasks[type];
for (var i in subTasks) {
var subTask = subTasks[i];
var taskName = concatName(type, subTask.name);
startupTasks.push(taskName);
watchTasks.push([subTask, taskName]);
}
}
gulp.task('watch', function () {
global.isWatching = true;
livereload.listen();
gulp.watch(task.jade, ['jade'])
gulp.watch(['./**/*.css', 'views/**/*.jade', '!views/angular/**/*.jade', 'package.json']).on('change', livereload.changed);
gulp.watch(['public/templates/**/*.html']).on('change', function() { livereload.changed("*"); }); // We need to explicitly reload everything here; Angular doesn't do partial reloading
gulp.watch(task.source, ['coffee']);
// theseus disabled for now, it was screwing with my tracebacks
//nodemon({script: "./bin/www", ext: "js", nodeArgs: ['/usr/bin/node-theseus']}).on("start", checkServerUp);
nodemon({script: "./bin/www", ext: "js", delay: 500}).on("start", checkServerUp);
gulp.watch(['./**/*.css', 'views/**/*.jade', '!views/client/**/*.jade', 'package.json']).on('change', livereload.changed);
gulp.watch(['public/views/**/*.html']).on('change', function() { livereload.changed("*"); }); // We need to explicitly reload everything here; Polymer doesn't do partial reloading
for (i in watchTasks) {
task = watchTasks[i];
gulp.watch(task[0].source, [task[1]]);
}
nodemon({script: "./bin/www.coffee", ext: "coffee", delay: 500}).on("start", checkServerUp);
});
gulp.task('default', ['coffee', 'jade', 'watch', 'browserify']);
startupTasks.push("webpack", "watch");
gulp.task('default', startupTasks);

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Attribute", {
tableName: "attributes",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("AttributeSource", {
tableName: "attribute_sources",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("AttributeType", {
tableName: "attribute_types",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Bin", {
tableName: "bins",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("BinAuthorization", {
tableName: "bin_authorizations",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("BinItem", {
tableName: "bin_items",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("BinProjectAssociation", {
tableName: "bin_project_associations",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Clearance", {
tableName: "clearances",
idAttribute: "id"
});
};

@ -1,16 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Node", {
tableName: "nodes",
idAttribute: "id",
relationIdAttribute: "perma_id",
type: function() {
return this.belongsTo("NodeType", "type_id");
},
tags: function() {
return this.belongsToMany("NodeTag").through("NodeTagAssociation");
},
attributes: function() {
return this.hasMany("Attribute", "node_id");
}
});
};

@ -1,11 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("NodeTag", {
tableName: "node_tags",
idAttribute: "id",
nodes: function() {
var wrappedModel;
wrappedModel = Object.create(bookshelf.model("NodeTag"));
return wrappedModel.idAttribute = this.belongsToMany("NodeTag").through("NodeTagAssociation");
}
});
};

@ -1,8 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("NodeTagAssociation", {
tableName: "node_tag_associations",
idAttribute: "id",
node: this.belongsTo("Node", "node_id"),
tag: this.belongsTo("NodeTag", "tag_id")
});
};

@ -1,7 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("NodeType", {
tableName: "node_types",
idAttribute: "id",
nodes: this.hasMany("Node", "type_id")
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Project", {
tableName: "projects",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("ProjectAuthorization", {
tableName: "project_autorizations",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Reference", {
tableName: "references",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("Relationship", {
tableName: "relationships",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("RelationshipReference", {
tableName: "relationship_references",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("RelationshipSource", {
tableName: "relationship_sources",
idAttribute: "id"
});
};

@ -1,6 +0,0 @@
module.exports = function(bookshelf) {
return bookshelf.model("RelationshipType", {
tableName: "relationship_types",
idAttribute: "id"
});
};

Before

Width:  |  Height:  |  Size: 399 KiB

After

Width:  |  Height:  |  Size: 399 KiB

@ -13,6 +13,7 @@
"debug": "~0.7.4",
"express": "~4.2.0",
"express-promise-router": "0.0.6",
"gulp-remember": "^0.3.0",
"jade": "~1.3.0",
"jquery": "^2.1.1",
"lodash": "^2.4.1",
@ -20,9 +21,8 @@
"static-favicon": "~1.0.0"
},
"devDependencies": {
"browserify": "^5.11.2",
"browserify-shim": "^3.7.0",
"coffeeify": "^0.7.0",
"coffee-loader": "^0.7.2",
"coffee-script": "^1.9.1",
"gulp": "~3.8.0",
"gulp-cached": "~0.0.3",
"gulp-coffee": "~2.0.1",
@ -32,30 +32,12 @@
"gulp-nodemon": "~1.0.4",
"gulp-notify": "^1.6.0",
"gulp-plumber": "~0.6.3",
"gulp-remember": "~0.2.0",
"gulp-remember": "~0.3.0",
"gulp-rename": "~1.2.0",
"gulp-sass": "^1.3.3",
"gulp-util": "~2.2.17",
"gulp-webpack": "^1.2.0",
"pretty-hrtime": "^0.2.1",
"vinyl-source-stream": "^1.0.0",
"watchify": "^1.0.2"
},
"browser": {
"angular": "./shimmable/angular.js",
"jquery": "./node_modules/jquery/dist/jquery.js"
},
"browserify": {
"transform": [
"browserify-shim",
"coffeeify"
]
},
"browserify-shim": {
"angular": {
"depends": "jquery",
"exports": "angular"
},
"jquery": {
"exports": "jQuery"
}
"through2-spy": "^1.2.0"
}
}

@ -0,0 +1 @@
<div>Hi! Gah!</div>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,7 +0,0 @@
{
"version": 3,
"file": "",
"sources": ["style.scss"],
"names": [],
"mappings": ""
}

@ -1 +0,0 @@
<form method="post" action="/nodes/create" class="pure-form"><div class="toolbarWindow hasBottom"><div class="toolbarWindowContents"><div class="formSection"><h1 class="formSectionTitle">Node</h1><div class="formField"><label>Name<i class="fa fa-exclamation-circle required"></i></label><input name="name" type="text"/></div><div class="formField"><label>Notes</label><textarea name="notes"></textarea></div></div><div class="formSection"><h1 class="formSectionTitle">Properties</h1><div auto-duplicate="auto-duplicate" class="formField"><input name="propertyName[]" placeholder="Name"/><input name="propertyValue[]" placeholder="Value"/></div></div></div><div class="toolbarWindowControls bottom"><button type="submit"><i class="fa fa-check"></i>Create</button></div></div></form>

@ -1 +0,0 @@
<form method="post" action="/nodes/create" class="pure-form"><div class="toolbarWindow hasBottom"><div class="toolbarWindowContents"><div class="formSection"><h1 class="formSectionTitle">Node</h1><div class="formField"><div class="labelWrapper"><label>Name<i class="fa fa-exclamation-circle required"></i></label></div><div class="inputWrapper"><input name="name" type="text"/></div></div><div class="formField"><div class="labelWrapper"><label>Notes</label></div><div class="inputWrapper"><textarea name="notes"></textarea></div></div></div><div class="formSection"><h1 class="formSectionTitle">Properties</h1><div auto-duplicate="auto-duplicate" class="formField unlabeled grouped"><div class="inputWrapper pure-u-1-2"><input name="propertyName[]" placeholder="Name"/></div><div class="inputWrapper pure-u-1-2"><input name="propertyValue[]" placeholder="Value"/></div></div></div></div><div class="toolbarWindowControls bottom"><button type="submit" class="pure-button style-okay"><i class="fa fa-check"></i>Create</button></div></div></form>

@ -1 +0,0 @@
<div ng-class="{'window-focused': focused}" ng-show="visible" style="width: {{width || 400}}px; height: {{height || 300}}px; left: {{ x || 0 }}px; top: {{ y || 0 }}px;" class="window-wrapper window-styled"><div class="window-title"><span class="window-title-inner">{{ title }}</span><div class="window-close"><a href="#">X</a></div></div><div class="window-outer"><div class="window-inner-wrapper"><div window-view="window-view" ng-transclude="ng-transclude" class="window-inner"></div></div><div ng-show="resizable" class="window-resizer"></div></div></div>

@ -1,15 +0,0 @@
var router;
router = require("express-promise-router")();
router.get("/", function(req, res) {
return res.render("layout");
});
router.get("/node/:uuid", function(req, res) {
return res.json({
"uuid": req.params.uuid
});
});
module.exports = router;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save