source: imaps-frontend/node_modules/inline-style-prefixer/lib/generator/index.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.0 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
9exports.generateFile = generateFile;
10exports.default = generateData;
11
12var _generatePrefixMap = require('./generatePrefixMap');
13
14var _generatePrefixMap2 = _interopRequireDefault(_generatePrefixMap);
15
16var _generatePluginList = require('./generatePluginList');
17
18var _generatePluginList2 = _interopRequireDefault(_generatePluginList);
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22function generateImportString(plugin, compatibility) {
23 if (compatibility) {
24 return 'var ' + plugin + ' = require(\'inline-style-prefixer/lib/plugins/' + plugin + '\')';
25 }
26 return 'import ' + plugin + ' from \'inline-style-prefixer/lib/plugins/' + plugin + '\'';
27}
28
29function generateFile(prefixMap, pluginList, compatibility) {
30 var pluginImports = pluginList.map(function (plugin) {
31 return generateImportString(plugin, compatibility);
32 }).join('\n');
33
34 var moduleExporter = compatibility ? 'module.exports = ' : 'export default';
35 var pluginExport = '[' + pluginList.join(',') + ']';
36 var prefixMapExport = JSON.stringify(prefixMap);
37
38 var prefixVariables = ['var w = ["Webkit"];', 'var m = ["Moz"];', 'var ms = ["ms"];', 'var wm = ["Webkit","Moz"];', 'var wms = ["Webkit","ms"];', 'var wmms = ["Webkit","Moz","ms"];'].join('\n');
39
40 return pluginImports + '\n' + prefixVariables + '\n\n' + moduleExporter + ' {\n plugins: ' + pluginExport + ',\n prefixMap: ' + prefixMapExport.replace(/\["Webkit"\]/g, 'w').replace(/\["Moz"\]/g, 'm').replace(/\["ms"\]/g, 'ms').replace(/\["Webkit","Moz"\]/g, 'wm').replace(/\["Webkit","ms"\]/g, 'wms').replace(/\["Webkit","Moz","ms"\]/g, 'wmms') + '\n}';
41}
42
43function saveFile(fileContent, path) {
44 /* eslint-disable global-require */
45 var fs = require('fs');
46 /* eslint-enable global-require */
47
48 fs.writeFile(path, fileContent, function (err) {
49 if (err) {
50 throw err;
51 }
52
53 console.log('Successfully saved data to "' + path + '".');
54 });
55}
56
57var defaultOptions = {
58 prefixMap: true,
59 plugins: true,
60 compatibility: false
61};
62
63function generateData(browserList) {
64 var userOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
65
66 var options = _extends({}, defaultOptions, userOptions);
67
68 var compatibility = options.compatibility,
69 plugins = options.plugins,
70 path = options.path,
71 prefixMap = options.prefixMap;
72
73
74 var requiredPrefixMap = prefixMap ? (0, _generatePrefixMap2.default)(browserList) : {};
75 var requiredPlugins = plugins ? (0, _generatePluginList2.default)(browserList) : [];
76
77 if (path) {
78 saveFile(generateFile(requiredPrefixMap, requiredPlugins, compatibility), path);
79 }
80
81 return {
82 prefixMap: requiredPrefixMap,
83 plugins: requiredPlugins
84 };
85}
Note: See TracBrowser for help on using the repository browser.