Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper-punchcard-commit-msg-1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Jul 11, 2017
2 parents 3b31d1b + 861c487 commit ac73983
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 222 deletions.
6 changes: 6 additions & 0 deletions config/test.js
Expand Up @@ -35,4 +35,10 @@ module.exports = {
workflows: {
directory: path.join(__dirname, '../tests/fixtures/workflows/good'),
},
storage: {
dest: 'tests/public/files',
temp: {
dest: 'tests/public/tmp/',
},
},
};
2 changes: 1 addition & 1 deletion lib/content/utils.js
Expand Up @@ -186,7 +186,7 @@ const filecompare = (files, inserted, val, attributes) => {
const data = inserted;

if (!files || !Array.isArray(files) || !data || typeof data !== 'object' || !values || typeof values !== 'object' || !attributes || typeof attributes !== 'object') {
return values;
return data;
}

// get all file inputs from the content type attributes
Expand Down
34 changes: 34 additions & 0 deletions lib/init/routes.js
@@ -1,11 +1,38 @@
'use strict';

const _ = require('lodash');
const config = require('config');
const multer = require('multer');
const mkdirp = require('mkdirp');

const content = require('../content/middleware');
const users = require('../users/middleware');

module.exports = (app) => {
return new Promise(res => {
// temp file storage location
const dest = config.storage.temp.dest || 'public/tmp/';

// multer form handling setup
const upload = multer({
storage: multer.diskStorage({
destination: (req, file, cb) => {
cb(null, dest);
},
filename: (req, file, cb) => {
cb(null, `/${file.originalname}`);
},
}),
});

// creates temp storage location if it does not exist
mkdirp.sync(dest);

// creates final storage location when using file storage
if (config.storage.type === 'fs' && typeof config.storage.dest === 'string' && config.storage.dest !== '') {
mkdirp.sync(config.storage.dest);
}

// add all content types and flows to request object
app.use((req, response, next) => {
const request = req;
Expand All @@ -16,12 +43,19 @@ module.exports = (app) => {
next();
});

// content type landing
app.use('/content/:type', content);

// save a piece of content
app.use('/content/:type/save', upload.any());

// piece of content actions
app.use('/content/:type/:id', content);
app.use('/content/:type/:id/:revision', content);
app.use('/content/:type/:id/:revision/edit', content);
app.use('/content/:type/:id/:revision/approve', content);

// individual user
app.use('/users/:id', users);

res(app);
Expand Down
45 changes: 6 additions & 39 deletions lib/routes/content.js
Expand Up @@ -6,7 +6,6 @@
*/
const config = require('config');
const types = require('punchcard-content-types');
const multer = require('multer');
const uuid = require('uuid');
const _ = require('lodash');
const path = require('path');
Expand All @@ -19,18 +18,6 @@ const workflows = require('../workflows');
const schedule = require('../schedule');
const storage = require('../storage');

const multeropts = {
storage: multer.diskStorage({
destination: (req, file, cb) => {
cb(null, config.storage.temp.dest || 'public/tmp/');
},
filename: (req, file, cb) => {
cb(null, `/${file.originalname}`);
},
}),
};
const upload = multer(multeropts);

/*
* Content Route Resolution
*
Expand Down Expand Up @@ -317,34 +304,31 @@ const routes = application => {
* @param {object} res - HTTP Response
* @param {object} next - Express callback
*/
app.post(`/${config.content.base}/:type/${config.content.actions.save}`, upload.any(), (req, res, next) => {
app.post(`/${config.content.base}/:type/${config.content.actions.save}`, (req, res, next) => {
const referrer = _.get(req.session, 'referrer') || req.get('Referrer');
let audits;
let publishable = false;
let check = 'publish';
let files = [];
let source = {
type: '',
type: 'add',
id: '',
revision: '',
revision: Math.floor(1000000 + Math.random() * 9000000),
};

if (req.body.submit === config.content.actions.new) {
check = 'save';
}

// determine data source from referrer
if (_.includes(referrer, '/add')) {
source.type = 'add';
}
else if (_.includes(referrer, '/edit')) {
if (_.includes(referrer, '/edit')) {
source = {
type: 'edit',
id: _.get(req.session, `form.content.edit[${req.params.type.toLowerCase()}].id`, ''),
revision: _.get(req.session, `form.content.edit[${req.params.type.toLowerCase()}].revision`, ''),
};
}
else {
else if (!_.includes(referrer, '/add')) {
// if neither edit or add, something nefarious is afoot
const err = {
message: 'You may only save from an edit or add form. For now...',
Expand Down Expand Up @@ -428,16 +412,14 @@ const routes = application => {
sunset,
publishable,
author: req.user.id,
value: data,
};

return storage.put(files).then(results => {
// if any files were uploaded
if (Object.keys(results).length > 0) {
insert.value = _.merge({}, data, utils.format(results));
}
else {
insert.value = data;
}

return database(`content-type--${req.content.type.id}`).where({
id,
Expand All @@ -449,21 +431,6 @@ const routes = application => {
// get all file inputs from the content type config
insert.value = cutils.filecompare(files, insert.value, content, req.content.type.attributes);


// /* NATH: now
// insert has file data now
// 1. use fileinputs


// 1. check for checkboxes without a new file
// - delete
// 2. check for checkboxes with a new file
// - delete
// 3. new file
// - replace with new
// 4. no file, no checkbox
// - replace with existing
// */
return database(`content-type--${req.params.type.toLowerCase()}`).insert(_.merge({}, insert, audits)).returning('*');
}).then(revision => {
const latest = utils.routes.identifier(revision, req.content.type)[0];
Expand Down
10 changes: 4 additions & 6 deletions lib/storage/get.js
@@ -1,6 +1,8 @@
'use strict';

const config = require('config');
const _ = require('lodash');
const urljoin = require('url-join');

/*
* File Get
Expand All @@ -11,17 +13,13 @@ const config = require('config');
*/
const get = file => {
const f = file;
let path = config.storage.public;
let path = _.get(config.storage, 'public', '');

if (path.indexOf('{{dest}}')) {
path = path.replace('{{dest}}', config.storage.dest);
}

if (path.substr(-1) !== '/') {
path += '/';
}

f.path = path + file.relative;
f.path = urljoin(path, file.relative);

return f;
};
Expand Down
4 changes: 3 additions & 1 deletion lib/users/routes.js
Expand Up @@ -65,9 +65,11 @@ const setup = (req, res, next) => {
* @param {object} res - HTTP Response
* @param {object} next - Express callback
*
* @returns {promise} database promise
*
*/
const all = (req, res, next) => {
database.select('*').from('users').then(rows => {
return database.select('*').from('users').then(rows => {
res.render('users/all', {
title: config.users.base,
users: rows,
Expand Down
69 changes: 38 additions & 31 deletions package.json
@@ -1,6 +1,7 @@
{
"name": "punchcard-cms",
"description": "Node-based content management system",
"version": "0.0.0",
"main": "index.js",
"keywords": [
"punchcard-cms",
Expand Down Expand Up @@ -45,17 +46,17 @@
"dependencies": {
"acl": "^0.4.9",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.15.2",
"body-parser": "^1.17.2",
"breakpoint-sass": "^2.7.1",
"cfenv": "^1.0.3",
"config": "^1.20.4",
"config": "^1.26.1",
"connect-ensure-login": "^0.1.1",
"connect-multiparty": "^2.0.0",
"connect-session-knex": "^1.0.23",
"debug": "^2.4.5",
"express": "^4.14.0",
"express-session": "^1.13.0",
"ibm-design-colors": "^1.8.0",
"connect-session-knex": "^1.3.3",
"debug": "^2.6.8",
"express": "^4.15.3",
"express-session": "^1.15.3",
"ibm-design-colors": "^2.0.4",
"input-plugin-checkbox": "^0.3.1",
"input-plugin-email": "^0.2.0",
"input-plugin-file": "^1.2.1",
Expand All @@ -66,54 +67,57 @@
"input-plugin-text": "^0.1.3",
"input-plugin-textarea": "^0.1.3",
"input-plugin-url": "^0.3.0",
"js-yaml": "^3.6.1",
"knex": "^0.12.6",
"js-yaml": "^3.8.4",
"knex": "^0.13.0",
"lodash": "^4.17.2",
"map-stream": "^0.0.6",
"modularscale-sass": "^2.1.1",
"moment": "^2.15.0",
"moment-timezone": "^0.5.4",
"morgan": "^1.6.1",
"map-stream": "^0.0.7",
"mkdirp": "^0.5.1",
"modularscale-sass": "^3.0.2",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"morgan": "^1.8.2",
"multer": "^1.2.1",
"multiparty": "^4.1.2",
"node-dir": "^0.1.11",
"node-schedule": "^1.1.1",
"node-dir": "^0.1.17",
"node-schedule": "^1.2.3",
"nodemon": "^1.10.0",
"nunjucks": "^3.0.0",
"nunjucks": "^3.0.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"pg": "^6.0.1",
"punchcard-content-types": "^6.1.15",
"request": "^2.75.0",
"pg": "^6.2.3",
"punchcard-content-types": "^6.1.20",
"request": "^2.80.0",
"sass-toolkit": "^2.10.0",
"serve-favicon": "^2.3.0",
"serve-favicon": "^2.4.3",
"stream-from-array": "^1.0.0",
"underscore.string": "^3.3.4",
"url-join": "^2.0.2",
"uuid": "^2.0.2",
"validator": "^6.0.0",
"validator": "^7.0.0",
"vinyl": "^2.0.0",
"vinyl-fs": "^2.4.4"
},
"devDependencies": {
"ava": "^0.16.0",
"coveralls": "^2.11.9",
"ava": "^0.19.1",
"ava-config": "^1.1.0",
"coveralls": "^2.13.1",
"del": "^2.2.2",
"eslint-config-punchcard": "^1.1.1",
"ghooks": "^2.0.0",
"gulp": "^3.9.1",
"input-plugin-file": "^1.1.0",
"lorem-ipsum": "^1.0.3",
"lorem-ipsum": "^1.0.4",
"mock-express-response": "^0.1.2",
"nock": "^9.0.0",
"node-mocks-http": "^1.5.3",
"nyc": "^10.0.0",
"nock": "^9.0.12",
"node-mocks-http": "^1.6.3",
"nyc": "^10.3.2",
"punchcard-commit-msg": "^1.1.0",
"punchcard-runner": "^2.1.2",
"punchcard-semantic-release": "^2.0.3",
"punchcard-shared-tests": "^1.3.0",
"reparo": "^1.1.1-0",
"semantic-release": "^6.3.2",
"supertest": "^2.0.1",
"semantic-release": "^6.3.6",
"supertest": "^3.0.0",
"tap-difflet": "^0.7.0",
"uuid": "^2.0.2"
},
Expand All @@ -136,7 +140,10 @@
"!tests/schedule.js"
],
"failFast": false,
"tap": false
"tap": false,
"require": [
"ava-config"
]
},
"config": {
"ghooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/js/app.js
@@ -1,5 +1,5 @@
(function app() {
'use strict';

console.log('Hello World');
console.log('Hello World'); // eslint-disable-line no-console
}());

0 comments on commit ac73983

Please sign in to comment.