Skip to content

Commit e7989a1

Browse files
committed
A bit more refactoring
I propose we put utils-methods into `lib/common`, and distinguish them a bit more than just `utils`
1 parent 934da81 commit e7989a1

File tree

1 file changed

+0
-62
lines changed

1 file changed

+0
-62
lines changed

lib/utils.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ module.exports.debrack = debrack
1313
module.exports.stripLineEndings = stripLineEndings
1414
module.exports.fullUrlForReq = fullUrlForReq
1515
module.exports.routeResolvedFile = routeResolvedFile
16-
module.exports.processHandlebarFile = processHandlebarFile
17-
module.exports.copyTemplateDir = copyTemplateDir
1816

1917
const fs = require('fs-extra')
2018
const path = require('path')
2119
const $rdf = require('rdflib')
2220
const from = require('from2')
2321
const url = require('url')
24-
const Handlebars = require('handlebars')
25-
const debug = require('./debug').errors
2622

2723
/**
2824
* Returns a fully qualified URL from an Express.js Request object.
@@ -151,64 +147,6 @@ function parse (data, baseUri, contentType, callback) {
151147
}
152148
}
153149

154-
/**
155-
* Reads a file, processes it (performing template substitution), and saves
156-
* back the processed result.
157-
*
158-
* @param filePath {string}
159-
* @param substitutions {Object}
160-
*
161-
* @return {Promise}
162-
*/
163-
async function processHandlebarFile (filePath, substitutions) {
164-
return new Promise((resolve, reject) => {
165-
fs.readFile(filePath, 'utf8', (error, rawSource) => {
166-
if (error) {
167-
return reject(error)
168-
}
169-
170-
const output = processHandlebarTemplate(rawSource, substitutions)
171-
172-
fs.writeFile(filePath, output, (error) => {
173-
if (error) {
174-
return reject(error)
175-
}
176-
resolve()
177-
})
178-
})
179-
})
180-
}
181-
182-
/**
183-
* Performs a Handlebars string template substitution, and returns the
184-
* resulting string.
185-
*
186-
* @see https://www.npmjs.com/package/handlebars
187-
*
188-
* @param source {string} e.g. 'Hello, {{name}}'
189-
*
190-
* @return {string} Result, e.g. 'Hello, Alice'
191-
*/
192-
function processHandlebarTemplate (source, substitutions) {
193-
try {
194-
const template = Handlebars.compile(source)
195-
return template(substitutions)
196-
} catch (error) {
197-
debug(`Error processing template: ${error}`)
198-
return source
199-
}
200-
}
201-
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-
212150
function serialize (graph, baseUri, contentType, callback) {
213151
try {
214152
// target, kb, base, contentType, callback

0 commit comments

Comments
 (0)