Skip to content

Commit a408b58

Browse files
committed
Copying over whole directory
Unsure about the affects on testing, so checking in now just in case
1 parent 31d35d1 commit a408b58

12 files changed

+46
-46
lines changed

lib/models/account-template.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict'
22

3-
import { processHandlebarFile } from '../utils'
4-
53
const fs = require('fs-extra')
64
const path = require('path')
75
const mime = require('mime-types')
86
const recursiveRead = require('recursive-readdir')
9-
const Handlebars = require('handlebars')
7+
const utils = require('../utils')
108

119
const RDF_MIME_TYPES = require('../ldp').RDF_MIME_TYPES
1210
const TEMPLATE_EXTENSIONS = [ '.acl', '.meta', '.json', '.hbs', '.handlebars' ]
@@ -132,7 +130,7 @@ class AccountTemplate {
132130
*/
133131
processAccount (accountPath) {
134132
return this.readTemplateFiles(accountPath)
135-
.then(files => Promise.all(files.map(path => processHandlebarFile(path, this.substitutions))))
133+
.then(files => Promise.all(files.map(path => utils.processHandlebarFile(path, this.substitutions))))
136134
}
137135

138136
/**

lib/server-config.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict'
2-
import { processHandlebarFile } from './utils'
32

43
/**
54
* Server config initialization utilities
65
*/
76

87
const fs = require('fs-extra')
98
const path = require('path')
9+
const utils = require('./utils')
1010

1111
/**
1212
* Ensures that a directory has been copied / initialized. Used to ensure that
@@ -39,28 +39,23 @@ function ensureDirCopyExists (fromDir, toDir) {
3939
* @param argv {Function} Express.js app object
4040
*/
4141
async function ensureWelcomePage (argv) {
42-
let { multiuser, templates } = argv
43-
let rootDir = path.resolve(argv.root)
44-
let serverRootDir
45-
46-
if (multiuser) {
47-
serverRootDir = path.join(rootDir, argv.host.hostname)
48-
} else {
49-
serverRootDir = rootDir
50-
}
42+
const { multiuser, templates } = argv
43+
const rootDir = path.resolve(argv.root)
44+
const serverRootDir = multiuser ? path.join(rootDir, argv.host.hostname) : rootDir
5145

52-
let defaultIndexPage = path.join(templates.server, 'index.html')
53-
let existingIndexPage = path.join(serverRootDir, 'index.html')
54-
let defaultIndexPageAcl = path.join(templates.server, 'index.html.acl')
55-
let existingIndexPageAcl = path.join(serverRootDir, 'index.html.acl')
46+
// let defaultIndexPage = path.join(templates.server, 'index.html')
47+
const existingIndexPage = path.join(serverRootDir, 'index.html')
48+
// let defaultIndexPageAcl = path.join(templates.server, 'index.html.acl')
49+
// let existingIndexPageAcl = path.join(serverRootDir, 'index.html.acl')
5650

5751
if (!fs.existsSync(existingIndexPage)) {
5852
fs.mkdirp(serverRootDir)
59-
fs.copySync(defaultIndexPage, existingIndexPage)
60-
await processHandlebarFile(existingIndexPage, {
53+
await utils.copyTemplateDir(templates.server, serverRootDir)
54+
await utils.processHandlebarFile(existingIndexPage, {
55+
serverName: 'Tittentei'
6156
// Need to load config from somewhere
6257
})
63-
fs.copySync(defaultIndexPageAcl, existingIndexPageAcl)
58+
// fs.copySync(defaultIndexPageAcl, existingIndexPageAcl)
6459
}
6560
}
6661

lib/utils.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports.pathBasename = pathBasename
55
module.exports.getFullUri = getFullUri
66
module.exports.hasSuffix = hasSuffix
77
module.exports.parse = parse
8-
module.exports.processHandlebarFile = processHandlebarFile
98
module.exports.serialize = serialize
109
module.exports.translate = translate
1110
module.exports.stringToStream = stringToStream
@@ -14,8 +13,10 @@ module.exports.debrack = debrack
1413
module.exports.stripLineEndings = stripLineEndings
1514
module.exports.fullUrlForReq = fullUrlForReq
1615
module.exports.routeResolvedFile = routeResolvedFile
16+
module.exports.processHandlebarFile = processHandlebarFile
17+
module.exports.copyTemplateDir = copyTemplateDir
1718

18-
const fs = require('fs')
19+
const fs = require('fs-extra')
1920
const path = require('path')
2021
const $rdf = require('rdflib')
2122
const from = require('from2')
@@ -198,9 +199,19 @@ function processHandlebarTemplate (source, substitutions) {
198199
}
199200
}
200201

202+
async function copyTemplateDir (templatePath, targetPath) {
203+
return new Promise((resolve, reject) => {
204+
fs.copy(templatePath, targetPath, (error) => {
205+
if (error) { return reject(error) }
206+
207+
resolve()
208+
})
209+
})
210+
}
211+
201212
function serialize (graph, baseUri, contentType, callback) {
202213
try {
203-
// target, kb, base, contentType, callback
214+
// target, kb, base, contentType, callback
204215
$rdf.serialize(null, graph, baseUri, contentType, function (err, result) {
205216
if (err) {
206217
console.log(err)
@@ -222,9 +233,9 @@ function serialize (graph, baseUri, contentType, callback) {
222233
function translate (stream, baseUri, from, to, callback) {
223234
// Handle Turtle Accept header
224235
if (to === 'text/turtle' ||
225-
to === 'text/n3' ||
226-
to === 'application/turtle' ||
227-
to === 'application/n3') {
236+
to === 'text/n3' ||
237+
to === 'application/turtle' ||
238+
to === 'application/n3') {
228239
to = 'text/turtle'
229240
}
230241

test/integration/account-creation-oidc-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ describe('AccountManager (OIDC account creation tests)', function () {
3737
after(function () {
3838
if (ldpHttpsServer) ldpHttpsServer.close()
3939
fs.removeSync(path.join(dbPath, 'oidc/users/users'))
40-
fs.removeSync(path.join(rootPath, 'localhost/index.html'))
41-
fs.removeSync(path.join(rootPath, 'localhost/index.html.acl'))
40+
fs.removeSync(path.join(rootPath, 'localhost'))
41+
fs.removeSync(path.join(rootPath, 'localhost'))
4242
})
4343

4444
var server = supertest(serverUri)

test/integration/acl-oidc-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
8686

8787
after(() => {
8888
if (ldpHttpsServer) ldpHttpsServer.close()
89-
fs.removeSync(path.join(rootPath, 'index.html'))
90-
fs.removeSync(path.join(rootPath, 'index.html.acl'))
89+
fs.removeSync(path.join(rootPath))
9190
})
9291

9392
const origin1 = 'http://example.org/'

test/integration/acl-tls-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ describe('ACL with WebID+TLS', function () {
6969

7070
after(function () {
7171
if (ldpHttpsServer) ldpHttpsServer.close()
72-
fs.removeSync(path.join(rootPath, 'index.html'))
73-
fs.removeSync(path.join(rootPath, 'index.html.acl'))
72+
fs.removeSync(path.join(rootPath))
7473
})
7574

7675
function createOptions (path, user) {

test/integration/auth-proxy-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path')
33
const nock = require('nock')
44
const request = require('supertest')
55
const { expect } = require('chai')
6-
const rm = require('../utils').rm
6+
const rmDir = require('../utils').rmDir
77

88
const USER = 'https://ruben.verborgh.org/profile/#me'
99

@@ -32,8 +32,7 @@ describe('Auth Proxy', () => {
3232
// Release back-end server
3333
nock.cleanAll()
3434
// Remove created index files
35-
rm('index.html')
36-
rm('index.html.acl')
35+
rmDir()
3736
})
3837

3938
describe('responding to /server/a', () => {

test/integration/authentication-oidc-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ describe('Authentication API (OIDC)', () => {
8181
alicePod.close()
8282
bobPod.close()
8383
fs.removeSync(path.join(aliceDbPath, 'oidc/users'))
84-
fs.removeSync(path.join(aliceRootPath, 'index.html'))
85-
fs.removeSync(path.join(aliceRootPath, 'index.html.acl'))
86-
fs.removeSync(path.join(bobRootPath, 'index.html'))
87-
fs.removeSync(path.join(bobRootPath, 'index.html.acl'))
84+
fs.removeSync(path.join(aliceRootPath))
85+
fs.removeSync(path.join(bobRootPath))
8886
})
8987

9088
describe('Login page (GET /login)', () => {

test/integration/capability-discovery-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ describe('API', () => {
4848

4949
after(() => {
5050
alicePod.close()
51-
fs.removeSync(path.join(aliceRootPath, 'index.html'))
52-
fs.removeSync(path.join(aliceRootPath, 'index.html.acl'))
51+
fs.removeSync(path.join(aliceRootPath))
5352
})
5453

5554
describe('Capability Discovery', () => {

test/integration/errors-oidc-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ describe('OIDC error handling', function () {
3030

3131
after(function () {
3232
if (ldpHttpsServer) ldpHttpsServer.close()
33-
fs.removeSync(path.join(rootPath, 'index.html'))
34-
fs.removeSync(path.join(rootPath, 'index.html.acl'))
33+
fs.removeSync(path.join(rootPath))
3534
})
3635

3736
const server = supertest(serverUri)

0 commit comments

Comments
 (0)