-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): update 2 files and delete 1 file
- Loading branch information
Showing
2 changed files
with
67 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,97 @@ | ||
const fs = require('fs'); | ||
const fs = require('fs').promises; | ||
const glob = require('glob'); | ||
|
||
const content = ` | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script defer src="https://unpkg.com/@lottiefiles/[email protected]/dist/lottie-player.js"></script> | ||
`; | ||
|
||
function deleteDirectory(path) { | ||
if (fs.existsSync(path)) { | ||
fs.readdirSync(path).forEach((file) => { | ||
const curPath = `${path}/${file}`; | ||
if (fs.statSync(curPath).isDirectory()) { | ||
deleteDirectory(curPath); | ||
} else { | ||
fs.unlinkSync(curPath); | ||
async function deleteDirectory(path) { | ||
try { | ||
if (await fs.access(path)) { | ||
const files = await fs.readdir(path); | ||
for (const file of files) { | ||
const curPath = `${path}/${file}`; | ||
const stats = await fs.stat(curPath); | ||
if (stats.isDirectory()) { | ||
await deleteDirectory(curPath); | ||
} else { | ||
await fs.unlink(curPath); | ||
} | ||
} | ||
}); | ||
fs.rmdirSync(path); | ||
await fs.rmdir(path); | ||
} | ||
} catch (err) { | ||
console.error(`Error deleting directory ${path}:`, err); | ||
} | ||
} | ||
|
||
function copyDirectory(src, dest) { | ||
fs.mkdirSync(dest); | ||
fs.readdirSync(src).forEach((file) => { | ||
const curPath = `${src}/${file}`; | ||
if (fs.statSync(curPath).isDirectory()) { | ||
copyDirectory(curPath, `${dest}/${file}`); | ||
} else { | ||
fs.copyFileSync(curPath, `${dest}/${file}`); | ||
async function copyDirectory(src, dest) { | ||
try { | ||
await fs.mkdir(dest); | ||
const files = await fs.readdir(src); | ||
for (const file of files) { | ||
const curPath = `${src}/${file}`; | ||
const stats = await fs.stat(curPath); | ||
if (stats.isDirectory()) { | ||
await copyDirectory(curPath, `${dest}/${file}`); | ||
} else { | ||
await fs.copyFile(curPath, `${dest}/${file}`); | ||
} | ||
} | ||
}); | ||
} catch (err) { | ||
console.error(`Error copying directory ${src} to ${dest}:`, err); | ||
} | ||
} | ||
|
||
async function buildPages() { | ||
await deleteDirectory('./dist/'); | ||
await copyDirectory('./components/', './dist/'); | ||
await copyDirectory('./public/', './dist/public/'); | ||
|
||
const files = await glob.sync('dist/**/*.html'); | ||
console.log('Total Components:', files.length); | ||
|
||
for (const filename of files) { | ||
console.log(filename); | ||
try { | ||
await fs.promises.appendFile(filename, content); | ||
} catch (err) { | ||
console.error(err); | ||
try { | ||
await deleteDirectory('./dist/'); | ||
await copyDirectory('./components/', './dist/'); | ||
await copyDirectory('./public/', './dist/public/'); | ||
|
||
const files = await glob.sync('dist/**/*.html'); | ||
console.log('Total Components:', files.length); | ||
|
||
for (const filename of files) { | ||
console.log(filename); | ||
await fs.appendFile(filename, content); | ||
} | ||
} | ||
|
||
console.log('Tags Injected'); | ||
console.log('Tags Injected'); | ||
} catch (err) { | ||
console.error('Error building pages:', err); | ||
} | ||
} | ||
|
||
let mainIndex = ''; | ||
|
||
async function buildIndex() { | ||
const filenames = await glob.sync('dist/**/*.html'); | ||
|
||
let dummyOk = null; | ||
try { | ||
let mainIndex = ''; | ||
const filenames = await glob.sync('dist/**/*.html'); | ||
let previousDirectory = null; | ||
|
||
for (const filename of filenames) { | ||
const newf = filename.replace('dist/', 'https://tailwind.besoeasy.com/'); | ||
const newn = filename.replace('dist/', ''); | ||
for (const filename of filenames) { | ||
const newf = filename.replace('dist/', 'https://tailwind.besoeasy.com/'); | ||
const newn = filename.replace('dist/', ''); | ||
const parts = newn.split('/'); | ||
|
||
const parts = newn.split('/'); | ||
if (previousDirectory !== parts[0]) { | ||
mainIndex += `<div class="py-20 leading-none text-4xl uppercase">${parts[0]}</div>`; | ||
} | ||
|
||
console.log(parts[0]); | ||
previousDirectory = parts[0]; | ||
const nameS = parts[1].split('.html')[0]; | ||
|
||
if (dummyOk !== parts[0]) { | ||
mainIndex += `<div class="py-20 leading-none text-4xl uppercase">${parts[0]}</div>`; | ||
mainIndex += `<div class="m-5 uppercase"><a href="${newf}" class="text-xl">${nameS}</a></div>`; | ||
} | ||
|
||
dummyOk = parts[0]; | ||
const nameS = parts[1].split('.html')[0]; | ||
|
||
mainIndex += `<div class="m-5 uppercase"><a href="${newf}" class="text-xl">${nameS}</a></div>`; | ||
} | ||
|
||
const template = ` | ||
<section class="w-full px-8 text-gray-700 bg-white body-font tails-selected-element"> | ||
<div class="container flex flex-col items-center justify-between py-5 mx-auto md:flex-row"> | ||
<a href="https://tailwind.besoeasy.com/" class="inline-block font-sans text-2xl font-extrabold text-left text-black no-underline bg-transparent cursor-pointer focus:no-underline">Tailwind CSS Components</a> | ||
<div class="inline-flex items-center ml-5 space-x-6 lg:w-2/5 lg:justify-end lg:ml-0"> | ||
<a href="https://github.com/besoeasy/tailwind-components" class="inline-flex items-center justify-center px-4 py-2 text-base font-medium leading-6 text-white whitespace-no-wrap bg-purple-600 border border-transparent shadow-sm rounded-xl hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-700" data-rounded="rounded-xl" data-primary="purple-600"> | ||
GITHUB | ||
</a> | ||
</div> | ||
</div> | ||
</section> | ||
<div class="py-20 px-2 m-auto max-w-5xl">${mainIndex}</div> | ||
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> | ||
`; | ||
const template = ` | ||
<!-- Your HTML template --> | ||
`; | ||
|
||
try { | ||
await fs.promises.writeFile('./dist/index.html', template); | ||
await fs.writeFile('./dist/index.html', template); | ||
} catch (err) { | ||
console.error(err); | ||
console.error('Error building index:', err); | ||
} | ||
} | ||
|
||
|
@@ -106,7 +100,7 @@ async function main() { | |
await buildPages(); | ||
await buildIndex(); | ||
} catch (err) { | ||
console.error(err); | ||
console.error('Error in main:', err); | ||
} | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.