Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / grunt / bs-commonjs-generator.js
1 'use strict';
2 var fs = require('fs');
3 var path = require('path');
4
5 var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
6
7 module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
8   var destDir = path.dirname(destFilepath);
9
10   function srcPathToDestRequire(srcFilepath) {
11     var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
12     return 'require(\'' + requirePath + '\')';
13   }
14
15   var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
16   try {
17     fs.writeFileSync(destFilepath, moduleOutputJs);
18   }
19   catch (err) {
20     grunt.fail.warn(err);
21   }
22   grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
23 };