2
0
mirror of https://github.com/tenrok/vue-context.git synced 2026-06-07 08:22:25 +03:00
Files
vue-context/docs-build/cleanup.js
T
rawilk b7760ae2d5 wip
2020-08-30 21:20:31 -05:00

95 lines
2.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
const fs = require('fs');
const filesToDelete = [
__dirname + '/mix-manifest.json',
];
filesToDelete.forEach(file => {
try {
fs.unlinkSync(file);
} catch (e) {}
});
fs.rmdirSync(__dirname + '/dist', { recursive: true });
console.log('All extra files cleaned up!');
// Add "ids" to the files for cache busting, and also update the script references in the docs
// const docFiles = [
// __dirname + '/../docs/demos/basic.md',
// __dirname + '/../docs/demos/advanced.md',
// ];
const docFiles = {
advanced: __dirname + '/../docs/demos/advanced.md',
}
const scripts = {
advanced: __dirname + '/../docs/scripts/vue-context-advanced-demos.js',
};
const renameFile = path => {
const id = Date.now();
const parts = path.split('/');
const fileName = parts[parts.length - 1];
const fileNameParts = fileName.split('.');
const newName = `${fileNameParts[0]}.${id}.${fileNameParts[1]}`;
const newPath = __dirname + '/../docs/scripts/' + newName;
fs.renameSync(path, newPath);
return newName;
};
const updateScriptSrc = (markdownFile, newName) => {
const content = fs.readFileSync(markdownFile, 'utf-8');
const lines = content.split("\n");
const scriptLine = lines[lines.length - 2];
if (scriptLine.startsWith('<script')) {
lines[lines.length - 2] = `<script src="../scripts/${newName}"></script>`;
}
fs.writeFileSync(markdownFile, lines.join("\n"));
};
Object.keys(scripts).forEach(key => {
const path = scripts[key];
const newName = renameFile(path);
updateScriptSrc(docFiles[key], newName);
});
return;
fs.readdir(__dirname + '/../docs/scripts', (err, files) => {
if (err) {
return;
}
files.forEach(file => {
const id = Date.now();
const oldPath = __dirname + '/../docs/scripts/' + file;
const parts = file.split('.');
const newPath = __dirname + '/../docs/scripts/' + parts[0] + `.${id}.` + parts[1];
fs.renameSync(oldPath, newPath);
docFiles.forEach(doc => {
const content = fs.readFileSync(doc, 'utf-8');
const regex = new RegExp("<script[\s\S]*?>[\s\S]*?<\/script>", 'gi');
console.log(content.replace(regex, '<foo>'));
});
});
});