Last active
November 26, 2015 05:27
-
-
Save Dafrok/c1e9cd76c1abfbe40da0 to your computer and use it in GitHub Desktop.
Create Vue files.
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
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