Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch(extname(file)) {
case '.pug': {
html = renderPugFileAsHtml(file)
// html = await renderFile(file)
break
}
case '.htm': case '.html': {
html = fs.readFileSync(file).toString()
break
}
case '.css': case '.sass': {
if(isUpdate) {
const p = parseFileName(relative(process.cwd(), file))
const pugFile = `${p.dir}/${p.name}.pug`
const htmlFile = `${p.dir}/${p.name}.html`
if(fs.existsSync(pugFile)) {
return await processFile(pugFile, isUpdate)
} else if(fs.existsSync(htmlFile)) {
return await processFile(htmlFile, isUpdate)
}
}
return null
}
}
if(!html) {
if(options.debug && options.debug.logHTML)
console.debug(`no html found in file ${file}`)
return null
}
if(options.debug && options.debug.logHTML)
html = renderPugFileAsHtml(file)
// html = await renderFile(file)
break
}
case '.htm': case '.html': {
html = fs.readFileSync(file).toString()
break
}
case '.css': case '.sass': {
if(isUpdate) {
const p = parseFileName(relative(process.cwd(), file))
const pugFile = `${p.dir}/${p.name}.pug`
const htmlFile = `${p.dir}/${p.name}.html`
if(fs.existsSync(pugFile)) {
return await processFile(pugFile, isUpdate)
} else if(fs.existsSync(htmlFile)) {
return await processFile(htmlFile, isUpdate)
}
}
return null
}
}
if(!html) {
if(options.debug && options.debug.logHTML)
console.debug(`no html found in file ${file}`)
return null
}
if(options.debug && options.debug.logHTML)
console.debug(relativeFile, 'HTML:\n' + html)
isRootGererated() {
// eslint-disable-next-line
return fs.existsSync(generatedRoot);
},
function loadOptions() {
options = clone(defaultOptions)
if(fs.existsSync(configFileName)) {
const loadedOptions = JSON.parse(fs.readFileSync(configFileName).toString())
options = merge(options, loadedOptions)
}
plugins = []
if(options && options.plugins) {
for(let plugin of options.plugins) {
try {
const pluginFn = require(plugin)
plugins.push(pluginFn)
} catch(e) {
console.error(`error loading ${plugin}`, e)
}
}
}
}
async importSchema(baseDir) {
if (!fs.existsSync(baseDir)) return;
const contents = await fs.readdir(baseDir);
await Promise.all(contents.map(async content => {
const buffer = await fs.readFile(path.join(baseDir, content));
const data = JSON.parse(buffer);
await this.ctx.model.Schema.upsert(data);
}));
}
getScriptSnapshot: (fileName) =>
fs.existsSync(fileName) ? ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()) : undefined,
getScriptVersion: () => "0",
.then(body => {
if (!fs.existsSync(tmpPath)) {
fs.mkdir(tmpPath).then(() => body);
}
return body;
})
.then(body => fs.writeFile(outputPath, body, 'utf8'))
getScriptSnapshot: (fileName) =>
fs.existsSync(fileName) ? ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()) : undefined,
getScriptVersion: () => "0",