Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: paths location #214

Merged
merged 2 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ var convict = require('convict')
var fs = require('fs')
var path = require('path')

// Set folder location differently if an npm install
var installRoot = ~process.cwd().indexOf('node_modules')
? __dirname
: process.cwd()

// Define a schema
var conf = convict({
app: {
Expand Down Expand Up @@ -320,13 +325,13 @@ var conf = convict({
doc: '',
format: Object,
default: {
datasources: path.join(__dirname, '/workspace/datasources'),
events: path.join(__dirname, '/workspace/events'),
middleware: path.join(__dirname, '/workspace/middleware'),
pages: path.join(__dirname, '/workspace/pages'),
public: path.join(__dirname, '/workspace/public'),
routes: path.join(__dirname, '/workspace/routes'),
tokenWallets: path.join(__dirname, '/.wallet')
datasources: path.join(installRoot, '/workspace/datasources'),
events: path.join(installRoot, '/workspace/events'),
middleware: path.join(installRoot, '/workspace/middleware'),
pages: path.join(installRoot, '/workspace/pages'),
public: path.join(installRoot, '/workspace/public'),
routes: path.join(installRoot, '/workspace/routes'),
tokenWallets: path.join(installRoot, '/.wallet')
}
},
sessions: {
Expand Down
17 changes: 14 additions & 3 deletions dadi/lib/cache/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,25 @@ DatasourceCache.prototype.cachingEnabled = function (opts) {
* @param {object} datasource - a datasource schema object containing the datasource settings
*/
DatasourceCache.prototype.getFilename = function (opts) {
var filename = crypto.createHash('sha1').update(opts.name).digest('hex')
var filename = crypto
.createHash('sha1')
.update(opts.name)
.digest('hex')

if (opts.cacheKey) {
filename +=
'_' + crypto.createHash('sha1').update(opts.cacheKey).digest('hex')
'_' +
crypto
.createHash('sha1')
.update(opts.cacheKey)
.digest('hex')
} else {
filename +=
'_' + crypto.createHash('sha1').update(opts.endpoint).digest('hex')
'_' +
crypto
.createHash('sha1')
.update(opts.endpoint)
.digest('hex')
}

return filename
Expand Down
5 changes: 4 additions & 1 deletion dadi/lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ module.exports.parseQuery = function (queryStr) {

module.exports.clearCache = function (req, Cache, callback) {
var pathname = req.body.path
var modelDir = crypto.createHash('sha1').update(pathname).digest('hex')
var modelDir = crypto
.createHash('sha1')
.update(pathname)
.digest('hex')
var cacheDir = config.get('caching.directory.path')

var datasourceCachePaths = []
Expand Down
2 changes: 1 addition & 1 deletion dadi/lib/view/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports.html = function (res, req, next, statusCode, contentType) {
module.exports.addHeaders = function (res) {
var headers = config.get('headers').cors || {}

Object.keys(headers).forEach((key) => {
Object.keys(headers).forEach(key => {
res.setHeader(key, headers[key])
if (key === 'Access-Control-Allow-Origin' && headers[key] !== '*') {
res.setHeader('Vary', 'Origin')
Expand Down
18 changes: 9 additions & 9 deletions scripts/copy-config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#! /usr/bin/env node

var fs = require('fs')
var mkdirp = require('mkdirp')
var path = require('path')
var fs = require("fs")
var mkdirp = require("mkdirp")
var path = require("path")

var currentPath = process.cwd() // should be node_modules/@dadi/web
var configPath = path.join(
__dirname,
'../config/config.development.json.sample'
"../config/config.development.json.sample"
)
var destinationDir = path.join(currentPath, '../../../config')
var destinationFile = path.join(destinationDir, 'config.development.json')
var destinationDir = path.join(currentPath, "../../../config")
var destinationFile = path.join(destinationDir, "config.development.json")

// Only run if in a node_modules folder
if (~currentPath.indexOf('node_modules')) {
if (~currentPath.indexOf("node_modules")) {
mkdirp(destinationDir, (err, made) => {
if (err) throw err

fs.stat(destinationFile, (err, stats) => {
if (err && err.code && err.code === 'ENOENT') {
if (err && err.code && err.code === "ENOENT") {
// file doesn't exist
fs.readFile(configPath, (err, data) => {
if (err) throw err

fs.writeFile(destinationFile, data, err => {
if (err) throw err

console.log('Web configuration created at', destinationFile)
console.log("Web configuration created at", destinationFile)
})
})
}
Expand Down
14 changes: 7 additions & 7 deletions scripts/copy-workspace.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#! /usr/bin/env node

var fs = require('fs-extra')
var path = require('path')
var fs = require("fs-extra")
var path = require("path")

var currentPath = process.cwd() // should be node_modules/@dadi/web
var workspacePath = path.join(currentPath, 'workspace')
var destinationDir = path.join(currentPath, '../../../workspace')
var workspacePath = path.join(currentPath, "workspace")
var destinationDir = path.join(currentPath, "../../../workspace")

// Only run if in a node_modules folder
if (~currentPath.indexOf('node_modules')) {
if (~currentPath.indexOf("node_modules")) {
fs.stat(destinationDir, (err, stats) => {
if (err && err.code && err.code === 'ENOENT') {
if (err && err.code && err.code === "ENOENT") {
fs.copy(workspacePath, destinationDir, { overwrite: false }, err => {
if (err) return console.error(err)
console.log('Web workspace created at', destinationDir)
console.log("Web workspace created at", destinationDir)
})
}
})
Expand Down
14 changes: 7 additions & 7 deletions scripts/init-web.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#! /usr/bin/env node

var fs = require('fs')
var path = require('path')
var fs = require("fs")
var path = require("path")

var currentPath = process.cwd() // should be node_modules/@dadi/web
var destinationFile = path.join(currentPath, '../../../server.js')
var destinationFile = path.join(currentPath, "../../../server.js")

// Add an server.js (which runs on npm start) file containing - require('@dadi/web')
// More info: https://docs.npmjs.com/cli/start

// Only run if in a node_modules folder
if (~currentPath.indexOf('node_modules')) {
if (~currentPath.indexOf("node_modules")) {
fs.stat(destinationFile, (err, stats) => {
if (err && err.code && err.code === 'ENOENT') {
if (err && err.code && err.code === "ENOENT") {
// file doesn't exist
fs.writeFile(
destinationFile,
"require('@dadi/web')({engines:[require('@dadi/web-dustjs')]})",
function (err) {
function(err) {
if (err) return console.log(err)
console.log('Web entry point created at', destinationFile)
console.log("Web entry point created at", destinationFile)
}
)
}
Expand Down
23 changes: 15 additions & 8 deletions test/acceptance/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ describe("Routing", function(done) {
var pages = TestHelper.setUpPages()

TestHelper.startServer(pages).then(() => {
client.get("/test").set("Host", "").expect(400).end(function(err, res) {
if (err) return done(err)
done()
})
client
.get("/test")
.set("Host", "")
.expect(400)
.end(function(err, res) {
if (err) return done(err)
done()
})
})
})

Expand Down Expand Up @@ -648,10 +652,13 @@ describe("Routing", function(done) {
var httpClient = request(
"http://" + config.get("server.host") + ":9999"
)
httpClient.get("/test").expect(302).end(function(err, res) {
if (err) return done(err)
done()
})
httpClient
.get("/test")
.expect(302)
.end(function(err, res) {
if (err) return done(err)
done()
})
})
})
})
Expand Down
12 changes: 9 additions & 3 deletions test/unit/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ describe("Cache", function(done) {
}

cache.reset()
cache(server.object).cachingEnabled(req).should.eql(false)
cache(server.object)
.cachingEnabled(req)
.should.eql(false)

done()
})
Expand Down Expand Up @@ -249,7 +251,9 @@ describe("Cache", function(done) {
}

cache.reset()
cache(server.object).cachingEnabled(req).should.eql(false)
cache(server.object)
.cachingEnabled(req)
.should.eql(false)

done()
})
Expand Down Expand Up @@ -321,7 +325,9 @@ describe("Cache", function(done) {
}

cache.reset()
cache(server.object).cachingEnabled(req).should.eql(false)
cache(server.object)
.cachingEnabled(req)
.should.eql(false)
done()
})
)
Expand Down
4 changes: 3 additions & 1 deletion test/unit/preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe("Preloader", function(done) {
preloadSpy.called.should.eql(true)
providerStub.called.should.eql(true)

Preload().get("car-makes").should.eql(results.results)
Preload()
.get("car-makes")
.should.eql(results.results)

done()
})
Expand Down