@yannick-z/modulo 0.2.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/README.md +311 -0
- package/bin/modulo.js +22 -0
- package/dist/index.js +773 -0
- package/package.json +36 -0
- package/rslib.config.ts +22 -0
- package/src/args/cmd.ts +16 -0
- package/src/args/get-framework-name.ts +19 -0
- package/src/args/index.ts +80 -0
- package/src/args/mode.ts +38 -0
- package/src/args/node_env.ts +15 -0
- package/src/args/preset.ts +26 -0
- package/src/args/target.ts +44 -0
- package/src/cli/init.ts +12 -0
- package/src/cli/pack-code.ts +17 -0
- package/src/config/example/example-config.ts +46 -0
- package/src/config/example/example-externals.ts +47 -0
- package/src/config/externals.ts +70 -0
- package/src/config/generate_config.ts +105 -0
- package/src/config/index.ts +27 -0
- package/src/config/preset/alias.ts +3 -0
- package/src/config/preset/dev-server.ts +6 -0
- package/src/config/preset/dirs.ts +12 -0
- package/src/config/preset/html.ts +19 -0
- package/src/config/preset/index.ts +23 -0
- package/src/config/preset/libs.ts +5 -0
- package/src/config/preset/minify.ts +24 -0
- package/src/config/preset/url.ts +4 -0
- package/src/config/type.ts +17 -0
- package/src/index.ts +13 -0
- package/src/initiator/create-config-file.ts +46 -0
- package/src/initiator/modify-scripts.ts +52 -0
- package/src/packer/collect-modules.ts +77 -0
- package/src/packer/get-externals-and-tags.ts +65 -0
- package/src/packer/lib.ts +84 -0
- package/src/packer/page.ts +98 -0
- package/src/packer/prepare.ts +76 -0
- package/src/tools/debug-log.ts +37 -0
- package/src/tools/file.ts +19 -0
- package/src/tools/find-path-root.ts +29 -0
- package/src/tools/get-framework-name.ts +14 -0
- package/src/tools/get-ui-plugin.ts +23 -0
- package/src/tools/json.ts +11 -0
- package/src/tools/merge-user-config.ts +21 -0
- package/src/tools/omit-root-path.ts +11 -0
- package/src/tools/panic.ts +11 -0
- package/src/tools/string.ts +3 -0
- package/src/type/guard.ts +11 -0
- package/template/index.html +12 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { get_packagejson } from "../config/index.ts";
|
|
2
|
+
import { PANIC_IF } from "./panic.ts";
|
|
3
|
+
|
|
4
|
+
export function get_framework_name() {
|
|
5
|
+
const { dependencies } = get_packagejson();
|
|
6
|
+
|
|
7
|
+
PANIC_IF(
|
|
8
|
+
!("vue" in dependencies || "react" in dependencies),
|
|
9
|
+
"package.json中未识别到支持的ui库信息, 当前只支持vue和react"
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// 该项目是vue还是react项目
|
|
13
|
+
return "vue" in dependencies ? "vue" : "react";
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PluginReactOptions, pluginReact } from "@rsbuild/plugin-react";
|
|
2
|
+
import { type PluginVueOptions, pluginVue2 } from "@rsbuild/plugin-vue2";
|
|
3
|
+
import { get_global_config, get_packagejson } from "../config/index.ts";
|
|
4
|
+
import { get_framework_name } from "./get-framework-name.ts";
|
|
5
|
+
import { PANIC_IF } from "./panic.ts";
|
|
6
|
+
import type { ModuloArgs_Pack } from "../args/index.ts";
|
|
7
|
+
|
|
8
|
+
export function framework_plugin(
|
|
9
|
+
args: ModuloArgs_Pack,
|
|
10
|
+
options?: PluginVueOptions | PluginReactOptions
|
|
11
|
+
) {
|
|
12
|
+
const { dependencies } = get_packagejson();
|
|
13
|
+
const framework_name = get_framework_name();
|
|
14
|
+
|
|
15
|
+
// 必须使用指定版本号的ui库,以优化代码产出
|
|
16
|
+
const version = dependencies[framework_name];
|
|
17
|
+
const global_config = get_global_config(args);
|
|
18
|
+
PANIC_IF(
|
|
19
|
+
global_config.ui_lib[framework_name] !== version,
|
|
20
|
+
"package.json中只允许使用固定版本号, 并且只支持vue-2.7.16和react-17.0.2"
|
|
21
|
+
);
|
|
22
|
+
return framework_name === "vue" ? pluginVue2(options) : pluginReact(options);
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PANIC_IF } from "./panic.ts";
|
|
2
|
+
|
|
3
|
+
export function merge_user_config(target: any, input: any) {
|
|
4
|
+
for (const key in input) {
|
|
5
|
+
const from = input[key];
|
|
6
|
+
const to = target[key];
|
|
7
|
+
if (typeof from !== typeof to || !(key in target)) {
|
|
8
|
+
target[key] = from;
|
|
9
|
+
continue;
|
|
10
|
+
} else {
|
|
11
|
+
if (Array.isArray(to)) {
|
|
12
|
+
PANIC_IF(!Array.isArray(from));
|
|
13
|
+
target[key] = [...to, ...from];
|
|
14
|
+
} else if (typeof to === "object") {
|
|
15
|
+
merge_user_config(to, from);
|
|
16
|
+
} else {
|
|
17
|
+
target[key] = from;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const root_path = process.cwd();
|
|
2
|
+
export function omit_root_path(path: string) {
|
|
3
|
+
// return relative path
|
|
4
|
+
return path.replace(root_path, "");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function omit_root_path_for_entries(entries: Record<string, string>) {
|
|
8
|
+
return Object.fromEntries(
|
|
9
|
+
Object.entries(entries).map(([key, value]) => [key, omit_root_path(value)])
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { exit } from 'node:process';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
|
|
4
|
+
const alert = '! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !';
|
|
5
|
+
|
|
6
|
+
export function PANIC_IF(status = false, msg = `SOMETHING'S WRONG`, halt = true): asserts status is false {
|
|
7
|
+
if (status) {
|
|
8
|
+
console.log(pc.bgRed(pc.white(`\n${alert}\n\n${msg}\n\n${alert}`)), '\n');
|
|
9
|
+
halt && exit(1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function is_string(data: unknown): data is string {
|
|
2
|
+
return typeof data === "string";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function is_true_string(data: unknown): data is string {
|
|
6
|
+
return typeof data === "string" && !!data;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function is_record(data: unknown): data is Record<string, unknown> {
|
|
10
|
+
return !!data && typeof data === "object";
|
|
11
|
+
}
|
package/tsconfig.json
ADDED