@zohodesk/react-cli 0.0.1-test.148.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +7 -7
- package/.eslintrc.js +180 -183
- package/.prettierrc +6 -0
- package/{CHANGELOG.md → CHANGELOG-fz.md} +0 -0
- package/Changelog.md +1019 -0
- package/README.md +1152 -678
- package/bin/cli.js +483 -392
- package/docs/CustomChunks.md +26 -0
- package/docs/DevServerPort.md +39 -0
- package/docs/DevStart.md +18 -0
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/SelectorWeight.md +6 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/VariableConversion.md +724 -0
- package/docs/warnings_while_install.txt +35 -0
- package/files/eslintrc.js +62 -62
- package/files/prettierrc.js +3 -3
- package/lib/common/index.js +6 -6
- package/lib/common/splitChunks.js +60 -12
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/testPattern.js +69 -0
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +18 -8
- package/lib/configs/libAlias.js +38 -0
- package/lib/configs/resolvers.js +40 -0
- package/lib/configs/webpack.css.umd.config.js +4 -4
- package/lib/configs/webpack.dev.config.js +59 -54
- package/lib/configs/webpack.docs.config.js +56 -53
- package/lib/configs/webpack.impact.config.js +54 -50
- package/lib/configs/webpack.prod.config.js +72 -47
- package/lib/constants.js +31 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -7
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +89 -21
- package/lib/loaderUtils/index.js +4 -4
- package/lib/loaderUtils/windowsModification.js +11 -0
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/scriptInstrumentLoader.js +2 -2
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +9 -9
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +59 -0
- package/lib/pluginUtils/getDevPlugins.js +69 -45
- package/lib/pluginUtils/getDocsPlugins.js +6 -8
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getProdPlugins.js +73 -58
- package/lib/pluginUtils/index.js +12 -12
- package/lib/plugins/CdnChangePlugin.js +16 -2
- package/lib/plugins/EFCPlugin.js +52 -20
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +4 -4
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +38 -38
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +30 -30
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +8 -8
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -86
- package/lib/plugins/I18nSplitPlugin/README.md +25 -25
- package/lib/plugins/I18nSplitPlugin/index.js +57 -57
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +2 -2
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +1 -1
- package/lib/plugins/ManifestPlugin.js +8 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +17 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +11 -7
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/SelectorPlugin.js +97 -0
- package/lib/plugins/ServiceWorkerPlugin.js +13 -9
- package/lib/plugins/SourceMapHookPlugin.js +9 -3
- package/lib/plugins/TPHashMappingPlugin.js +4 -4
- package/lib/plugins/VariableConversionCollector.js +352 -0
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +36 -36
- package/lib/plugins/libraryImpactPlugin.js +14 -2
- package/lib/postcss-plugins/{ExcludeRTLPlugin.js → ExcludePlugin.js} +1 -1
- package/lib/postcss-plugins/RTLSplitPlugin.js +36 -32
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
- package/lib/postcss-plugins/__test__/test1Input.css +39 -0
- package/lib/postcss-plugins/__test__/test1Output.css +39 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +389 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +60 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +307 -0
- package/lib/postcss-plugins/variableModifier.js +244 -0
- package/lib/schemas/index.js +166 -11
- package/lib/servers/devBuild.js +102 -0
- package/lib/servers/docsServerCore.js +16 -18
- package/lib/servers/getCliPath.js +28 -0
- package/lib/servers/httpsOptions.js +49 -0
- package/lib/servers/nowatchserver.js +206 -0
- package/lib/servers/server.js +114 -82
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -45
- package/lib/templates/linterConstant.js +1 -1
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/cssClassNameGenerate.js +9 -2
- package/lib/utils/cssURLReplacer.js +30 -43
- package/lib/utils/getCurrentBranch.js +1 -1
- package/lib/utils/getDependenciesImpactList.js +14 -12
- package/lib/utils/getFileType.js +49 -0
- package/lib/utils/getOptions.js +118 -10
- package/lib/utils/index.js +44 -20
- package/lib/utils/jsonHelper.js +12 -3
- package/lib/utils/reinstallDependencies.js +1 -1
- package/lib/utils/repoClone.js +16 -4
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +19 -2
- package/lib/utils/useExitCleanup.js +55 -0
- package/npm8.md +9 -0
- package/package.json +121 -142
- package/postpublish.js +8 -0
- package/result.json +1 -0
- package/templates/app/.eslintrc.js +140 -140
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -24
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -18
- package/templates/app/package.json +37 -37
- package/templates/app/src/actions/SampleActions/index.js +37 -37
- package/templates/app/src/actions/index.js +65 -65
- package/templates/app/src/appUrls.js +19 -19
- package/templates/app/src/components/Alert/Alert.js +134 -134
- package/templates/app/src/components/Alert/Alert.module.css +79 -79
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
- package/templates/app/src/components/Sample/Sample.module.css +11 -11
- package/templates/app/src/components/Sample/SampleList.js +61 -61
- package/templates/app/src/components/Slider/Slider.css +41 -41
- package/templates/app/src/components/Slider/Slider.js +55 -55
- package/templates/app/src/containers/AlertContainer/index.js +15 -15
- package/templates/app/src/containers/AppContainer/index.js +96 -96
- package/templates/app/src/containers/AppContainer/index.module.css +27 -27
- package/templates/app/src/containers/CustomMatch/index.js +65 -65
- package/templates/app/src/containers/DevTools/index.js +10 -10
- package/templates/app/src/containers/Header/index.js +67 -67
- package/templates/app/src/containers/Header/index.module.css +43 -43
- package/templates/app/src/containers/Redirect/index.js +63 -63
- package/templates/app/src/containers/Redirector/index.js +47 -47
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
- package/templates/app/src/historyChange.js +5 -5
- package/templates/app/src/index.html +10 -10
- package/templates/app/src/index.js +24 -24
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
- package/templates/app/src/reducers/alertData.js +11 -11
- package/templates/app/src/reducers/index.js +6 -6
- package/templates/app/src/reducers/samples.js +19 -19
- package/templates/app/src/store/configureStore.dev.js +51 -51
- package/templates/app/src/store/configureStore.js +5 -5
- package/templates/app/src/store/configureStore.prod.js +26 -26
- package/templates/app/src/util/Common.js +5 -5
- package/templates/app/src/util/RequestAPI.js +132 -132
- package/templates/docs/all.html +249 -249
- package/templates/docs/component.html +178 -178
- package/templates/docs/components.html +221 -221
- package/templates/docs/css/b.min.css +6 -6
- package/templates/docs/css/component.css +42 -42
- package/templates/docs/css/componentTest.css +6 -6
- package/templates/docs/css/hopscotch.css +585 -585
- package/templates/docs/css/style.css +1022 -1022
- package/templates/docs/impactReportTemplate.html +154 -154
- package/templates/docs/index.html +1501 -1493
- package/templates/docs/js/active-line.js +72 -72
- package/templates/docs/js/b.min.js +7 -7
- package/templates/docs/js/codemirror.js +9680 -9680
- package/templates/docs/js/designTokens.js +334 -334
- package/templates/docs/js/j.min.js +4 -4
- package/templates/docs/js/javascript.js +874 -874
- package/templates/docs/js/matchbrackets.js +145 -145
- package/unittest/index.html +37 -0
- package/cert/cert.pem +0 -105
- package/cert/key.pem +0 -30
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
+
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
+
|
|
12
|
+
var _webpackSources = require("webpack-sources");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const isCss = filename => path.extname(filename) === '.css';
|
|
19
|
+
|
|
20
|
+
function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings) {
|
|
21
|
+
rootOriginal.walkRules((rule, index) => {
|
|
22
|
+
const prevNode = rootOriginal.nodes[index - 1];
|
|
23
|
+
|
|
24
|
+
if (index !== 0 && prevNode.type && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'updateselector:ignore') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (rule.parent && rule.parent.type === 'atrule') {
|
|
29
|
+
if (rule.parent.name !== 'media') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (excludeStrings.includes(rule.selector)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let ruleArr = rule.selector.split(',');
|
|
39
|
+
ruleArr.forEach((rule, index) => {
|
|
40
|
+
if (rule.includes(']')) {
|
|
41
|
+
if (rule.slice(rule.lastIndexOf(']') + 2).trim() === '') {
|
|
42
|
+
return;
|
|
43
|
+
} // console.log(
|
|
44
|
+
// rule.slice(rule.lastIndexOf(']') + 2).trim(),
|
|
45
|
+
// rule.slice(rule.lastIndexOf(']') + 2).trim() !== ''
|
|
46
|
+
// );
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
ruleArr[index] = `${rule.slice(0, rule.lastIndexOf(']') + 1).trim()} ${defaultSelector}${rule.slice(rule.lastIndexOf(']') + 2).trim()}`; // console.log(ruleArr[index]);
|
|
50
|
+
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ruleArr[index] = data[chunkFilename] ? `${data[chunkFilename].defaultSelector}${rule}` : `${defaultSelector}${rule}`;
|
|
55
|
+
});
|
|
56
|
+
rule.selector = ruleArr.join(',\n'); // console.log(`${rule.selector} converted`);
|
|
57
|
+
});
|
|
58
|
+
return rootOriginal;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class SelectorPlugin {
|
|
62
|
+
constructor(options = {}) {
|
|
63
|
+
this.optimize = options.optimize;
|
|
64
|
+
this.selectorWeightConfig = options.selectorWeightConfig;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
apply(compiler) {
|
|
68
|
+
const {
|
|
69
|
+
defaultSelector,
|
|
70
|
+
customFileDetails,
|
|
71
|
+
excludeStrings
|
|
72
|
+
} = this.selectorWeightConfig;
|
|
73
|
+
|
|
74
|
+
const rawdata = _fs.default.readFileSync(customFileDetails);
|
|
75
|
+
|
|
76
|
+
const data = JSON.parse(rawdata);
|
|
77
|
+
compiler.hooks.compilation.tap('selector-weight-rewrite', compilation => {
|
|
78
|
+
compilation.hooks.optimizeChunkAssets.tapAsync('selector-weight-rewrite', (chunks, callback) => {
|
|
79
|
+
chunks.forEach(chunk => {
|
|
80
|
+
chunk.files.filter(isCss).forEach(chunkFilename => {
|
|
81
|
+
const asset = compilation.assets[chunkFilename];
|
|
82
|
+
const sourceStr = asset.source();
|
|
83
|
+
|
|
84
|
+
const rootOriginal = _postcss.default.parse(sourceStr);
|
|
85
|
+
|
|
86
|
+
compilation.assets[chunkFilename] = new _webpackSources.RawSource(rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings).toString());
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
callback();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var _default = SelectorPlugin;
|
|
97
|
+
exports.default = _default;
|
|
@@ -51,11 +51,11 @@ class ServiceWorkerPlugin {
|
|
|
51
51
|
if (err) {
|
|
52
52
|
throw new Error(err);
|
|
53
53
|
} else {
|
|
54
|
-
/* const extractedChunks = compilation.chunks.filter(chunk => {
|
|
55
|
-
if ('canBeInitial' in chunk) {
|
|
56
|
-
return chunk.canBeInitial();
|
|
57
|
-
}
|
|
58
|
-
return chunk.isInitial();
|
|
54
|
+
/* const extractedChunks = compilation.chunks.filter(chunk => {
|
|
55
|
+
if ('canBeInitial' in chunk) {
|
|
56
|
+
return chunk.canBeInitial();
|
|
57
|
+
}
|
|
58
|
+
return chunk.isInitial();
|
|
59
59
|
}); */
|
|
60
60
|
// let [js, css, , , i18nPublicPath] = this.publicPaths;
|
|
61
61
|
// let initialChunkUrls = [];
|
|
@@ -64,10 +64,10 @@ class ServiceWorkerPlugin {
|
|
|
64
64
|
let entrypoint = compilation.entrypoints.get('main');
|
|
65
65
|
let initialChunkUrls = entrypoint.getFiles();
|
|
66
66
|
const cssDirTemplate = '@dir@';
|
|
67
|
-
/**
|
|
68
|
-
* NOTE:
|
|
69
|
-
* if chunkSplitEnable is false means,
|
|
70
|
-
* serviceWorker will get i18n files path for html
|
|
67
|
+
/**
|
|
68
|
+
* NOTE:
|
|
69
|
+
* if chunkSplitEnable is false means,
|
|
70
|
+
* serviceWorker will get i18n files path for html
|
|
71
71
|
*/
|
|
72
72
|
|
|
73
73
|
let initalI18nAssets = chunkSplitEnable ? entrypoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@')) : [];
|
|
@@ -76,6 +76,10 @@ class ServiceWorkerPlugin {
|
|
|
76
76
|
allChunkUrls = allChunkUrls.concat(chunk.files);
|
|
77
77
|
allI18nAssets.push((0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
|
78
78
|
});
|
|
79
|
+
/** Removing source map files from getting added */
|
|
80
|
+
|
|
81
|
+
initialChunkUrls = initialChunkUrls.filter(fileName => !fileName.endsWith('.map'));
|
|
82
|
+
allChunkUrls = allChunkUrls.filter(fileName => !fileName.endsWith('.map'));
|
|
79
83
|
|
|
80
84
|
if (enableRTLSplit) {
|
|
81
85
|
initialChunkUrls = (0, _replaceCssDirTemplate.replaceCssDirTemplateMapper)(initialChunkUrls, cssDirTemplate);
|
|
@@ -15,15 +15,21 @@ class SourceMapHookPlugin {
|
|
|
15
15
|
apply(compiler) {
|
|
16
16
|
compiler.hooks.emit.tap('SourceMapHookPlugin', compilation => {
|
|
17
17
|
Object.keys(compilation.assets).forEach(filename => {
|
|
18
|
-
if (/\.js$/g.test(filename)) {
|
|
18
|
+
if (/\.js$/g.test(filename) && !/(\.map.|tp\/)/g.test(filename)) {
|
|
19
19
|
let source = compilation.assets[filename].source();
|
|
20
20
|
|
|
21
21
|
let {
|
|
22
22
|
name
|
|
23
23
|
} = _path.default.parse(filename);
|
|
24
24
|
|
|
25
|
-
let src =
|
|
26
|
-
|
|
25
|
+
let src = source;
|
|
26
|
+
|
|
27
|
+
if (!/(i18n-chunk\/)/g.test(filename)) {
|
|
28
|
+
src = `${source}\n//# sourceMappingURL=../../js/${name}.js.map`;
|
|
29
|
+
compilation.assets[filename.replace(/js\//g, 'smap/js/')] = new _webpackSources.RawSource(src);
|
|
30
|
+
} else {
|
|
31
|
+
compilation.assets[filename.replace(/i18n-chunk\//g, 'smap/i18n-chunk/')] = new _webpackSources.RawSource(src);
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
});
|
|
29
35
|
});
|
|
@@ -15,10 +15,10 @@ var _crypto = _interopRequireDefault(require("crypto"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Plugin that generates hash for the provided list of third party files
|
|
20
|
-
* Map the provided key with the file hash and add it to the list of exisiting global constants.
|
|
21
|
-
* Plugin in turn uses the defineplugin to generate global constants.
|
|
18
|
+
/**
|
|
19
|
+
* Plugin that generates hash for the provided list of third party files
|
|
20
|
+
* Map the provided key with the file hash and add it to the list of exisiting global constants.
|
|
21
|
+
* Plugin in turn uses the defineplugin to generate global constants.
|
|
22
22
|
*/
|
|
23
23
|
class TPHashMappingPlugin {
|
|
24
24
|
constructor(options) {
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
+
|
|
10
|
+
var _ErrorHandler = require("../postcss-plugins/variableModificationPlugin/ErrorHandler");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
// import { RawSource } from 'webpack-sources';
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
|
|
17
|
+
const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
|
18
|
+
let variablesRead = {};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
errors,
|
|
22
|
+
errTable,
|
|
23
|
+
errHandler
|
|
24
|
+
} = require('../postcss-plugins/variableModificationPlugin/index');
|
|
25
|
+
|
|
26
|
+
const supportedProps = ['font-size', 'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', '^top', '^right', '^bottom', '^left', '^width', 'min-width', 'max-width', '^height', 'min-height', 'max-height', 'text-indent', 'clip', 'flex-basis', 'row-gap', 'gap', 'column-gap', 'flex']; // const avoidProps = [];
|
|
27
|
+
// -- is issue IO --
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
issues eg :
|
|
31
|
+
issues = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
|
32
|
+
input :
|
|
33
|
+
--zd_size
|
|
34
|
+
output :
|
|
35
|
+
true
|
|
36
|
+
comment :
|
|
37
|
+
do not execute when --zd_size comes as prop
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
function isIgnoreValuePresent(ignoreVals, prop) {
|
|
41
|
+
let present = false;
|
|
42
|
+
ignoreVals.forEach(issue => {
|
|
43
|
+
if (prop && prop.includes(issue)) {
|
|
44
|
+
present = true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return present;
|
|
48
|
+
} // -- to convert the hyphen values to values --
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
input :
|
|
52
|
+
var(--zdt_uploadlist_default_width)
|
|
53
|
+
output :
|
|
54
|
+
--zdt_uploadlist_default_width
|
|
55
|
+
|
|
56
|
+
comment :
|
|
57
|
+
to make the variable object using the output as key and decl.prop such as font-size as value
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function extractVariableName(val) {
|
|
62
|
+
return val.replace(/calc\((.+)\)/gi, '$1').replace(/var\((.+)\)/gi, '$1').replace('-1', '').replace('*', '').replace('\n', '').trim();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function rootConvertor(rootOriginal, variables, settingsObject) {
|
|
66
|
+
rootOriginal.walkRules(rule => {
|
|
67
|
+
rule.nodes.forEach((decl, index) => {
|
|
68
|
+
const prevNode = rule.nodes[index - 1];
|
|
69
|
+
const currentNode = rule.nodes[index];
|
|
70
|
+
|
|
71
|
+
if (decl.prop && decl.prop.includes('--')) {
|
|
72
|
+
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'variable:ignore') {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isIgnoreValuePresent(ignoreVals, decl.prop)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (settingsObject[variables[decl.prop]]) {
|
|
81
|
+
/* if there is no value for property, set it to default so that undefined doesn't get called as key */
|
|
82
|
+
if (!variables[decl.prop]) {
|
|
83
|
+
variables[decl.prop] = 'default';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
|
87
|
+
const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
|
|
88
|
+
|
|
89
|
+
valArr.forEach((value, index) => {
|
|
90
|
+
if (value.includes('px')) {
|
|
91
|
+
const num = value.replace('px', '');
|
|
92
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
currentNode.value = valArr.join(' ');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return rootOriginal;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function createFolderIfNonExistant(path) {
|
|
104
|
+
if (!fs.existsSync(path)) {
|
|
105
|
+
fs.mkdirSync(path, {
|
|
106
|
+
recursive: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createFileIfNonExistant(path, content) {
|
|
112
|
+
if (fs.existsSync(path)) {
|
|
113
|
+
fs.writeFileSync(path, content, 'utf-8');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class VariableConversionCollector {
|
|
118
|
+
constructor(options = {}) {
|
|
119
|
+
this.optimize = options.optimize;
|
|
120
|
+
this.filename = options.cssVariableReplacementConfig;
|
|
121
|
+
this.fileHandler();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fileHandler() {
|
|
125
|
+
createFolderIfNonExistant('./.cli/logs/');
|
|
126
|
+
createFolderIfNonExistant('./.cli/config/variables/');
|
|
127
|
+
createFolderIfNonExistant('./.cli/config/selectorWeight/');
|
|
128
|
+
createFileIfNonExistant('./.cli/logs/unassignedVariables.log', '{}');
|
|
129
|
+
createFileIfNonExistant('./.cli/logs/css_error.log', '{}');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
apply(compiler) {
|
|
133
|
+
const variables = {};
|
|
134
|
+
const unassigned = {};
|
|
135
|
+
const rawdata = fs.readFileSync(this.filename);
|
|
136
|
+
const data = JSON.parse(rawdata);
|
|
137
|
+
const {
|
|
138
|
+
settings: settingsObject,
|
|
139
|
+
errorLog: errorLogStatus,
|
|
140
|
+
errorInConsole: errorConsoleStatus,
|
|
141
|
+
errorsAllowed,
|
|
142
|
+
strictMode
|
|
143
|
+
} = data; // If theres is no setting for default prop in settingsObject, set one.
|
|
144
|
+
|
|
145
|
+
if (!settingsObject.default) {
|
|
146
|
+
settingsObject.default = {
|
|
147
|
+
allowed: ['px', 'em', 'fit-content', 'auto', '%', 'inherit', '-moz-fit-content', 'vh', '0', 'initial', 'vw'],
|
|
148
|
+
replacements: {
|
|
149
|
+
px: 'var(--zd_size$$)'
|
|
150
|
+
},
|
|
151
|
+
range: {
|
|
152
|
+
start: -99999,
|
|
153
|
+
end: 99999
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/*
|
|
158
|
+
purpose of tap : to create a variable object such as:
|
|
159
|
+
{
|
|
160
|
+
--zdt_uploadlist_default_width : width,
|
|
161
|
+
--zdt_uploadlist_default_height : height,
|
|
162
|
+
}
|
|
163
|
+
which will help in the conversion further
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if (fs.existsSync('./.cli/config/variables/variableMapping.json')) {
|
|
168
|
+
variablesRead = JSON.parse(fs.readFileSync('./.cli/config/variables/variableMapping.json', 'utf-8'));
|
|
169
|
+
Object.keys(variablesRead.changes).forEach(key => {
|
|
170
|
+
variables[key] = variablesRead.changes[key];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
compiler.hooks.compilation.tap('VariableConversionCollector', compilation => {
|
|
175
|
+
compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
|
|
176
|
+
const mods = modules.filter(x => x.type.includes('css'));
|
|
177
|
+
mods.forEach(module => {
|
|
178
|
+
const rootOriginal = _postcss.default.parse(module.content);
|
|
179
|
+
|
|
180
|
+
const filename = module.issuer.resource;
|
|
181
|
+
|
|
182
|
+
if (!filename.includes('node_modules')) {
|
|
183
|
+
rootOriginal.walkRules(rule => {
|
|
184
|
+
rule.walkDecls(decl => {
|
|
185
|
+
decl.value.split(' ').forEach(val => {
|
|
186
|
+
if (val && val.includes('--') && !new RegExp(ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
|
|
187
|
+
const extractedValue = extractVariableName(val);
|
|
188
|
+
|
|
189
|
+
if (!variables[extractedValue]) {
|
|
190
|
+
variables[extractedValue] = decl.prop;
|
|
191
|
+
} else {
|
|
192
|
+
if (new RegExp(supportedProps.join('|'), 'gi').test(decl.prop)) {
|
|
193
|
+
// console.log(
|
|
194
|
+
// `${extractedValue} : ${variables[extractedValue]} already exists please check!`
|
|
195
|
+
// );
|
|
196
|
+
if (errorsAllowed.MULTIPLE_OCCURANCES) {
|
|
197
|
+
const errObj = {
|
|
198
|
+
decl,
|
|
199
|
+
type: 'MULTIPLE_OCCURANCES',
|
|
200
|
+
filename,
|
|
201
|
+
message: `${extractedValue} : ${variables[extractedValue]} already exists please check!`
|
|
202
|
+
};
|
|
203
|
+
errHandler.errorTable.push(errObj);
|
|
204
|
+
errHandler.errorFunction(errObj);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
// console.log(decl.prop);
|
|
210
|
+
if (/^--/gi.test(decl.prop) && val.trim() !== '' && !variables[decl.prop]) {
|
|
211
|
+
if (!Object.keys(variablesRead.ignore).includes(decl.prop)) {
|
|
212
|
+
unassigned[decl.prop] = variables[decl.prop];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
/*
|
|
220
|
+
current value example:
|
|
221
|
+
{
|
|
222
|
+
--zdt_uploadlist_default_width : --zd_upload_width,
|
|
223
|
+
--zd_upload_width : width
|
|
224
|
+
}
|
|
225
|
+
expected value :
|
|
226
|
+
{
|
|
227
|
+
--zdt_uploadlist_default_width : width,
|
|
228
|
+
--zd_upload_width : width
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
conversion is done in the while loop below
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
Object.keys(variables).forEach(key => {
|
|
235
|
+
while (variables[variables[key]]) {
|
|
236
|
+
variables[key] = variables[variables[key]];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}); // -- conversion for the root using rootConvertor --
|
|
242
|
+
|
|
243
|
+
/*
|
|
244
|
+
input :
|
|
245
|
+
.a{
|
|
246
|
+
padding : 20px
|
|
247
|
+
}
|
|
248
|
+
output :
|
|
249
|
+
// on settingObject file :
|
|
250
|
+
{ padding : { replacements : { px : 'zd_size$$' }}}
|
|
251
|
+
.a{
|
|
252
|
+
padding : zd_size20;
|
|
253
|
+
}
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
|
|
257
|
+
const mods = modules.filter(x => x.type.includes('css'));
|
|
258
|
+
mods.forEach(module => {
|
|
259
|
+
const rootOriginal = _postcss.default.parse(module.content);
|
|
260
|
+
|
|
261
|
+
module.content = rootConvertor(rootOriginal, variables, settingsObject).toString();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
/*
|
|
266
|
+
purpose of tap : to display the errors encountered so far
|
|
267
|
+
input :
|
|
268
|
+
all css files
|
|
269
|
+
output :
|
|
270
|
+
all errors that are present in the errTable arr
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
compiler.hooks.afterEmit.tap('error-display', () => {
|
|
274
|
+
if (Object.keys(unassigned).length > 0 && strictMode) {
|
|
275
|
+
console.log();
|
|
276
|
+
console.log(unassigned);
|
|
277
|
+
console.log();
|
|
278
|
+
let str = '{\n';
|
|
279
|
+
Object.keys(unassigned).forEach(key => {
|
|
280
|
+
str += `"${key}" : "${unassigned[key]}",\n`;
|
|
281
|
+
});
|
|
282
|
+
str += '}';
|
|
283
|
+
fs.writeFileSync('./.cli/logs/unassignedVariables.log', str, 'utf-8');
|
|
284
|
+
throw new Error('^^^ Variables above have not been assigned! ^^^');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const avlTypes = new Set([]);
|
|
288
|
+
const srtArr = errTable.sort((a, b) => {
|
|
289
|
+
avlTypes.add(a.type);
|
|
290
|
+
avlTypes.add(b.type);
|
|
291
|
+
|
|
292
|
+
if (a.type < b.type) {
|
|
293
|
+
return -1;
|
|
294
|
+
}
|
|
295
|
+
}); // variable constructed now to be written in a json file
|
|
296
|
+
// const newVars = Object.keys(variables)
|
|
297
|
+
// //Filter Object with key contanis "NAME"
|
|
298
|
+
// .filter(key => variables[key].includes('--'))
|
|
299
|
+
// .reduce(
|
|
300
|
+
// (obj, key) =>
|
|
301
|
+
// Object.assign(obj, {
|
|
302
|
+
// [key]: variables[key]
|
|
303
|
+
// }),
|
|
304
|
+
// {}
|
|
305
|
+
// );
|
|
306
|
+
// console.log('new variables: ', newVars);
|
|
307
|
+
// try {
|
|
308
|
+
// fs.writeFileSync('./variableMapping.json', JSON.stringify(variables));
|
|
309
|
+
// } catch (err) {
|
|
310
|
+
// console.log(err);
|
|
311
|
+
// }
|
|
312
|
+
// fs.writeFile('./variableMapping.json', JSON.stringify(variables), err => {
|
|
313
|
+
// if (err) {
|
|
314
|
+
// throw err;
|
|
315
|
+
// }
|
|
316
|
+
// console.log('variable mapping file generated.');
|
|
317
|
+
// });
|
|
318
|
+
|
|
319
|
+
if (errorConsoleStatus) {
|
|
320
|
+
const errorHandler = new _ErrorHandler.ErrorHandler();
|
|
321
|
+
avlTypes.forEach(type => {
|
|
322
|
+
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
|
323
|
+
console.log(`Error Type : ${type}`);
|
|
324
|
+
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
|
325
|
+
srtArr.forEach(err => {
|
|
326
|
+
if (err.decl.prop && err.decl.value && err.type === type) {
|
|
327
|
+
errorHandler.printError(err);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (errorLogStatus) {
|
|
335
|
+
fs.writeFileSync('./.cli/logs/css_error.log', '');
|
|
336
|
+
console.log('writing to logFile...');
|
|
337
|
+
|
|
338
|
+
if (errors.length > 0) {
|
|
339
|
+
errors.forEach((err, index) => {
|
|
340
|
+
if (errTable[index].decl.prop && errTable[index].decl.value) {
|
|
341
|
+
fs.appendFileSync('./.cli/logs/css_error.log', err);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
var _default = VariableConversionCollector;
|
|
352
|
+
exports.default = _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
class ComposeCommonPlugin {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.optimize = options.optimize;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
|
|
19
|
+
compilation.hooks.optimizeModules.tap('OptimizeMods', modules => {
|
|
20
|
+
modules.forEach(module => {
|
|
21
|
+
console.log(module);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var _default = ComposeCommonPlugin;
|
|
30
|
+
exports.default = _default;
|