Created
February 5, 2016 14:24
-
-
Save indiefolk/d1c8c8c1603510cc6a67 to your computer and use it in GitHub Desktop.
Node script to restructure app module 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
/** | |
* Node Generate Modules | |
* | |
* Node script to restructure app module files | |
* | |
* Move nested modules from individual project directories to a | |
* central modules directory shared by the app. | |
* | |
* Auto generate related module files - scss, html template, html demo page | |
*/ | |
var del = require('del'); | |
var dive = require('dive'); | |
var fs = require('fs-extra'); | |
// Delete target directory if already exists | |
del('./app/modules', function () { | |
fs.mkdirSync('./app/modules'); | |
dive('./app/section/modules/', { all: true }, function(err, file, stat) { | |
if (err) throw err; | |
console.log(file); | |
// Get filename by regex on path | |
var filename = file.match(/[^/]*(?=\.[^.]+($|\?))/)[0]; | |
var filenameWithExtension = file.match(/[^\/]+(?=\.*$)/)[0]; | |
// Create directory in modules directory | |
fs.mkdirSync('./app/modules/' + filename); | |
// Copy file to modules directory | |
fs.copySync(file, './app/modules/' + filename + '/' + filenameWithExtension); | |
// Create empty scss, template, index pages | |
fs.writeFileSync('./app/modules/' + filename + '/' + filename + '.scss', ''); | |
fs.writeFileSync('./app/modules/' + filename + '/' + filename + '.html', ''); | |
fs.writeFileSync('./app/modules/' + filename + '/' + 'index.html', ''); | |
}, function() { | |
console.log('complete'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment