src_js/iconolab-bundle/move_dist.js
changeset 146 f912b591e1c1
child 150 c35816b65834
equal deleted inserted replaced
145:de5736883786 146:f912b591e1c1
       
     1 /* deplacer le build vers le dossier src/static */
       
     2 const fs = require('fs')
       
     3 const path = require('path')
       
     4 const ncp = require('ncp').ncp
       
     5 ncp.limit = 16;
       
     6 const rimraf = require('rimraf')
       
     7 const srcJsPath = path.dirname(__dirname)
       
     8 const iconolabSrcPath = path.join(srcJsPath,"..","src")
       
     9 const destJsDir = path.join(iconolabSrcPath, "iconolab", "static","iconolab", "js")
       
    10 const destCssDir = path.join(iconolabSrcPath,"iconolab", "static","iconolab", "css")
       
    11 
       
    12 
       
    13 
       
    14 var copyFile = function (src, dest, callback) {
       
    15 	try {
       
    16 		
       
    17 		fs.accessSync(src, fs.R_OK);
       
    18 		fs.accessSync(path.dirname(dest), fs.W_OK);
       
    19 		
       
    20 		// handler error
       
    21 		var errorHandler = function (e) {
       
    22 			callback(e);
       
    23 		}
       
    24 
       
    25 		var readStream = fs.createReadStream(src);
       
    26 
       
    27 		var writeStream = fs.createWriteStream(dest);
       
    28 
       
    29 		readStream.on("error", errorHandler);
       
    30 		writeStream.on("error", errorHandler);
       
    31 
       
    32 		readStream.on("data", function (chunk) {
       
    33 			writeStream.write(chunk);			
       
    34 		});
       
    35 
       
    36 		readStream.on("end", function () {
       
    37 			writeStream.close();
       
    38 		});
       
    39 
       
    40 	} catch (e) {
       
    41 		console.log(e);
       
    42 		if(typeof callback === "function") {
       
    43 			callback(e);
       
    44 		}
       
    45 	}
       
    46 }
       
    47 
       
    48 //move js
       
    49 copyFile(
       
    50 	path.join(srcJsPath, "iconolab-bundle", "dist", "build.js"), 
       
    51 	path.join(destJsDir, "build.js")
       
    52 	)
       
    53 
       
    54 
       
    55 const bootstrapPath = path.join(srcJsPath, "iconolab-bundle", "node_modules", "bootstrap", "dist", "css", "bootstrap.min.css");
       
    56 const fontAwesomeCssPath = path.join(srcJsPath, "iconolab-bundle", "node_modules", "font-awesome","css","font-awesome.min.css");
       
    57 const fontAwesomeDir = path.join(srcJsPath, "iconolab-bundle", "node_modules", "font-awesome");
       
    58 
       
    59 copyFile(bootstrapPath, path.join(destCssDir, "bootstrap.min.css"));
       
    60 
       
    61 
       
    62 /* delete font-awesome folder */
       
    63 rimraf(path.join(destCssDir,'font-awesome'), function (e) {
       
    64 		fs.access(path.join(destCssDir,'font-awesome'), fs.F_OK, function (hasError) {
       
    65 			if (hasError) {
       
    66 				fs.mkdir(path.join(destCssDir,'font-awesome'), function (hasError) {
       
    67 					if (!hasError) {
       
    68 						fs.mkdir(path.join(destCssDir,'font-awesome','css'), function (hasError) {
       
    69 							if (!hasError) {
       
    70 								copyFile(fontAwesomeCssPath, path.join(destCssDir, "font-awesome", "css", "font-awesome.min.css"));
       
    71 								ncp(path.join(fontAwesomeDir, "fonts"), path.join(destCssDir, "font-awesome", "fonts"));
       
    72 							}
       
    73 						})
       
    74 						
       
    75 					} else {
       
    76 						console.log(e);
       
    77 					}
       
    78 				});
       
    79 			} 
       
    80 		});
       
    81 });
       
    82 
       
    83 
       
    84