This repository was archived by the owner on Oct 5, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathcleanup.js
executable file
·67 lines (48 loc) · 1.72 KB
/
cleanup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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 = {
basic: __dirname + '/../docs/demos/basic.md',
advanced: __dirname + '/../docs/demos/advanced.md',
props: __dirname + '/../docs/demos/props.md',
}
const scripts = {
basic: __dirname + '/../docs/scripts/vue-context-basic-demos.js',
advanced: __dirname + '/../docs/scripts/vue-context-advanced-demos.js',
props: __dirname + '/../docs/scripts/vue-context-props-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;