-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathclean-project.js
74 lines (62 loc) · 2.34 KB
/
clean-project.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
68
69
70
71
72
73
74
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
const indexVuePath = path.resolve(process.cwd(), './pages/index.vue');
function removeCleanupScript() {
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
if (packageJson.scripts && packageJson.scripts['script:cleanup']) {
delete packageJson.scripts['script:cleanup'];
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Removed "script:cleanup" script from package.json.');
} else {
console.log('"script:cleanup" script not found in package.json.');
}
} catch (error) {
console.error('Error reading or writing package.json:', error);
}
}
function emptyDirectory(directory) {
if (!fs.existsSync(directory)) {
console.log(`Directory ${directory} does not exist.`);
return;
}
const items = fs.readdirSync(directory);
for (const item of items) {
const fullPath = path.join(directory, item);
fs.rmSync(fullPath, { recursive: true, force: true });
}
console.log(`Deleted contents of ${directory}`);
}
function removeDirectory(directory) {
if (fs.existsSync(directory)) {
fs.rmSync(directory, { recursive: true, force: true });
console.log(`Deleted directory ${directory}`);
} else {
console.log(`Directory ${directory} does not exist.`);
}
}
function replaceIndexVueContent() {
try {
const newContent = `<template> 🚀 Here we go! </template>\n`;
fs.writeFileSync(indexVuePath, newContent, 'utf-8');
console.log('Replaced content of ./pages/index.vue');
} catch (error) {
console.error('Error updating ./pages/index.vue:', error);
}
}
function cleanProject() {
console.log('Cleaning project...');
const directoriesToEmpty = ['./components', './tests', './store'];
directoriesToEmpty.forEach(emptyDirectory);
const assetsDirToDelete = ['./.assets/img', './coverage', './.github', './.vscode', './.git', './SECURITY.md', './LICENSE'];
assetsDirToDelete.forEach(removeDirectory);
removeCleanupScript();
replaceIndexVueContent();
fs.rmSync(__filename, { force: true });
console.log(`Deleted clean-project.js script itself.`);
}
cleanProject();