UNPKG

@abhijithvijayan/portfolio

Version:

CLI to use my portfolio site as a template to build yours!

93 lines (77 loc) 2.57 kB
const fs = require('fs'); const del = require('del'); const execa = require('execa'); const {isWin} = require('./os'); const {readFileAsync, writeFileAsync} = require('./fs'); const {sampleReadmeContent, sampleManifestContent} = require('./template'); async function deleteStrayFilesAndFolders() { const deleteCommand = isWin ? 'del' : 'rm'; if (fs.existsSync('.kodiak.toml')) { await execa(`${deleteCommand} .kodiak.toml`, {shell: true}); } if (fs.existsSync('CONTRIBUTING.md')) { await execa(`${deleteCommand} CONTRIBUTING.md`, {shell: true}); } if (fs.existsSync('CODE_OF_CONDUCT.md')) { await execa(`${deleteCommand} CODE_OF_CONDUCT.md`, {shell: true}); } // overwrite `config/index.js` with `config/sample.js` if (fs.existsSync('config/index.js')) { await writeFileAsync( 'config/index.js', await readFileAsync('config/sample.js') ); } if (fs.existsSync('public/resume.pdf')) { await execa(`${deleteCommand} public/resume.pdf`, {shell: true}); } // overwrite public/manifest.json if (fs.existsSync('public/manifest.json')) { await writeFileAsync( 'public/manifest.json', JSON.stringify(sampleManifestContent, null, 2) ); } // overwrite README.md if (fs.existsSync('README.md')) { await writeFileAsync('README.md', sampleReadmeContent); } // update `package.json` fields: `name`, 'description`, `repository` if (fs.existsSync('package.json')) { const pkg = await readFileAsync(`package.json`); const fileContent = JSON.parse(pkg.toString()); fileContent.name = 'portfolio'; fileContent.description = 'My Portfolio Website, generated by @abhijithvijayan/portfolio'; delete fileContent.repository; await writeFileAsync('package.json', JSON.stringify(fileContent, null, 2)); } /** * delete markdown/** except sample.md * delete public/images * delete public/icons */ await del([ 'public/images/**', 'public/icons/**', 'markdown/home/**', 'markdown/about/**', 'markdown/experience/**', 'markdown/featured/**', 'markdown/projects/**', 'markdown/contact/**', '!markdown/home', '!markdown/home/sample.md', '!markdown/about', '!markdown/about/sample.md', '!markdown/experience', '!markdown/experience/sample.md', '!markdown/featured', '!markdown/featured/sample.md', '!markdown/projects', '!markdown/projects/sample.md', '!markdown/contact', '!markdown/contact/sample.md', ]); } module.exports = deleteStrayFilesAndFolders;