-
Notifications
You must be signed in to change notification settings - Fork 1
/
clean.js
161 lines (137 loc) · 4.99 KB
/
clean.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import fs from 'fs-extra'
import path from 'path';
import replace from 'replace-in-file';
import * as readline from "readline-sync";
const pathToProject = path.resolve('./');
const demoProjectFolderName = `${pathToProject}/Gulp_Default_Project`
const snippetsFolderName = `${pathToProject}/snippets`
const readmeFolder = `${pathToProject}/readmeFiles`
const src = '/#src'
const scriptModules = `${pathToProject}${src}/scripts/modules/`
const scriptGeneral = `${pathToProject}${src}/scripts/`
const stylesModules = `${pathToProject}${src}/styles/modules/`
const componentsFolder = `${pathToProject}${src}/components/`
const fontsGitkeep = `${src}/fonts/.gitkeep`
const mainStyleFile = `${pathToProject}${src}/styles/style.styl`
const mainHtmlFile = `${pathToProject}${src}/index.html`
const mainScriptFile = `${src}/scripts/script.ts`
const gulpSliderConnectionFile = `${pathToProject}/gulpfile.js`
const slidersFile = `${pathToProject}${src}/scripts/sliders.js`
const srcDemoFoldersAndFIles =
[`${pathToProject}${src}/docs`, `${pathToProject}${src}/img/demo`,]
const hint = '(enter [y], if you not, enter [enter] or another key and [enter])';
deleteDemoContent()
cleanReadmeFilesAndFolders()
deleteSnippets()
deleteDemoProject()
console.log('Initialize the swiper-slider? ' + hint)
await setSlider()
await setModules()
console.log('🎆🎆🎆 I wish You a successful job!');
async function setModules() {
await includeModuleByQuestion(
'Modal-Window',
`${scriptModules}modalWindow.ts`,
null,
`${componentsFolder}_modals.htm`,
async () => {
await replace({
files: mainHtmlFile,
from: `@@include('components/_modals.htm', {})`, to: '',
})
})
await includeModuleByQuestion('Burger-menu', `${scriptModules}burgerMenu.ts`, `${stylesModules}_burgerMenu.styl`)
await includeModuleByQuestion('Filter', `${scriptModules}filter.ts`)
await includeModuleByQuestion('Spoilers', `${scriptModules}spoiler.ts`, `${stylesModules}_spoiler.styl`)
await includeModuleByQuestion('Sidebar', `${scriptModules}sidebar.ts`, `${stylesModules}_sidebar.styl`)
await includeModuleByQuestion('Submenu', `${scriptModules}submenu.ts`, `${stylesModules}_submenu.styl`)
await includeModuleByQuestion('Tabs', `${scriptModules}tab.ts`)
await includeModuleByQuestion('Element-modal', `${scriptModules}elementModal.ts`)
await includeModuleByQuestion('Parallax', `${scriptModules}parallax.ts`)
await includeModuleByQuestion('ScrollToElement', `${scriptModules}scrollToElement.ts`)
await includeModuleByQuestion('Animations by scroll', `${scriptModules}animateByScroll.ts`)
await includeModuleByQuestion('Swipe module', `${scriptModules}swipe.ts`)
await includeModuleByQuestion('Searchbar styles', ``, `${stylesModules}_searchbar.styl`)
await includeModuleByQuestion('Form styles', ``, `${stylesModules}_form.styl`)
}
function deleteDemoContent() {
try {
for (let pathToDemo of srcDemoFoldersAndFIles) {
fs.removeSync(pathToDemo)
}
console.log('✅ The demo content have been deleted.');
} catch (error) {
console.log('❌' + error)
}
}
function cleanReadmeFilesAndFolders() {
try {
fs.emptyDirSync(readmeFolder)
fs.removeSync(`${pathToProject}/README.md`)
fs.createFileSync('README.md')
console.log('✅ The readme folder and file are clean.');
} catch (error) {
console.log('❌' + error);
}
}
function deleteDemoProject() {
try {
fs.removeSync(demoProjectFolderName)
console.log('✅ Demo Project have been deleted.');
} catch (error) {
console.log('❌' + error);
}
}
function deleteSnippets() {
try {
fs.removeSync(snippetsFolderName)
console.log('✅ Snippets have been deleted.');
} catch (error) {
console.log('❌' + error);
}
}
async function setSlider(questionString) {
let answer = readline.question(questionString).toLowerCase()
if (answer !== 'y') {
await replace({
files: gulpSliderConnectionFile,
from: `let build = gulp.series(recreate, setupSwiperCss, setupSwiperJs,`,
to: 'let build = gulp.series(recreate,',
})
await replace({
files: mainHtmlFile,
from: ['<!-- Swiper -->',
'<link rel="stylesheet" href="css/swiper-bundle.min.css">',
'<script defer src="scripts/swiper-bundle.min.js"></script>',
'<script type="module" src="scripts/sliders.js"></script>'],
to: '',
})
fs.removeSync(slidersFile)
}
}
async function includeModuleByQuestion(moduleName, scriptPath, stylePath, htmlPath, replaceFunc) {
let questionString = `Include the ${moduleName}? ${hint}`
let answer = readline.question(questionString).toLowerCase()
if (answer === 'y')
return
if (scriptPath) {
fs.removeSync(scriptPath)
let scriptNameWithoutExp = path.basename(scriptPath, '.ts')
let scriptConnFileName = `${scriptNameWithoutExp}Conn.ts`
fs.removeSync(scriptGeneral + scriptConnFileName)
}
if (stylePath) {
fs.removeSync(stylePath)
let styleModuleName = path.basename(stylePath, '.styl')
await replace({
files: mainStyleFile,
from: `@import 'modules/${styleModuleName}';`, to: '',
})
}
if (htmlPath) {
fs.removeSync(htmlPath)
}
if (replaceFunc) {
await replaceFunc()
}
}