@dcloudio/uni-cli-shared 0.0.1-nvue3.3030820220125001
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/dist/checkUpdate.d.ts +30 -0
- package/dist/checkUpdate.js +243 -0
- package/dist/constants.d.ts +19 -0
- package/dist/constants.js +43 -0
- package/dist/deps.d.ts +19 -0
- package/dist/deps.js +39 -0
- package/dist/easycom.d.ts +29 -0
- package/dist/easycom.js +202 -0
- package/dist/env/define.d.ts +15 -0
- package/dist/env/define.js +45 -0
- package/dist/env/index.d.ts +2 -0
- package/dist/env/index.js +8 -0
- package/dist/env/provide.d.ts +9 -0
- package/dist/env/provide.js +24 -0
- package/dist/esbuild.d.ts +3 -0
- package/dist/esbuild.js +42 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.js +8 -0
- package/dist/filter.d.ts +16 -0
- package/dist/filter.js +60 -0
- package/dist/fs.d.ts +1 -0
- package/dist/fs.js +25 -0
- package/dist/hbx/alias.d.ts +5 -0
- package/dist/hbx/alias.js +75 -0
- package/dist/hbx/env.d.ts +6 -0
- package/dist/hbx/env.js +44 -0
- package/dist/hbx/index.d.ts +3 -0
- package/dist/hbx/index.js +36 -0
- package/dist/hbx/log.d.ts +6 -0
- package/dist/hbx/log.js +99 -0
- package/dist/i18n.d.ts +10 -0
- package/dist/i18n.js +94 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +40 -0
- package/dist/json/app/index.d.ts +3 -0
- package/dist/json/app/index.js +17 -0
- package/dist/json/app/manifest/arguments.d.ts +2 -0
- package/dist/json/app/manifest/arguments.js +36 -0
- package/dist/json/app/manifest/confusion.d.ts +4 -0
- package/dist/json/app/manifest/confusion.js +77 -0
- package/dist/json/app/manifest/defaultManifestJson.d.ts +1 -0
- package/dist/json/app/manifest/defaultManifestJson.js +41 -0
- package/dist/json/app/manifest/env.d.ts +3 -0
- package/dist/json/app/manifest/env.js +24 -0
- package/dist/json/app/manifest/i18n.d.ts +1 -0
- package/dist/json/app/manifest/i18n.js +14 -0
- package/dist/json/app/manifest/index.d.ts +4 -0
- package/dist/json/app/manifest/index.js +49 -0
- package/dist/json/app/manifest/launchwebview.d.ts +1 -0
- package/dist/json/app/manifest/launchwebview.js +32 -0
- package/dist/json/app/manifest/merge.d.ts +1 -0
- package/dist/json/app/manifest/merge.js +17 -0
- package/dist/json/app/manifest/nvue.d.ts +4 -0
- package/dist/json/app/manifest/nvue.js +43 -0
- package/dist/json/app/manifest/plus.d.ts +1 -0
- package/dist/json/app/manifest/plus.js +83 -0
- package/dist/json/app/manifest/safearea.d.ts +1 -0
- package/dist/json/app/manifest/safearea.js +28 -0
- package/dist/json/app/manifest/splashscreen.d.ts +5 -0
- package/dist/json/app/manifest/splashscreen.js +44 -0
- package/dist/json/app/manifest/statusbar.d.ts +1 -0
- package/dist/json/app/manifest/statusbar.js +14 -0
- package/dist/json/app/manifest/tabBar.d.ts +1 -0
- package/dist/json/app/manifest/tabBar.js +27 -0
- package/dist/json/app/manifest/uniApp.d.ts +1 -0
- package/dist/json/app/manifest/uniApp.js +19 -0
- package/dist/json/app/pages/code.d.ts +3 -0
- package/dist/json/app/pages/code.js +44 -0
- package/dist/json/app/pages/definePage.d.ts +2 -0
- package/dist/json/app/pages/definePage.js +42 -0
- package/dist/json/app/pages/index.d.ts +3 -0
- package/dist/json/app/pages/index.js +28 -0
- package/dist/json/app/pages/uniConfig.d.ts +1 -0
- package/dist/json/app/pages/uniConfig.js +69 -0
- package/dist/json/app/pages/uniRoutes.d.ts +1 -0
- package/dist/json/app/pages/uniRoutes.js +8 -0
- package/dist/json/index.d.ts +5 -0
- package/dist/json/index.js +17 -0
- package/dist/json/json.d.ts +1 -0
- package/dist/json/json.js +9 -0
- package/dist/json/manifest.d.ts +28 -0
- package/dist/json/manifest.js +64 -0
- package/dist/json/mp/index.d.ts +4 -0
- package/dist/json/mp/index.js +19 -0
- package/dist/json/mp/jsonFile.d.ts +23 -0
- package/dist/json/mp/jsonFile.js +127 -0
- package/dist/json/mp/pages.d.ts +17 -0
- package/dist/json/mp/pages.js +126 -0
- package/dist/json/mp/project.d.ts +14 -0
- package/dist/json/mp/project.js +81 -0
- package/dist/json/mp/types.d.ts +118 -0
- package/dist/json/mp/types.js +2 -0
- package/dist/json/mp/utils.d.ts +3 -0
- package/dist/json/mp/utils.js +66 -0
- package/dist/json/pages.d.ts +30 -0
- package/dist/json/pages.js +383 -0
- package/dist/logs/console.d.ts +4 -0
- package/dist/logs/console.js +49 -0
- package/dist/logs/format.d.ts +11 -0
- package/dist/logs/format.js +82 -0
- package/dist/logs/index.d.ts +1 -0
- package/dist/logs/index.js +7 -0
- package/dist/messages/index.d.ts +20 -0
- package/dist/messages/index.js +23 -0
- package/dist/mp/ast.d.ts +4 -0
- package/dist/mp/ast.js +12 -0
- package/dist/mp/constants.d.ts +5 -0
- package/dist/mp/constants.js +8 -0
- package/dist/mp/event.d.ts +5 -0
- package/dist/mp/event.js +35 -0
- package/dist/mp/externalClasses.d.ts +5 -0
- package/dist/mp/externalClasses.js +42 -0
- package/dist/mp/imports.d.ts +12 -0
- package/dist/mp/imports.js +72 -0
- package/dist/mp/index.d.ts +11 -0
- package/dist/mp/index.js +38 -0
- package/dist/mp/nvue.d.ts +1 -0
- package/dist/mp/nvue.js +18 -0
- package/dist/mp/plugin.d.ts +2 -0
- package/dist/mp/plugin.js +13 -0
- package/dist/mp/style.d.ts +1 -0
- package/dist/mp/style.js +9 -0
- package/dist/mp/tags.d.ts +1 -0
- package/dist/mp/tags.js +117 -0
- package/dist/mp/template.d.ts +73 -0
- package/dist/mp/template.js +73 -0
- package/dist/mp/usingComponents.d.ts +65 -0
- package/dist/mp/usingComponents.js +402 -0
- package/dist/mp/wxs.d.ts +2 -0
- package/dist/mp/wxs.js +55 -0
- package/dist/platform.d.ts +2 -0
- package/dist/platform.js +31 -0
- package/dist/postcss/index.d.ts +10 -0
- package/dist/postcss/index.js +19 -0
- package/dist/postcss/plugins/stylePluginScoped.d.ts +3 -0
- package/dist/postcss/plugins/stylePluginScoped.js +176 -0
- package/dist/postcss/plugins/uniapp.d.ts +11 -0
- package/dist/postcss/plugins/uniapp.js +110 -0
- package/dist/preprocess/context.d.ts +3 -0
- package/dist/preprocess/context.js +81 -0
- package/dist/preprocess/index.d.ts +9 -0
- package/dist/preprocess/index.js +28 -0
- package/dist/resolve.d.ts +6 -0
- package/dist/resolve.js +102 -0
- package/dist/scripts.d.ts +10 -0
- package/dist/scripts.js +44 -0
- package/dist/ssr.d.ts +4 -0
- package/dist/ssr.js +20 -0
- package/dist/url.d.ts +2 -0
- package/dist/url.js +15 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +80 -0
- package/dist/vite/features.d.ts +41 -0
- package/dist/vite/features.js +191 -0
- package/dist/vite/index.d.ts +36 -0
- package/dist/vite/index.js +17 -0
- package/dist/vite/plugins/console.d.ts +8 -0
- package/dist/vite/plugins/console.js +42 -0
- package/dist/vite/plugins/copy.d.ts +11 -0
- package/dist/vite/plugins/copy.js +51 -0
- package/dist/vite/plugins/cssScoped.d.ts +6 -0
- package/dist/vite/plugins/cssScoped.js +54 -0
- package/dist/vite/plugins/dynamicImportPolyfill.d.ts +2 -0
- package/dist/vite/plugins/dynamicImportPolyfill.js +15 -0
- package/dist/vite/plugins/index.d.ts +10 -0
- package/dist/vite/plugins/index.js +32 -0
- package/dist/vite/plugins/inject.d.ts +12 -0
- package/dist/vite/plugins/inject.js +207 -0
- package/dist/vite/plugins/jsonJs.d.ts +3 -0
- package/dist/vite/plugins/jsonJs.js +52 -0
- package/dist/vite/plugins/mainJs.d.ts +2 -0
- package/dist/vite/plugins/mainJs.js +29 -0
- package/dist/vite/plugins/vitejs/config.d.ts +1 -0
- package/dist/vite/plugins/vitejs/config.js +2 -0
- package/dist/vite/plugins/vitejs/constants.d.ts +8 -0
- package/dist/vite/plugins/vitejs/constants.js +11 -0
- package/dist/vite/plugins/vitejs/index.d.ts +1 -0
- package/dist/vite/plugins/vitejs/index.js +2 -0
- package/dist/vite/plugins/vitejs/plugin.d.ts +1 -0
- package/dist/vite/plugins/vitejs/plugin.js +2 -0
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +40 -0
- package/dist/vite/plugins/vitejs/plugins/asset.js +270 -0
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +48 -0
- package/dist/vite/plugins/vitejs/plugins/css.js +760 -0
- package/dist/vite/plugins/vitejs/server/moduleGraph.d.ts +1 -0
- package/dist/vite/plugins/vitejs/server/moduleGraph.js +2 -0
- package/dist/vite/plugins/vitejs/utils.d.ts +29 -0
- package/dist/vite/plugins/vitejs/utils.js +129 -0
- package/dist/vite/utils/ast.d.ts +17 -0
- package/dist/vite/utils/ast.js +85 -0
- package/dist/vite/utils/index.d.ts +7 -0
- package/dist/vite/utils/index.js +23 -0
- package/dist/vite/utils/plugin.d.ts +11 -0
- package/dist/vite/utils/plugin.js +45 -0
- package/dist/vite/utils/url.d.ts +28 -0
- package/dist/vite/utils/url.js +69 -0
- package/dist/vite/utils/utils.d.ts +3 -0
- package/dist/vite/utils/utils.js +14 -0
- package/dist/vue/babel.d.ts +3 -0
- package/dist/vue/babel.js +17 -0
- package/dist/vue/index.d.ts +4 -0
- package/dist/vue/index.js +19 -0
- package/dist/vue/transforms/index.d.ts +13 -0
- package/dist/vue/transforms/index.js +48 -0
- package/dist/vue/transforms/templateTransformAssetUrl.d.ts +33 -0
- package/dist/vue/transforms/templateTransformAssetUrl.js +150 -0
- package/dist/vue/transforms/templateTransformSrcset.d.ts +4 -0
- package/dist/vue/transforms/templateTransformSrcset.js +122 -0
- package/dist/vue/transforms/templateUtils.d.ts +9 -0
- package/dist/vue/transforms/templateUtils.js +41 -0
- package/dist/vue/transforms/transformComponent.d.ts +3 -0
- package/dist/vue/transforms/transformComponent.js +26 -0
- package/dist/vue/transforms/transformEvent.d.ts +2 -0
- package/dist/vue/transforms/transformEvent.js +28 -0
- package/dist/vue/transforms/transformPageHead.d.ts +2 -0
- package/dist/vue/transforms/transformPageHead.js +11 -0
- package/dist/vue/transforms/transformRef.d.ts +2 -0
- package/dist/vue/transforms/transformRef.js +32 -0
- package/dist/vue/transforms/transformTag.d.ts +2 -0
- package/dist/vue/transforms/transformTag.js +18 -0
- package/dist/vue/transforms/vModel.d.ts +12 -0
- package/dist/vue/transforms/vModel.js +33 -0
- package/dist/vue/transforms/vOn.d.ts +15 -0
- package/dist/vue/transforms/vOn.js +88 -0
- package/dist/vue/utils.d.ts +31 -0
- package/dist/vue/utils.js +120 -0
- package/dist/watcher.d.ts +30 -0
- package/dist/watcher.js +92 -0
- package/lib/crypto.js +65 -0
- package/lib/nvue.css +34 -0
- package/lib/preprocess/LICENSE +13 -0
- package/lib/preprocess/README.md +410 -0
- package/lib/preprocess/lib/preprocess.js +437 -0
- package/lib/preprocess/lib/regexrules.js +121 -0
- package/lib/preprocess/package.json +68 -0
- package/package.json +68 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDefine = void 0;
|
|
4
|
+
const env_1 = require("../hbx/env");
|
|
5
|
+
const json_1 = require("../json");
|
|
6
|
+
function initDefine(stringifyBoolean = false) {
|
|
7
|
+
const manifestJson = (0, json_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
|
|
8
|
+
const isRunByHBuilderX = (0, env_1.runByHBuilderX)();
|
|
9
|
+
const isDebug = !!manifestJson.debug;
|
|
10
|
+
return {
|
|
11
|
+
...initCustomDefine(),
|
|
12
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
13
|
+
'process.env.UNI_DEBUG': stringifyBoolean
|
|
14
|
+
? JSON.stringify(isDebug)
|
|
15
|
+
: isDebug,
|
|
16
|
+
'process.env.UNI_APP_ID': JSON.stringify(manifestJson.appid || ''),
|
|
17
|
+
'process.env.UNI_APP_NAME': JSON.stringify(manifestJson.name || ''),
|
|
18
|
+
'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
|
|
19
|
+
'process.env.UNI_MP_PLUGIN': JSON.stringify(process.env.UNI_MP_PLUGIN),
|
|
20
|
+
'process.env.UNI_SUBPACKAGE': JSON.stringify(process.env.UNI_SUBPACKAGE),
|
|
21
|
+
'process.env.UNI_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION),
|
|
22
|
+
'process.env.RUN_BY_HBUILDERX': stringifyBoolean
|
|
23
|
+
? JSON.stringify(isRunByHBuilderX)
|
|
24
|
+
: isRunByHBuilderX,
|
|
25
|
+
'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT),
|
|
26
|
+
'process.env.UNI_CLOUD_PROVIDER': JSON.stringify(process.env.UNI_CLOUD_PROVIDER),
|
|
27
|
+
'process.env.UNICLOUD_DEBUG': JSON.stringify(process.env.UNICLOUD_DEBUG),
|
|
28
|
+
// 兼容旧版本
|
|
29
|
+
'process.env.VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.initDefine = initDefine;
|
|
33
|
+
function initCustomDefine() {
|
|
34
|
+
let define = {};
|
|
35
|
+
if (process.env.UNI_CUSTOM_DEFINE) {
|
|
36
|
+
try {
|
|
37
|
+
define = JSON.parse(process.env.UNI_CUSTOM_DEFINE);
|
|
38
|
+
}
|
|
39
|
+
catch (e) { }
|
|
40
|
+
}
|
|
41
|
+
return Object.keys(define).reduce((res, name) => {
|
|
42
|
+
res['process.env.' + name] = JSON.stringify(define[name]);
|
|
43
|
+
return res;
|
|
44
|
+
}, {});
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initH5Provide = exports.initAppProvide = exports.initDefine = void 0;
|
|
4
|
+
var define_1 = require("./define");
|
|
5
|
+
Object.defineProperty(exports, "initDefine", { enumerable: true, get: function () { return define_1.initDefine; } });
|
|
6
|
+
var provide_1 = require("./provide");
|
|
7
|
+
Object.defineProperty(exports, "initAppProvide", { enumerable: true, get: function () { return provide_1.initAppProvide; } });
|
|
8
|
+
Object.defineProperty(exports, "initH5Provide", { enumerable: true, get: function () { return provide_1.initH5Provide; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initH5Provide = exports.initAppProvide = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const libDir = path_1.default.resolve(__dirname, '../../lib');
|
|
9
|
+
function initAppProvide() {
|
|
10
|
+
const cryptoDefine = [path_1.default.join(libDir, 'crypto.js'), 'default'];
|
|
11
|
+
return {
|
|
12
|
+
__f__: ['@dcloudio/uni-shared', 'formatAppLog'],
|
|
13
|
+
crypto: cryptoDefine,
|
|
14
|
+
'window.crypto': cryptoDefine,
|
|
15
|
+
'global.crypto': cryptoDefine,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.initAppProvide = initAppProvide;
|
|
19
|
+
function initH5Provide() {
|
|
20
|
+
return {
|
|
21
|
+
__f__: ['@dcloudio/uni-shared', 'formatH5Log'],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.initH5Provide = initH5Provide;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BuildOptions } from 'esbuild';
|
|
2
|
+
export declare function transformWithEsbuild(code: string, filename: string, options: BuildOptions): Promise<import("esbuild").BuildResult>;
|
|
3
|
+
export declare function esbuild(options: BuildOptions): Promise<import("esbuild").BuildResult>;
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.esbuild = exports.transformWithEsbuild = void 0;
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
function transformWithEsbuild(code, filename, options) {
|
|
28
|
+
options.stdin = {
|
|
29
|
+
contents: code,
|
|
30
|
+
resolveDir: path_1.default.dirname(filename),
|
|
31
|
+
};
|
|
32
|
+
return Promise.resolve().then(() => __importStar(require('esbuild'))).then((esbuild) => {
|
|
33
|
+
return esbuild.build(options);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.transformWithEsbuild = transformWithEsbuild;
|
|
37
|
+
function esbuild(options) {
|
|
38
|
+
return Promise.resolve().then(() => __importStar(require('esbuild'))).then((esbuild) => {
|
|
39
|
+
return esbuild.build(options);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.esbuild = esbuild;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as chokidar } from 'chokidar';
|
package/dist/exports.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.chokidar = void 0;
|
|
7
|
+
var chokidar_1 = require("chokidar");
|
|
8
|
+
Object.defineProperty(exports, "chokidar", { enumerable: true, get: function () { return __importDefault(chokidar_1).default; } });
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function isWxs(id: string): boolean;
|
|
2
|
+
export declare function isSjs(id: string): boolean;
|
|
3
|
+
export declare function isRenderjs(id: string): boolean;
|
|
4
|
+
declare type FilterType = 'wxs' | 'renderjs' | 'sjs';
|
|
5
|
+
export declare function parseRenderjs(id: string): {
|
|
6
|
+
type: FilterType;
|
|
7
|
+
name: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "";
|
|
11
|
+
readonly name: "";
|
|
12
|
+
readonly filename: "";
|
|
13
|
+
};
|
|
14
|
+
export declare function missingModuleName(type: FilterType, code: string): string;
|
|
15
|
+
export declare function parseFilterNames(lang: string, code: string): string[];
|
|
16
|
+
export {};
|
package/dist/filter.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFilterNames = exports.missingModuleName = exports.parseRenderjs = exports.isRenderjs = exports.isSjs = exports.isWxs = void 0;
|
|
4
|
+
const url_1 = require("./vite/utils/url");
|
|
5
|
+
const WXS_RE = /vue&type=wxs/;
|
|
6
|
+
function isWxs(id) {
|
|
7
|
+
return WXS_RE.test(id);
|
|
8
|
+
}
|
|
9
|
+
exports.isWxs = isWxs;
|
|
10
|
+
const SJS_RE = /vue&type=sjs/;
|
|
11
|
+
function isSjs(id) {
|
|
12
|
+
return SJS_RE.test(id);
|
|
13
|
+
}
|
|
14
|
+
exports.isSjs = isSjs;
|
|
15
|
+
const RENDERJS_RE = /vue&type=renderjs/;
|
|
16
|
+
function isRenderjs(id) {
|
|
17
|
+
return RENDERJS_RE.test(id);
|
|
18
|
+
}
|
|
19
|
+
exports.isRenderjs = isRenderjs;
|
|
20
|
+
function parseRenderjs(id) {
|
|
21
|
+
if (isWxs(id) || isRenderjs(id) || isSjs(id)) {
|
|
22
|
+
const { query, filename } = (0, url_1.parseVueRequest)(id);
|
|
23
|
+
return {
|
|
24
|
+
type: query.type,
|
|
25
|
+
name: query.name,
|
|
26
|
+
filename,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
type: '',
|
|
31
|
+
name: '',
|
|
32
|
+
filename: '',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.parseRenderjs = parseRenderjs;
|
|
36
|
+
function missingModuleName(type, code) {
|
|
37
|
+
return `<script module="missing module name" lang="${type}">
|
|
38
|
+
${code}
|
|
39
|
+
</script>`;
|
|
40
|
+
}
|
|
41
|
+
exports.missingModuleName = missingModuleName;
|
|
42
|
+
const moduleRE = /module=["'](.*?)["']/;
|
|
43
|
+
function parseFilterNames(lang, code) {
|
|
44
|
+
const names = [];
|
|
45
|
+
const scriptTags = code.match(/<script\b[^>]*>/gm);
|
|
46
|
+
if (!scriptTags) {
|
|
47
|
+
return names;
|
|
48
|
+
}
|
|
49
|
+
const langRE = new RegExp(`lang=["']${lang}["']`);
|
|
50
|
+
scriptTags.forEach((scriptTag) => {
|
|
51
|
+
if (langRE.test(scriptTag)) {
|
|
52
|
+
const matches = scriptTag.match(moduleRE);
|
|
53
|
+
if (matches) {
|
|
54
|
+
names.push(matches[1]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return names;
|
|
59
|
+
}
|
|
60
|
+
exports.parseFilterNames = parseFilterNames;
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function emptyDir(dir: string, skip?: string[]): void;
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.emptyDir = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function emptyDir(dir, skip) {
|
|
10
|
+
for (const file of fs_1.default.readdirSync(dir)) {
|
|
11
|
+
if (skip === null || skip === void 0 ? void 0 : skip.includes(file)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const abs = path_1.default.resolve(dir, file);
|
|
15
|
+
// baseline is Node 12 so can't use rmSync :(
|
|
16
|
+
if (fs_1.default.lstatSync(abs).isDirectory()) {
|
|
17
|
+
emptyDir(abs);
|
|
18
|
+
fs_1.default.rmdirSync(abs);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
fs_1.default.unlinkSync(abs);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.emptyDir = emptyDir;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Formatter } from '../logs/format';
|
|
2
|
+
export declare function initModuleAlias(): void;
|
|
3
|
+
export declare function installHBuilderXPlugin(plugin: string): void;
|
|
4
|
+
export declare const moduleAliasFormatter: Formatter;
|
|
5
|
+
export declare function formatInstallHBuilderXPluginTips(lang: string, preprocessor: string): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatInstallHBuilderXPluginTips = exports.moduleAliasFormatter = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const module_alias_1 = __importDefault(require("module-alias"));
|
|
9
|
+
const env_1 = require("./env");
|
|
10
|
+
const hbxPlugins = {
|
|
11
|
+
// typescript: 'compile-typescript/node_modules/typescript',
|
|
12
|
+
less: 'compile-less/node_modules/less',
|
|
13
|
+
sass: 'compile-dart-sass/node_modules/sass',
|
|
14
|
+
stylus: 'compile-stylus/node_modules/stylus',
|
|
15
|
+
pug: 'compile-pug-cli/node_modules/pug',
|
|
16
|
+
};
|
|
17
|
+
function initModuleAlias() {
|
|
18
|
+
const compilerSfcPath = require.resolve('@vue/compiler-sfc');
|
|
19
|
+
const serverRendererPath = require.resolve('@vue/server-renderer');
|
|
20
|
+
module_alias_1.default.addAliases({
|
|
21
|
+
'@vue/shared': require.resolve('@vue/shared'),
|
|
22
|
+
'@vue/compiler-dom': require.resolve('@vue/compiler-dom'),
|
|
23
|
+
'@vue/compiler-sfc': compilerSfcPath,
|
|
24
|
+
'@vue/server-renderer': serverRendererPath,
|
|
25
|
+
'vue/compiler-sfc': compilerSfcPath,
|
|
26
|
+
'vue/server-renderer': serverRendererPath,
|
|
27
|
+
});
|
|
28
|
+
if ((0, env_1.isInHBuilderX)()) {
|
|
29
|
+
Object.keys(hbxPlugins).forEach((name) => {
|
|
30
|
+
module_alias_1.default.addAlias(name, path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, hbxPlugins[name]));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.initModuleAlias = initModuleAlias;
|
|
35
|
+
function supportAutoInstallPlugin() {
|
|
36
|
+
return !!process.env.HX_Version;
|
|
37
|
+
}
|
|
38
|
+
function installHBuilderXPlugin(plugin) {
|
|
39
|
+
if (!supportAutoInstallPlugin()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return console.error(`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`);
|
|
43
|
+
}
|
|
44
|
+
exports.installHBuilderXPlugin = installHBuilderXPlugin;
|
|
45
|
+
exports.moduleAliasFormatter = {
|
|
46
|
+
test(msg) {
|
|
47
|
+
return msg.includes('Preprocessor dependency');
|
|
48
|
+
},
|
|
49
|
+
format(msg) {
|
|
50
|
+
let lang = '';
|
|
51
|
+
let preprocessor = '';
|
|
52
|
+
if (msg.includes(`"sass"`)) {
|
|
53
|
+
lang = 'sass';
|
|
54
|
+
preprocessor = 'compile-dart-sass';
|
|
55
|
+
}
|
|
56
|
+
else if (msg.includes(`"less"`)) {
|
|
57
|
+
lang = 'less';
|
|
58
|
+
preprocessor = 'compile-less';
|
|
59
|
+
}
|
|
60
|
+
else if (msg.includes('"stylus"')) {
|
|
61
|
+
lang = 'stylus';
|
|
62
|
+
preprocessor = 'compile-stylus';
|
|
63
|
+
}
|
|
64
|
+
if (lang) {
|
|
65
|
+
installHBuilderXPlugin(preprocessor);
|
|
66
|
+
return formatInstallHBuilderXPluginTips(lang, preprocessor);
|
|
67
|
+
}
|
|
68
|
+
return msg;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
function formatInstallHBuilderXPluginTips(lang, preprocessor) {
|
|
72
|
+
return `预编译器错误:代码使用了${lang}语言,但未安装相应的编译器插件,${supportAutoInstallPlugin() ? '正在从' : '请前往'}插件市场安装该插件:
|
|
73
|
+
https://ext.dcloud.net.cn/plugin?name=${preprocessor}`;
|
|
74
|
+
}
|
|
75
|
+
exports.formatInstallHBuilderXPluginTips = formatInstallHBuilderXPluginTips;
|
package/dist/hbx/env.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initModulePaths = exports.runByHBuilderX = exports.isInHBuilderX = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const module_1 = __importDefault(require("module"));
|
|
9
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
10
|
+
exports.isInHBuilderX = (0, uni_shared_1.once)(() => {
|
|
11
|
+
try {
|
|
12
|
+
const { name } = require(path_1.default.resolve(process.cwd(), '../about/package.json'));
|
|
13
|
+
if (name === 'about') {
|
|
14
|
+
process.env.UNI_HBUILDERX_PLUGINS = path_1.default.resolve(process.cwd(), '..');
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
// console.error(e)
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
});
|
|
23
|
+
exports.runByHBuilderX = (0, uni_shared_1.once)(() => {
|
|
24
|
+
return !!process.env.UNI_HBUILDERX_PLUGINS;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* 增加 node_modules
|
|
28
|
+
*/
|
|
29
|
+
function initModulePaths() {
|
|
30
|
+
if (!(0, exports.isInHBuilderX)()) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const Module = module.constructor.length > 1 ? module.constructor : module_1.default;
|
|
34
|
+
const nodeModulesPath = path_1.default.resolve(process.env.UNI_CLI_CONTEXT, 'node_modules');
|
|
35
|
+
const oldNodeModulePaths = Module._nodeModulePaths;
|
|
36
|
+
Module._nodeModulePaths = function (from) {
|
|
37
|
+
const paths = oldNodeModulePaths.call(this, from);
|
|
38
|
+
if (!paths.includes(nodeModulesPath)) {
|
|
39
|
+
paths.push(nodeModulesPath);
|
|
40
|
+
}
|
|
41
|
+
return paths;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.initModulePaths = initModulePaths;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.uniHBuilderXConsolePlugin = exports.formatInstallHBuilderXPluginTips = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
|
+
const console_1 = require("../vite/plugins/console");
|
|
20
|
+
__exportStar(require("./env"), exports);
|
|
21
|
+
var alias_1 = require("./alias");
|
|
22
|
+
Object.defineProperty(exports, "initModuleAlias", { enumerable: true, get: function () { return alias_1.initModuleAlias; } });
|
|
23
|
+
Object.defineProperty(exports, "installHBuilderXPlugin", { enumerable: true, get: function () { return alias_1.installHBuilderXPlugin; } });
|
|
24
|
+
Object.defineProperty(exports, "formatInstallHBuilderXPluginTips", { enumerable: true, get: function () { return alias_1.formatInstallHBuilderXPluginTips; } });
|
|
25
|
+
function uniHBuilderXConsolePlugin() {
|
|
26
|
+
return (0, console_1.uniConsolePlugin)({
|
|
27
|
+
filename(filename) {
|
|
28
|
+
filename = path_1.default.relative(process.env.UNI_INPUT_DIR, filename);
|
|
29
|
+
if (filename.startsWith('.') || path_1.default.isAbsolute(filename)) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
return (0, utils_1.normalizePath)(filename);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.uniHBuilderXConsolePlugin = uniHBuilderXConsolePlugin;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LogErrorOptions } from 'vite';
|
|
2
|
+
import { Formatter } from '../logs/format';
|
|
3
|
+
export declare const h5ServeFormatter: Formatter;
|
|
4
|
+
export declare const removeInfoFormatter: Formatter;
|
|
5
|
+
export declare const removeWarnFormatter: Formatter;
|
|
6
|
+
export declare const errorFormatter: Formatter<LogErrorOptions>;
|
package/dist/hbx/log.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.errorFormatter = exports.removeWarnFormatter = exports.removeInfoFormatter = exports.h5ServeFormatter = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const SIGNAL_H5_LOCAL = ' > Local:';
|
|
11
|
+
const SIGNAL_H5_NETWORK = ' > Network:';
|
|
12
|
+
const networkLogs = [];
|
|
13
|
+
exports.h5ServeFormatter = {
|
|
14
|
+
test(msg) {
|
|
15
|
+
return msg.includes(SIGNAL_H5_LOCAL) || msg.includes(SIGNAL_H5_NETWORK);
|
|
16
|
+
},
|
|
17
|
+
format(msg) {
|
|
18
|
+
if (msg.includes(SIGNAL_H5_NETWORK)) {
|
|
19
|
+
networkLogs.push(msg);
|
|
20
|
+
process.nextTick(() => {
|
|
21
|
+
if (networkLogs.length) {
|
|
22
|
+
// 延迟打印所有 network,仅最后一个 network 替换 > 为 -,通知 hbx
|
|
23
|
+
const len = networkLogs.length - 1;
|
|
24
|
+
networkLogs[len] = networkLogs[len].replace('>', '-');
|
|
25
|
+
console.log(networkLogs.join('\n'));
|
|
26
|
+
networkLogs.length = 0;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
return msg.replace('>', '-');
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const REMOVED_MSGS = [
|
|
35
|
+
'build started...',
|
|
36
|
+
(msg) => {
|
|
37
|
+
return /built in [0-9]+ms\./.test(msg);
|
|
38
|
+
},
|
|
39
|
+
'watching for file changes...',
|
|
40
|
+
];
|
|
41
|
+
exports.removeInfoFormatter = {
|
|
42
|
+
test(msg) {
|
|
43
|
+
return !!REMOVED_MSGS.find((m) => typeof m === 'string' ? msg.includes(m) : m(msg));
|
|
44
|
+
},
|
|
45
|
+
format() {
|
|
46
|
+
return '';
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const REMOVED_WARN_MSGS = [];
|
|
50
|
+
exports.removeWarnFormatter = {
|
|
51
|
+
test(msg) {
|
|
52
|
+
return !!REMOVED_WARN_MSGS.find((m) => msg.includes(m));
|
|
53
|
+
},
|
|
54
|
+
format() {
|
|
55
|
+
return '';
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
exports.errorFormatter = {
|
|
59
|
+
test(_, opts) {
|
|
60
|
+
return !!(opts && opts.error);
|
|
61
|
+
},
|
|
62
|
+
format(_, opts) {
|
|
63
|
+
return buildErrorMessage(opts.error, [], false);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
function buildErrorMessage(err, args = [], includeStack = true) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (err.plugin) {
|
|
69
|
+
args.push(`${picocolors_1.default.magenta('[plugin:' + err.plugin + ']')} ${picocolors_1.default.red(err.message)}`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
args.push(picocolors_1.default.red(err.message));
|
|
73
|
+
}
|
|
74
|
+
if (err.id) {
|
|
75
|
+
args.push(`at ${picocolors_1.default.cyan((0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, err.id.split('?')[0])) +
|
|
76
|
+
':' +
|
|
77
|
+
(((_a = err.loc) === null || _a === void 0 ? void 0 : _a.line) || 1) +
|
|
78
|
+
':' +
|
|
79
|
+
(((_b = err.loc) === null || _b === void 0 ? void 0 : _b.column) || 0))}`);
|
|
80
|
+
}
|
|
81
|
+
if (err.frame) {
|
|
82
|
+
args.push(picocolors_1.default.yellow(pad(err.frame)));
|
|
83
|
+
}
|
|
84
|
+
if (includeStack && err.stack) {
|
|
85
|
+
args.push(pad(cleanStack(err.stack)));
|
|
86
|
+
}
|
|
87
|
+
return args.join('\n');
|
|
88
|
+
}
|
|
89
|
+
function cleanStack(stack) {
|
|
90
|
+
return stack
|
|
91
|
+
.split(/\n/g)
|
|
92
|
+
.filter((l) => /^\s*at/.test(l))
|
|
93
|
+
.join('\n');
|
|
94
|
+
}
|
|
95
|
+
const splitRE = /\r?\n/;
|
|
96
|
+
function pad(source, n = 2) {
|
|
97
|
+
const lines = source.split(splitRE);
|
|
98
|
+
return lines.map((l) => ` `.repeat(n) + l).join(`\n`);
|
|
99
|
+
}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function initI18nOptions(platform: UniApp.PLATFORM, inputDir: string, warning?: boolean, withMessages?: boolean): {
|
|
2
|
+
locale: string;
|
|
3
|
+
locales: Record<string, Record<string, string>>;
|
|
4
|
+
delimiters: [string, string];
|
|
5
|
+
} | undefined;
|
|
6
|
+
export declare const initI18nOptionsOnce: typeof initI18nOptions;
|
|
7
|
+
export declare function isUniAppLocaleFile(filepath: string): boolean;
|
|
8
|
+
export declare function getLocaleFiles(cwd: string): string[];
|
|
9
|
+
export declare function initLocales(dir: string, withMessages?: boolean): Record<string, Record<string, string>>;
|
|
10
|
+
export declare function resolveI18nLocale(platfrom: UniApp.PLATFORM, locales: string[], locale?: string): string;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveI18nLocale = exports.initLocales = exports.getLocaleFiles = exports.isUniAppLocaleFile = exports.initI18nOptionsOnce = exports.initI18nOptions = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fast_glob_1 = require("fast-glob");
|
|
10
|
+
const shared_1 = require("@vue/shared");
|
|
11
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
12
|
+
const json_1 = require("./json");
|
|
13
|
+
const messages_1 = require("./messages");
|
|
14
|
+
function initI18nOptions(platform, inputDir, warning = false, withMessages = true) {
|
|
15
|
+
const locales = initLocales(path_1.default.resolve(inputDir, 'locale'), withMessages);
|
|
16
|
+
if (!Object.keys(locales).length) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const manifestJson = (0, json_1.parseManifestJsonOnce)(inputDir);
|
|
20
|
+
const fallbackLocale = manifestJson.fallbackLocale || manifestJson.locale;
|
|
21
|
+
const locale = resolveI18nLocale(platform, Object.keys(locales), fallbackLocale);
|
|
22
|
+
if (warning) {
|
|
23
|
+
if (!fallbackLocale) {
|
|
24
|
+
console.warn(messages_1.M['i18n.fallbackLocale.default'].replace('{locale}', locale));
|
|
25
|
+
}
|
|
26
|
+
else if (locale !== fallbackLocale) {
|
|
27
|
+
console.warn(messages_1.M['i18n.fallbackLocale.missing'].replace('{locale}', fallbackLocale));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
locale,
|
|
32
|
+
locales,
|
|
33
|
+
delimiters: uni_shared_1.I18N_JSON_DELIMITERS,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.initI18nOptions = initI18nOptions;
|
|
37
|
+
exports.initI18nOptionsOnce = (0, uni_shared_1.once)(initI18nOptions);
|
|
38
|
+
const localeJsonRE = /uni-app.*.json/;
|
|
39
|
+
function isUniAppLocaleFile(filepath) {
|
|
40
|
+
if (!filepath) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return localeJsonRE.test(path_1.default.basename(filepath));
|
|
44
|
+
}
|
|
45
|
+
exports.isUniAppLocaleFile = isUniAppLocaleFile;
|
|
46
|
+
function parseLocaleJson(filepath) {
|
|
47
|
+
let jsonObj = (0, json_1.parseJson)(fs_1.default.readFileSync(filepath, 'utf8'));
|
|
48
|
+
if (isUniAppLocaleFile(filepath)) {
|
|
49
|
+
jsonObj = jsonObj.common || {};
|
|
50
|
+
}
|
|
51
|
+
return jsonObj;
|
|
52
|
+
}
|
|
53
|
+
function getLocaleFiles(cwd) {
|
|
54
|
+
return (0, fast_glob_1.sync)('*.json', { cwd, absolute: true });
|
|
55
|
+
}
|
|
56
|
+
exports.getLocaleFiles = getLocaleFiles;
|
|
57
|
+
function initLocales(dir, withMessages = true) {
|
|
58
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
return fs_1.default.readdirSync(dir).reduce((res, filename) => {
|
|
62
|
+
if (path_1.default.extname(filename) === '.json') {
|
|
63
|
+
try {
|
|
64
|
+
const locale = path_1.default
|
|
65
|
+
.basename(filename)
|
|
66
|
+
.replace(/(uni-app.)?(.*).json/, '$2');
|
|
67
|
+
if (withMessages) {
|
|
68
|
+
(0, shared_1.extend)(res[locale] || (res[locale] = {}), parseLocaleJson(path_1.default.join(dir, filename)));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
res[locale] = {};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) { }
|
|
75
|
+
}
|
|
76
|
+
return res;
|
|
77
|
+
}, {});
|
|
78
|
+
}
|
|
79
|
+
exports.initLocales = initLocales;
|
|
80
|
+
function resolveI18nLocale(platfrom, locales, locale) {
|
|
81
|
+
if (locale && locales.includes(locale)) {
|
|
82
|
+
return locale;
|
|
83
|
+
}
|
|
84
|
+
const defaultLocales = ['zh-Hans', 'zh-Hant'];
|
|
85
|
+
if (platfrom === 'app' || platfrom === 'h5') {
|
|
86
|
+
defaultLocales.unshift('en');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// 小程序
|
|
90
|
+
defaultLocales.push('en');
|
|
91
|
+
}
|
|
92
|
+
return defaultLocales.find((locale) => locales.includes(locale)) || locales[0];
|
|
93
|
+
}
|
|
94
|
+
exports.resolveI18nLocale = resolveI18nLocale;
|