-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: Add a script for scaffolding default files & components. (#148)
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const scaffoldDir = path.join(__dirname, '/../playground') | ||
const target = '.' | ||
|
||
function copyFile (source, target) { | ||
const targetFile = target + '/' + path.basename(source) | ||
|
||
// If target is a directory, a new file with the same name will be created | ||
if (!fs.existsSync(targetFile)) { | ||
// eslint-disable-next-line no-console | ||
console.log(targetFile + ' - Created.') | ||
fs.writeFileSync(targetFile, fs.readFileSync(source)) | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log(targetFile + ' - Existing, skipped.') | ||
} | ||
} | ||
|
||
function syncDir (directory) { | ||
fs.readdirSync(scaffoldDir + '/' + directory).forEach(function (item) { | ||
if (fs.lstatSync(scaffoldDir + '/' + directory + '/' + item).isDirectory()) { | ||
syncDir(directory + '/' + item) | ||
} else { | ||
copyFile(scaffoldDir + '/' + directory + '/' + item, target + '/' + directory) | ||
} | ||
}) | ||
} | ||
|
||
// Here we want to make sure our directories exist. | ||
fs.mkdirSync('./components/global', { recursive: true }) | ||
fs.mkdirSync('./pages', { recursive: true }) | ||
|
||
syncDir('pages') | ||
syncDir('components') | ||
copyFile(scaffoldDir + '/app.vue', target) |
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