Browse Source

tidy

master
Conduitry 1 year ago
parent
commit
156a657198
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      index.js

+ 7
- 7
index.js View File

@ -1,21 +1,21 @@
const fs = require('fs');
const readText = filename => new Promise(res => fs.readFile(filename, (err, data) => (err ? res(null) : res(data.toString()))));
const read_text = filename => new Promise(res => fs.readFile(filename, (err, data) => (err ? res(null) : res(data.toString()))));
module.exports = ({ extensions = ['.html', '.svelte'] } = {}) => ({
transform(code, id) {
const extension = extensions.find(extension => id.endsWith(extension));
if (extension) {
const baseId = id.slice(0, -extension.length);
const jsId = baseId + '.js';
const cssId = baseId + '.css';
return Promise.all([jsId, cssId].map(readText)).then(([js, css]) => {
const base_id = id.slice(0, -extension.length);
const js_id = base_id + '.js';
const css_id = base_id + '.css';
return Promise.all([js_id, css_id].map(read_text)).then(([js, css]) => {
if (js) {
this.addWatchFile(jsId);
this.addWatchFile(js_id);
code += `\n<script>\n${js}\n</script>\n`;
}
if (css) {
this.addWatchFile(cssId);
this.addWatchFile(css_id);
code += `\n<style>\n${css}\n</style>\n`;
}
return code;

Loading…
Cancel
Save