@zohodesk/react-cli 0.0.1-beta.16 → 0.0.1-beta.162
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 +1 -0
- package/.eslintrc.js +46 -3
- package/CHANGELOG.md +5 -0
- package/README.md +708 -0
- package/bin/cli.js +134 -27
- package/cert/cert.pem +37 -129
- package/cert/key.pem +27 -27
- package/cert/passphrase.pem +1 -0
- package/files/eslintrc.js +62 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +33 -24
- package/lib/common/getPublicPathConfig.js +40 -0
- package/lib/common/index.js +27 -13
- package/lib/common/splitChunks.js +64 -26
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/templateParameters.js +25 -0
- package/lib/configs/jest.config.js +26 -27
- package/lib/configs/libAlias.js +31 -0
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -44
- package/lib/configs/webpack.dev.config.js +96 -56
- package/lib/configs/webpack.docs.config.js +104 -98
- package/lib/configs/webpack.impact.config.js +116 -0
- package/lib/configs/webpack.prod.config.js +137 -85
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +144 -71
- package/lib/jest/coverageCollector.js +62 -29
- package/lib/jest/jsonMaker.js +54 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +91 -41
- package/lib/jest/run.js +74 -27
- package/lib/jest/setup.js +103 -102
- package/lib/loaderUtils/getCSSLoaders.js +77 -0
- package/lib/loaderUtils/getDevJsLoaders.js +30 -23
- package/lib/loaderUtils/index.js +14 -7
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/fileLoader.js +47 -38
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +59 -41
- package/lib/middlewares/SSTMiddleware.js +21 -0
- package/lib/pluginUtils/getDevPlugins.js +175 -26
- package/lib/pluginUtils/getDocsPlugins.js +32 -17
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +240 -37
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +77 -0
- package/lib/plugins/CleanupStatsPlugin.js +28 -0
- package/lib/plugins/EFCPlugin.js +241 -0
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +59 -62
- package/lib/plugins/ModuleStatsPlugin.js +98 -97
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
- package/lib/plugins/PublicPathChangePlugin.js +187 -174
- package/lib/plugins/ReportGeneratePlugin.js +181 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +107 -0
- package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
- package/lib/plugins/SourceMapHookPlugin.js +25 -31
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
- package/lib/plugins/index.js +118 -55
- package/lib/plugins/libraryImpactPlugin.js +190 -0
- package/lib/plugins/webpackwatchrunplugin.js +26 -0
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
- package/lib/schemas/index.js +466 -52
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +93 -85
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/httpsOptions.js +19 -0
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +44 -0
- package/lib/servers/nowatchserver.js +275 -0
- package/lib/servers/scrServer.js +147 -0
- package/lib/servers/server.js +118 -124
- package/lib/servers/ssServer.js +107 -65
- package/lib/sh/reportPublish.sh +16 -10
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +10 -0
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/buildstats.html +148 -0
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +13 -127
- package/lib/utils/copyTimezones.js +21 -0
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +77 -0
- package/lib/utils/cssURLReplacer.js +67 -54
- package/lib/utils/dependencyPostPublish.js +42 -0
- package/lib/utils/fileUtils.js +125 -0
- package/lib/utils/folderIterator.js +47 -0
- package/lib/utils/getComponents.js +126 -0
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +151 -0
- package/lib/utils/getHash.js +26 -0
- package/lib/utils/getIp.js +20 -0
- package/lib/utils/getOptions.js +55 -30
- package/lib/utils/getServerURL.js +25 -8
- package/lib/utils/index.js +259 -82
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -31
- package/lib/utils/jsonHelper.js +97 -0
- package/lib/utils/libraryImpactConfig.js +63 -0
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +142 -0
- package/lib/utils/mailSender.js +16 -25
- package/lib/utils/pullOrigin.js +28 -0
- package/lib/utils/reinstallDependencies.js +133 -0
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +56 -63
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -0
- package/lib/utils/rtl.js +42 -0
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +48 -0
- package/lib/utils/switchBranch.js +28 -0
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +92 -64
- package/templates/app/.eslintrc.js +140 -0
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -8
- 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 -13
- package/templates/app/package.json +37 -17
- package/templates/app/src/actions/SampleActions/index.js +37 -0
- package/templates/app/src/actions/index.js +65 -0
- package/templates/app/src/appUrls.js +19 -0
- package/templates/app/src/components/Alert/Alert.js +134 -0
- package/templates/app/src/components/Alert/Alert.module.css +79 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
- package/templates/app/src/components/Sample/Sample.module.css +11 -0
- package/templates/app/src/components/Sample/SampleList.js +61 -0
- package/templates/app/src/components/Slider/Slider.css +41 -0
- package/templates/app/src/components/Slider/Slider.js +55 -0
- package/templates/app/src/containers/AlertContainer/index.js +15 -0
- package/templates/app/src/containers/AppContainer/index.js +96 -0
- package/templates/app/src/containers/AppContainer/index.module.css +27 -0
- package/templates/app/src/containers/CustomMatch/index.js +65 -0
- package/templates/app/src/containers/DevTools/index.js +10 -0
- package/templates/app/src/containers/Header/index.js +67 -0
- package/templates/app/src/containers/Header/index.module.css +43 -0
- package/templates/app/src/containers/Redirect/index.js +63 -0
- package/templates/app/src/containers/Redirector/index.js +47 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
- package/templates/app/src/historyChange.js +5 -0
- package/templates/app/src/index.html +10 -0
- package/templates/app/src/index.js +24 -0
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
- package/templates/app/src/reducers/alertData.js +11 -0
- package/templates/app/src/reducers/index.js +6 -0
- package/templates/app/src/reducers/samples.js +19 -0
- package/templates/app/src/store/configureStore.dev.js +51 -0
- package/templates/app/src/store/configureStore.js +5 -0
- package/templates/app/src/store/configureStore.prod.js +26 -0
- package/templates/app/src/util/Common.js +5 -0
- package/templates/app/src/util/RequestAPI.js +132 -0
- package/templates/appold/README.md +12 -0
- package/templates/appold/app/index.html +8 -0
- package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
- package/templates/appold/app/properties/i18nkeys.json +3 -0
- package/templates/appold/docs/all.html +69 -0
- package/templates/appold/mockapi/index.js +13 -0
- package/templates/{app → appold}/mockapi/tickets.json +0 -0
- package/templates/appold/package.json +17 -0
- package/templates/appold/src/components/Text/Text.css +0 -0
- package/templates/appold/src/components/Text/Text.js +23 -0
- package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
- package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
- package/templates/appold/src/components/docs.js +1 -0
- package/templates/appold/src/components/index.js +5 -0
- package/templates/appold/src/index.js +13 -0
- package/templates/docs/all.html +1 -1
- package/templates/docs/component.html +110 -69
- package/templates/docs/components.html +221 -0
- package/templates/docs/css/component.css +12 -14
- package/templates/docs/css/componentTest.css +7 -0
- package/templates/docs/css/style.css +150 -206
- package/templates/docs/impactReportTemplate.html +154 -0
- package/templates/docs/index.html +1482 -1336
- package/templates/library/src/index.js +0 -0
@@ -0,0 +1,241 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _webpackSources = require("webpack-sources");
|
9
|
+
|
10
|
+
var _utils = require("../utils");
|
11
|
+
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
13
|
+
|
14
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
15
|
+
|
16
|
+
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
|
17
|
+
|
18
|
+
var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
19
|
+
|
20
|
+
var _EFCTemplatePlugin = _interopRequireDefault(require("./EFCTemplatePlugin"));
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
25
|
+
const cliOptions = (0, _utils.getOptions)();
|
26
|
+
const {
|
27
|
+
app: {
|
28
|
+
publicPaths
|
29
|
+
},
|
30
|
+
i18n: {
|
31
|
+
chunkSplitEnable
|
32
|
+
},
|
33
|
+
css: {
|
34
|
+
enableRTLSplit
|
35
|
+
},
|
36
|
+
efc: efcOptios
|
37
|
+
} = cliOptions;
|
38
|
+
const {
|
39
|
+
createSDkFile,
|
40
|
+
cdnStatement
|
41
|
+
} = efcOptios;
|
42
|
+
|
43
|
+
class EFCPlugin {
|
44
|
+
constructor(options = {}) {
|
45
|
+
this.isDevelopment = options.isDevelopment;
|
46
|
+
this.templateFilePath = options.templateFilePath;
|
47
|
+
this.serverUrl = options.serverUrl;
|
48
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
49
|
+
// this.i18nManifestFileName = options.i18nManifestFileName;
|
50
|
+
// IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
|
51
|
+
// So when debugging consider this as well
|
52
|
+
|
53
|
+
this.options = Object.assign({}, efcOptios, options);
|
54
|
+
this.options.entryPointName = options.entryPointName || 'efc';
|
55
|
+
this.options.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
|
56
|
+
this.options.nameScope = options.nameScope || 'EFComponents';
|
57
|
+
const localeAttr = this.options.localeAttr || 'data-efc-locale';
|
58
|
+
const cssDirAttr = this.options.cssDirAttr || 'data-efc-dir';
|
59
|
+
const localeDefaultValue = this.options.localeDefaultValue || 'en_US';
|
60
|
+
const cssDirDefaultValue = this.options.cssDirDefaultValue || 'ltr';
|
61
|
+
this.options.localeStatement = options.localeStatement || // Statment 1: return langEle && langEle.getAttribute('${localeAttr}') || 'en_US';
|
62
|
+
// Statment 2: return langEle ? langEle.getAttribute('${localeAttr}') : 'en_US';
|
63
|
+
// We are using statement1 not statment2,
|
64
|
+
// Because even that attribute doesn't have value, We need default value
|
65
|
+
`(() => {
|
66
|
+
let langEle = document.querySelector('[${localeAttr}]');
|
67
|
+
return langEle && langEle.getAttribute('${localeAttr}') || '${localeDefaultValue}';
|
68
|
+
})();`;
|
69
|
+
this.options.cssDirStatement = options.cssDirStatement || `(() => {
|
70
|
+
let dirEle = document.querySelector('[${cssDirAttr}]');
|
71
|
+
return dirEle && dirEle.getAttribute('${cssDirAttr}') || '${cssDirDefaultValue}';
|
72
|
+
})();`;
|
73
|
+
} // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
74
|
+
// getI18nManifest(compilation) {
|
75
|
+
// const i18nManifestFile =
|
76
|
+
// compilation.assets[this.options.i18nManifestFileName];
|
77
|
+
// if (i18nManifestFile) {
|
78
|
+
// const manifest = JSON.parse(i18nManifestFile.source());
|
79
|
+
// return manifest;
|
80
|
+
// }
|
81
|
+
// return {};
|
82
|
+
// }
|
83
|
+
|
84
|
+
|
85
|
+
getI18nAssetsStr(entryPoint, compilation) {
|
86
|
+
if (!chunkSplitEnable) {
|
87
|
+
let i18nAsstes = {};
|
88
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
89
|
+
|
90
|
+
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
91
|
+
let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
92
|
+
let splittedFileName = fileName.split('.');
|
93
|
+
res[splittedFileName[0]] = i18nFilePath;
|
94
|
+
return res;
|
95
|
+
}, {});
|
96
|
+
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
97
|
+
}
|
98
|
+
|
99
|
+
let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
100
|
+
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
101
|
+
}
|
102
|
+
|
103
|
+
createFileContent(compilation) {
|
104
|
+
const {
|
105
|
+
entryPointName,
|
106
|
+
localeStatement,
|
107
|
+
cssDirStatement,
|
108
|
+
nameScope,
|
109
|
+
cdnVariableName = null
|
110
|
+
} = this.options;
|
111
|
+
const {
|
112
|
+
serverUrl
|
113
|
+
} = this;
|
114
|
+
const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
|
115
|
+
|
116
|
+
const entryPoint = compilation.entrypoints.get(entryPointName); // const chunk = compilation.namedChunks.get(entryPointName);
|
117
|
+
|
118
|
+
const [jsPath, cssPath,,, i18nJsPath] = !this.isDevelopment ? publicPaths : [];
|
119
|
+
const initialFiles = entryPoint.getFiles();
|
120
|
+
const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file)); // const i18nAssets = getShortI18nAssets(
|
121
|
+
// entryPoint.chunks,
|
122
|
+
// i18nManifest,
|
123
|
+
// i18nJsPath
|
124
|
+
// );
|
125
|
+
|
126
|
+
const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, i18nJsPath);
|
127
|
+
return `(() => {
|
128
|
+
const lang = ${localeStatement};
|
129
|
+
${enableRTLSplit ? `const cssDir = ${cssDirStatement};` : ''}
|
130
|
+
const prod = !${this.isDevelopment};
|
131
|
+
let cdnVariableName = "${cdnVariableName}";
|
132
|
+
|
133
|
+
function getAssetUrl(ext) {
|
134
|
+
${cdnStatement ? `
|
135
|
+
return (() => {
|
136
|
+
let fu = (${cdnStatement});
|
137
|
+
return typeof fu === "function" ? fu(ext) : fu;
|
138
|
+
})();` : ''}
|
139
|
+
|
140
|
+
${publicPaths.callback ? `return (${publicPaths.callback})(ext)` : ''}
|
141
|
+
|
142
|
+
let assetURLs = {
|
143
|
+
//hook
|
144
|
+
js: ${JSON.stringify(jsPath || serverUrl)},
|
145
|
+
css: ${JSON.stringify(cssPath || serverUrl)},
|
146
|
+
i18n: ${JSON.stringify(i18nJsPath || serverUrl)}
|
147
|
+
};
|
148
|
+
|
149
|
+
return assetURLs[ext];
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
window.desk_urls={}
|
155
|
+
window.desk_urls.staticDomain = 'https:' + getAssetUrl('js') + '/';
|
156
|
+
if (prod && cdnVariableName) {
|
157
|
+
window["${cdnVariableName}"] = 'https:' + getAssetUrl('css') + '/';
|
158
|
+
}
|
159
|
+
|
160
|
+
let initalI18nAssets = ${initalI18nAssets};
|
161
|
+
let initialAssets = initalI18nAssets.concat(${JSON.stringify(enableRTLSplit ? filteredInitialFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate)) : filteredInitialFiles)});
|
162
|
+
|
163
|
+
let loadAsset = (id, type, url) => {
|
164
|
+
return new Promise((res, rej) => {
|
165
|
+
let el = document.createElement(type);
|
166
|
+
// el.id = id;
|
167
|
+
el.onload = res;
|
168
|
+
el.error = rej;
|
169
|
+
switch(type) {
|
170
|
+
case 'script':
|
171
|
+
case 'i18n':
|
172
|
+
el.src = (type === 'i18n'? getAssetUrl('i18n') : getAssetUrl('js'))+'/'+url
|
173
|
+
el.defer = 'defer';
|
174
|
+
document.body.appendChild(el);
|
175
|
+
break;
|
176
|
+
case 'link':
|
177
|
+
el.href = getAssetUrl('css')+'/'+url${enableRTLSplit ? `.replace(${JSON.stringify(cssDirTemplate)}, cssDir)` : ''}
|
178
|
+
el.rel = 'stylesheet';
|
179
|
+
document.head.appendChild(el);
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
});
|
183
|
+
};
|
184
|
+
|
185
|
+
let memorizedPromise = null;
|
186
|
+
${nameScope}.onload = (cb, err) => {
|
187
|
+
if(!memorizedPromise) {
|
188
|
+
memorizedPromise = Promise.all(
|
189
|
+
initialAssets.map(
|
190
|
+
(url, index) => loadAsset(
|
191
|
+
"${nameScope}-" + (url.endsWith("js") ? "js" : "css") +"-"+index,
|
192
|
+
url.endsWith("js") ? url.endsWith(".i18n.js") ? "i18n" : 'script' : 'link',
|
193
|
+
url
|
194
|
+
)
|
195
|
+
)
|
196
|
+
).then(() => ${nameScope}.onBasicLoad(cb));
|
197
|
+
}
|
198
|
+
return memorizedPromise;
|
199
|
+
};
|
200
|
+
|
201
|
+
})();
|
202
|
+
`;
|
203
|
+
}
|
204
|
+
|
205
|
+
apply(compiler) {
|
206
|
+
if (!createSDkFile) {
|
207
|
+
return;
|
208
|
+
} //console.log('this.templateFilePath', this.templateFilePath, this.options);
|
209
|
+
|
210
|
+
|
211
|
+
if (this.templateFilePath) {
|
212
|
+
new _EFCTemplatePlugin.default({
|
213
|
+
templateFilePath: this.templateFilePath,
|
214
|
+
publicPath: this.serverUrl,
|
215
|
+
i18nFileNameTemplate: this.i18nFileNameTemplate,
|
216
|
+
entryPointName: this.options.entryPointName
|
217
|
+
}).apply(compiler);
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
|
221
|
+
compiler.hooks.emit.tap('EFCPlugin', compilation => {
|
222
|
+
const {
|
223
|
+
entryPointName,
|
224
|
+
outputFile
|
225
|
+
} = this.options;
|
226
|
+
const entryPoint = compilation.entrypoints.get(entryPointName);
|
227
|
+
|
228
|
+
if (!entryPoint) {
|
229
|
+
return;
|
230
|
+
}
|
231
|
+
|
232
|
+
const source = new _webpackSources.RawSource(this.createFileContent(compilation));
|
233
|
+
compilation.assets[outputFile] = source; // eslint-disable-next-line no-console
|
234
|
+
|
235
|
+
console.log('The EFC embedded code was created successfully..!!!');
|
236
|
+
});
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
exports.default = EFCPlugin;
|
@@ -0,0 +1,151 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _webpackSources = require("webpack-sources");
|
9
|
+
|
10
|
+
var _utils = require("../utils");
|
11
|
+
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
13
|
+
|
14
|
+
var _fs = require("fs");
|
15
|
+
|
16
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
17
|
+
|
18
|
+
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
|
19
|
+
|
20
|
+
var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
25
|
+
const cliOptions = (0, _utils.getOptions)();
|
26
|
+
const {
|
27
|
+
i18n: {
|
28
|
+
chunkSplitEnable
|
29
|
+
},
|
30
|
+
css: {
|
31
|
+
enableRTLSplit
|
32
|
+
},
|
33
|
+
efc: efcOptios
|
34
|
+
} = cliOptions;
|
35
|
+
const {
|
36
|
+
createSDkFile
|
37
|
+
} = efcOptios; // for smap relate changes
|
38
|
+
// CdnChangePlugin
|
39
|
+
// SourceMapHookPlugin
|
40
|
+
|
41
|
+
class EFCTemplatePlugin {
|
42
|
+
constructor(options = {}) {
|
43
|
+
// console.log(' templateFilePath ', process.cwd(), options.templateFilePath, templateFilePath);
|
44
|
+
this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath); // console.log(' templateFilePath ', this.templateFilePath);
|
45
|
+
|
46
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
47
|
+
this.publicPath = options.publicPath; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
48
|
+
// this.i18nManifestFileName = options.i18nManifestFileName;
|
49
|
+
// IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
|
50
|
+
// So when debugging consider this as well
|
51
|
+
// this.options = Object.assign({}, efcOptios, options);
|
52
|
+
|
53
|
+
this.entryPointName = options.entryPointName || 'efc';
|
54
|
+
this.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
|
55
|
+
} // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
56
|
+
// getI18nManifest(compilation) {
|
57
|
+
// const i18nManifestFile =
|
58
|
+
// compilation.assets[this.options.i18nManifestFileName];
|
59
|
+
// if (i18nManifestFile) {
|
60
|
+
// const manifest = JSON.parse(i18nManifestFile.source());
|
61
|
+
// return manifest;
|
62
|
+
// }
|
63
|
+
// return {};
|
64
|
+
// }
|
65
|
+
|
66
|
+
|
67
|
+
getI18nAssetsStr(entryPoint, compilation) {
|
68
|
+
// NOTE: we have used lang variable inside
|
69
|
+
if (!chunkSplitEnable) {
|
70
|
+
let i18nAsstes = {};
|
71
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
72
|
+
|
73
|
+
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
74
|
+
let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
75
|
+
let splittedFileName = fileName.split('.');
|
76
|
+
res[splittedFileName[0]] = i18nFilePath;
|
77
|
+
return res;
|
78
|
+
}, {});
|
79
|
+
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
80
|
+
}
|
81
|
+
|
82
|
+
let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
83
|
+
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
84
|
+
}
|
85
|
+
|
86
|
+
templateReplacer(entryPoint, compilation) {
|
87
|
+
const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
|
88
|
+
|
89
|
+
const initialFiles = entryPoint.getFiles();
|
90
|
+
const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file));
|
91
|
+
const initialJsFiles = filteredInitialFiles.filter(file => /\.js$/.test(file));
|
92
|
+
let initialCssFiles = filteredInitialFiles.filter(file => /\.css$/.test(file));
|
93
|
+
|
94
|
+
if (enableRTLSplit) {
|
95
|
+
initialCssFiles = initialCssFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate));
|
96
|
+
} // const i18nAssets = getShortI18nAssets(
|
97
|
+
// entryPoint.chunks,
|
98
|
+
// i18nManifest,
|
99
|
+
// '' // i18nJsPath
|
100
|
+
// );
|
101
|
+
|
102
|
+
|
103
|
+
const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, '' // i18nJsPath
|
104
|
+
);
|
105
|
+
let templateStr = (0, _fs.readFileSync)(this.templateFilePath).toString();
|
106
|
+
return templateStr.replace('((\'getInitalAssets\'))', `function getInitalAssets(assetsType, lang) {
|
107
|
+
if (assetsType === "js") {
|
108
|
+
return ${JSON.stringify(initialJsFiles)}
|
109
|
+
}
|
110
|
+
if (assetsType === "css") {
|
111
|
+
return ${JSON.stringify(initialCssFiles)}
|
112
|
+
}
|
113
|
+
if (assetsType === "i18n") {
|
114
|
+
return ${initalI18nAssets};
|
115
|
+
}
|
116
|
+
return [];
|
117
|
+
}`).replace('((\'@dir@\'))', '\'@dir@\'').replace('((\'publicPath\'))', this.publicPath).replace('((\'@locale@\'))', '\'@locale@\'');
|
118
|
+
}
|
119
|
+
|
120
|
+
apply(compiler) {
|
121
|
+
if (!createSDkFile) {
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
|
125
|
+
compiler.hooks.emit.tap('EFCTemplatePlugin', compilation => {
|
126
|
+
const {
|
127
|
+
entryPointName,
|
128
|
+
outputFile
|
129
|
+
} = this;
|
130
|
+
const entryPoint = compilation.entrypoints.get(entryPointName);
|
131
|
+
|
132
|
+
if (!entryPoint) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
|
136
|
+
if (!(0, _fs.existsSync)(this.templateFilePath)) {
|
137
|
+
console.error(`EFC Template file not exists ${this.templateFilePath}`);
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
|
141
|
+
const source = new _webpackSources.RawSource(this.templateReplacer(entryPoint, compilation));
|
142
|
+
compilation.assets[outputFile] = source; // console.log('EFCTemplatePlugin working');
|
143
|
+
// eslint-disable-next-line no-console
|
144
|
+
|
145
|
+
console.log('The EFC embedded code was created successfully..!!!');
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
exports.default = EFCTemplatePlugin;
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
9
|
+
|
10
|
+
var _utils = require("../utils");
|
11
|
+
|
12
|
+
var _urlConcat = require("../utils/urlConcat");
|
13
|
+
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
15
|
+
|
16
|
+
var _webpackSources = require("webpack-sources");
|
17
|
+
|
18
|
+
var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
|
19
|
+
|
20
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
let i18nObj = null;
|
25
|
+
let options = (0, _utils.getOptions)();
|
26
|
+
|
27
|
+
function newAssign(target, data) {
|
28
|
+
return Object.assign({}, target, data);
|
29
|
+
}
|
30
|
+
|
31
|
+
const {
|
32
|
+
i18n
|
33
|
+
} = options;
|
34
|
+
|
35
|
+
class I18NInjectIntoIndexPlugin {
|
36
|
+
constructor(options) {
|
37
|
+
this.isDevelopment = options.isDevelopment;
|
38
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
39
|
+
this.publicPath = options.publicPath;
|
40
|
+
this.templateLabel = options.templateLabel || '{{--user-locale}}';
|
41
|
+
this.i18nManifestFileName = options.i18nManifestFileName;
|
42
|
+
this.entryPointName = options.mainChunkName;
|
43
|
+
}
|
44
|
+
|
45
|
+
getI18nFileUrlPath(chunk, compilation) {
|
46
|
+
let urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
|
47
|
+
return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
|
48
|
+
}
|
49
|
+
|
50
|
+
getI18nManifest(compilation) {
|
51
|
+
const i18nManifestFile = compilation.assets[this.i18nManifestFileName];
|
52
|
+
|
53
|
+
if (!i18nManifestFile) {
|
54
|
+
return {};
|
55
|
+
}
|
56
|
+
|
57
|
+
const manifest = JSON.parse(i18nManifestFile.source());
|
58
|
+
return manifest;
|
59
|
+
}
|
60
|
+
|
61
|
+
injectI18nURLsToHTML(compilation) {
|
62
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
|
63
|
+
const {
|
64
|
+
assets
|
65
|
+
} = data; // Manipulate the content
|
66
|
+
|
67
|
+
const i18nManifest = this.getI18nManifest(compilation);
|
68
|
+
const entryPoint = compilation.entrypoints.get(this.entryPointName);
|
69
|
+
const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation)); // .map(url => getI18nScriptTagObj(url));
|
70
|
+
// .join('');
|
71
|
+
// Tell webpack to move on
|
72
|
+
|
73
|
+
cb(null, newAssign(data, {
|
74
|
+
assets: newAssign(assets, {
|
75
|
+
js: i18nScriptURLs.concat(assets.js)
|
76
|
+
})
|
77
|
+
}));
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
withI18nSpitHandling(compiler) {
|
82
|
+
compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
|
83
|
+
// let cdns = Object.keys(this.publicPaths);
|
84
|
+
// console.log('compilation.assets', Object.keys(compilation.assets).filter(a => a.includes('i18n')));
|
85
|
+
if (!(0, _hashUtils.hasContentHash)(this.i18nFileNameTemplate)) {
|
86
|
+
this.injectI18nURLsToHTML(compilation);
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
|
90
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
|
91
|
+
// Manipulate the content
|
92
|
+
const i18nManifest = this.getI18nManifest(compilation);
|
93
|
+
const entryPoint = compilation.entrypoints.get(this.entryPointName);
|
94
|
+
let i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
|
95
|
+
data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
|
96
|
+
|
97
|
+
cb(null, data);
|
98
|
+
});
|
99
|
+
});
|
100
|
+
}
|
101
|
+
|
102
|
+
apply(compiler) {
|
103
|
+
if (i18n.chunkSplitEnable) {
|
104
|
+
this.withI18nSpitHandling(compiler);
|
105
|
+
} else {
|
106
|
+
this.withoutI18nSpitHandling(compiler);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
withoutI18nSpitHandling(compiler) {
|
111
|
+
compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
|
112
|
+
// let cdns = Object.keys(this.publicPaths);
|
113
|
+
if (i18nObj === null) {
|
114
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
115
|
+
|
116
|
+
i18nObj = i18nFiles.reduce((res, next) => {
|
117
|
+
let fileName = next.replace(`i18n${_path.default.sep}`, '');
|
118
|
+
let splittedFileName = fileName.split('.');
|
119
|
+
/* if (this.isDevelopment) {
|
120
|
+
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
121
|
+
} else {
|
122
|
+
res[splittedFileName[0]] = fileName;
|
123
|
+
} */
|
124
|
+
|
125
|
+
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
126
|
+
return res;
|
127
|
+
}, {});
|
128
|
+
}
|
129
|
+
|
130
|
+
let [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
|
131
|
+
|
132
|
+
if (indexFile) {
|
133
|
+
let source = compilation.assets[indexFile].source();
|
134
|
+
compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
|
135
|
+
}
|
136
|
+
});
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
exports.default = I18NInjectIntoIndexPlugin;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _utils = require("./utils");
|
9
|
+
|
10
|
+
const pluginName = 'I18nDebugPlugin'; // this plugin only for debug related purpose
|
11
|
+
|
12
|
+
class I18nDebugPlugin {
|
13
|
+
constructor(jsResourceI18nKeys) {
|
14
|
+
this.jsResourceI18nKeys = jsResourceI18nKeys;
|
15
|
+
this.warnings = [];
|
16
|
+
}
|
17
|
+
|
18
|
+
apply(compiler) {
|
19
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
|
20
|
+
// TEMP : only for debugging purpose
|
21
|
+
this.compilation1 = compilation;
|
22
|
+
this.compilationParams = compilationParams.normalModuleFactory;
|
23
|
+
});
|
24
|
+
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
|
25
|
+
if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
|
26
|
+
return;
|
27
|
+
} // console.log('skiped');
|
28
|
+
|
29
|
+
|
30
|
+
let handler = parser => {
|
31
|
+
parser.hooks.program.tap(pluginName, (ast, commmets) => {
|
32
|
+
const {
|
33
|
+
module
|
34
|
+
} = parser.state; //
|
35
|
+
|
36
|
+
if (!(module && /\.jsx?$/.test(module.resource))) {
|
37
|
+
return;
|
38
|
+
} // i18n grep proper contract regex
|
39
|
+
|
40
|
+
|
41
|
+
let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
|
42
|
+
i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
|
43
|
+
(0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
|
44
|
+
i18nKeys.length && this.warnings.push({
|
45
|
+
message: 'skiped i18n keys',
|
46
|
+
reason: 'may be some child compiler',
|
47
|
+
fileName: module.resource,
|
48
|
+
i18nKeys
|
49
|
+
});
|
50
|
+
});
|
51
|
+
};
|
52
|
+
|
53
|
+
factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
|
54
|
+
factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler); // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
exports.default = I18nDebugPlugin;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.I18nDependencyTemplate = exports.I18nDependency = void 0;
|
7
|
+
|
8
|
+
var _webpack = require("webpack");
|
9
|
+
|
10
|
+
// const webpack = require('webpack');
|
11
|
+
class I18nDependency extends _webpack.Dependency {
|
12
|
+
constructor({
|
13
|
+
identifier,
|
14
|
+
i18nKeys
|
15
|
+
}, context, identifierIndex) {
|
16
|
+
super();
|
17
|
+
this.identifier = identifier;
|
18
|
+
this.identifierIndex = identifierIndex;
|
19
|
+
this.i18nKeys = i18nKeys;
|
20
|
+
this.context = context;
|
21
|
+
}
|
22
|
+
|
23
|
+
getResourceIdentifier() {
|
24
|
+
return `i18n-module-${this.identifier}-${this.identifierIndex}`;
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
exports.I18nDependency = I18nDependency;
|
30
|
+
|
31
|
+
class I18nDependencyTemplate {
|
32
|
+
//eslint-disable-next-line no-empty-function
|
33
|
+
apply() {} // apply(dep, source) {
|
34
|
+
// if (typeof dep.range === "number") {
|
35
|
+
// source.insert(0, `/* comment by I18nSplitPlugin , i18n keys = ${JSON.stringify(dep.i18nKeys)} */`);
|
36
|
+
// return;
|
37
|
+
// }
|
38
|
+
// source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
|
39
|
+
// }
|
40
|
+
|
41
|
+
|
42
|
+
}
|
43
|
+
|
44
|
+
exports.I18nDependencyTemplate = I18nDependencyTemplate;
|