Skip to content

Instantly share code, notes, and snippets.

@Dafrok
Last active November 26, 2015 05:27
Show Gist options
  • Save Dafrok/c1e9cd76c1abfbe40da0 to your computer and use it in GitHub Desktop.
Save Dafrok/c1e9cd76c1abfbe40da0 to your computer and use it in GitHub Desktop.
Create Vue files.
var fs = require('fs')
var createVueFile = function (path, option) {
console.log('Creating vue files...')
var files = fs.readdirSync(path)
files.forEach(function (componentName) {
var componentPath = path + '/' + componentName;
var stats = fs.statSync(componentPath)
stats.isDirectory() && ~function () {
var vueFile = componentPath + '/' + componentName + '.vue'
var htmlLang = option.html ? 'lang="' + option.html + '"' : ''
var cssLang = option.css ? 'lang="' + option.css + '"' : ''
var scoped = option.scoped ? ' scoped' : ''
var isExist = fs.existsSync(vueFile)
;(option.rewrite || !isExist) && fs.writeFileSync(vueFile, '<template '
+ htmlLang + '>include '
+ componentName + '</template><style '
+ cssLang + scoped + '>@import "'
+ componentName + '"</style><script>import mod from "./'
+ componentName + '.js";export default mod;</script>')
}()
});
console.log('All vue files has been created.')
}
module.exports = createVueFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment