Guest User

Untitled

a guest
Mar 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/usr/bin/env node
  2. const path = require('path');
  3. const globby = require('globby');
  4. const fs = require('fs');
  5. const {promisify} = require('util');
  6. const readFile = promisify(fs.readFile);
  7. const appendFile = promisify(fs.appendFile);
  8.  
  9. /** bundles the files */
  10.  
  11. async function bundle() {
  12. /** gets the path of config file*/
  13. const configPath = path.join(process.cwd(), 'bundler.js');
  14. /** import the config file*/
  15. const config = require(configPath); // <-
  16. /** gets the list of filenames to bundle*/
  17. const files = await globby([config.src]);
  18. /** Iterates each file by their name */
  19. Promise.all(files.map(async (file) => {
  20. /** read the file in text formate */
  21. const fileContent = await readFile(file);
  22. /** add comment line in dist.js */
  23. await appendFile(path.join(process.cwd(), 'dist', 'dist.js'), `/** File Name: ${path.basename(file)}*/ \n`);
  24. /** append file content in dist.js */
  25. await appendFile(path.join(process.cwd(), 'dist', 'dist.js'), fileContent+'\n');
  26. }))
  27. }
  28.  
  29. bundle();
Add Comment
Please, Sign In to add comment