@infomaximum/package-cli 2.23.1 → 2.24.0-1
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/CHANGELOG.md +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/widget/commands/build_script.d.ts +7 -0
- package/dist/widget/commands/build_script.js +12 -0
- package/dist/widget/commands.js +2 -0
- package/dist/widget/configs/file.d.ts +2 -0
- package/dist/widget/configs/webpack/common.d.ts +1 -1
- package/dist/widget/configs/webpack/common.js +4 -6
- package/dist/widget/configs/webpack/sections/plugins/minimizer.d.ts +1 -1
- package/dist/widget/scripts/build_script.d.ts +3 -0
- package/dist/widget/scripts/build_script.js +39 -0
- package/dist/widget/scripts/init/actions.js +1 -1
- package/dist/widget/templates/src/widgetIndex.d.ts +1 -1
- package/dist/widget/templates/src/widgetIndex.js +3 -1
- package/dist/widget/templates/widgetPackageJson.d.ts +1 -1
- package/dist/widget/templates/widgetPackageJson.js +10 -5
- package/dist/widget/templates/widgetRCConfig.js +15 -11
- package/dist/widget/widgetPaths.d.ts +2 -1
- package/package.json +6 -3
- package/schemas/widgetConfigSchema.json +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.24.0-1](https://github.com/Infomaximum/package-cli/compare/v2.24.0-0...v2.24.0-1) (2025-06-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* убрано копирование ресурсов при сборке скрипта ([9084cab](https://github.com/Infomaximum/package-cli/commit/9084cab37462fadf4ad15169ea7d701a18698199))
|
|
11
|
+
|
|
12
|
+
## [2.24.0-0](https://github.com/Infomaximum/package-cli/compare/v2.23.1...v2.24.0-0) (2025-06-20)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* добавлена команда по сборки скрипта виджета ([2810b69](https://github.com/Infomaximum/package-cli/commit/2810b69d7637947f1b143eec064439338057f508))
|
|
18
|
+
* добавлена поддержка externals ([897eb0c](https://github.com/Infomaximum/package-cli/commit/897eb0cba2b3921f47c6d10d02de860b50d4c151))
|
|
19
|
+
|
|
5
20
|
### [2.23.1](https://github.com/Infomaximum/package-cli/compare/v2.23.0...v2.23.1) (2025-06-02)
|
|
6
21
|
|
|
7
22
|
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { configMergeWithOptionsCommon, type InputCommonOptions } from "./common.js";
|
|
3
|
+
export type InputBuildScriptOptions = {
|
|
4
|
+
buildDir?: string;
|
|
5
|
+
} & InputCommonOptions;
|
|
6
|
+
export type MergedBuildScriptOptions = ReturnType<typeof configMergeWithOptionsCommon>;
|
|
7
|
+
export declare const registerWidgetBuildScriptCommand: (widgetCommand: Command) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getConfigFromFile } from "../configs/file.js";
|
|
2
|
+
import { configMergeWithOptionsCommon, registerCommonOption, } from "./common.js";
|
|
3
|
+
import { runBuildScript } from "../scripts/build_script.js";
|
|
4
|
+
export const registerWidgetBuildScriptCommand = (widgetCommand) => {
|
|
5
|
+
const widgetBuildScriptCommand = widgetCommand.command("build-script");
|
|
6
|
+
const config = getConfigFromFile();
|
|
7
|
+
registerCommonOption(widgetBuildScriptCommand);
|
|
8
|
+
widgetBuildScriptCommand
|
|
9
|
+
.description("Выполняет сборку js файла виджета для публикации")
|
|
10
|
+
.option("--build-dir <buildDirPath>", "путь до директории в которую будет собран пакет")
|
|
11
|
+
.action((options) => runBuildScript(configMergeWithOptionsCommon(config, options), config));
|
|
12
|
+
};
|
package/dist/widget/commands.js
CHANGED
|
@@ -2,10 +2,12 @@ import { registerWidgetBuildCommand } from "./commands/build.js";
|
|
|
2
2
|
import { registerWidgetStartCommand } from "./commands/start.js";
|
|
3
3
|
import { registerWidgetInitCommand } from "./commands/init.js";
|
|
4
4
|
import { registerWidgetReleaseCommand } from "./commands/release.js";
|
|
5
|
+
import { registerWidgetBuildScriptCommand } from "./commands/build_script.js";
|
|
5
6
|
export const registerWidgetCommands = (cli) => {
|
|
6
7
|
const widgetCommand = cli.command("widget");
|
|
7
8
|
registerWidgetBuildCommand(widgetCommand);
|
|
8
9
|
registerWidgetStartCommand(widgetCommand);
|
|
9
10
|
registerWidgetInitCommand(widgetCommand);
|
|
10
11
|
registerWidgetReleaseCommand(widgetCommand);
|
|
12
|
+
registerWidgetBuildScriptCommand(widgetCommand);
|
|
11
13
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SystemWidgetExternals } from "@infomaximum/widget-sdk";
|
|
1
2
|
export type WidgetRCConfig = {
|
|
2
3
|
entry: string;
|
|
3
4
|
widgetManifest: string;
|
|
@@ -7,5 +8,6 @@ export type WidgetRCConfig = {
|
|
|
7
8
|
buildDir: string;
|
|
8
9
|
port: number;
|
|
9
10
|
host: string;
|
|
11
|
+
externals?: Partial<SystemWidgetExternals>;
|
|
10
12
|
};
|
|
11
13
|
export declare const getConfigFromFile: () => WidgetRCConfig | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Configuration } from "webpack";
|
|
2
2
|
import type { Mode } from "../../../paths.js";
|
|
3
3
|
import type { WidgetPaths } from "../../widgetPaths.js";
|
|
4
|
-
export declare const getCommonWidgetConfig: (mode: Mode, PATHS: WidgetPaths) => Configuration;
|
|
4
|
+
export declare const getCommonWidgetConfig: (mode: Mode, PATHS: WidgetPaths, isCopyResources?: boolean) => Configuration;
|
|
@@ -9,7 +9,7 @@ import { WIDGET_OUTPUT_FILE_NAME, WIDGET_OUTPUT_FULL_FILE_NAME, } from "../../co
|
|
|
9
9
|
const { ProgressPlugin } = webpack;
|
|
10
10
|
const isProduction = (mode) => mode === "production";
|
|
11
11
|
const isDevelopment = (mode) => mode === "development";
|
|
12
|
-
export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
12
|
+
export const getCommonWidgetConfig = (mode, PATHS, isCopyResources = true) => {
|
|
13
13
|
const manifestEntry = systemRequire(PATHS.widgetManifestJsonPath).entry;
|
|
14
14
|
const filename = isProduction(mode)
|
|
15
15
|
? `${WIDGET_OUTPUT_FILE_NAME}.[contenthash].js`
|
|
@@ -34,7 +34,8 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
}),
|
|
37
|
-
|
|
37
|
+
isCopyResources &&
|
|
38
|
+
PATHS.widgetResourcesPath &&
|
|
38
39
|
PATHS.widgetResourcesDirName &&
|
|
39
40
|
new CopyWebpackPlugin({
|
|
40
41
|
patterns: [
|
|
@@ -115,12 +116,9 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
|
115
116
|
resourceQuery: /url/,
|
|
116
117
|
parser: {
|
|
117
118
|
dataUrlCondition: {
|
|
118
|
-
maxSize:
|
|
119
|
+
maxSize: Infinity,
|
|
119
120
|
},
|
|
120
121
|
},
|
|
121
|
-
generator: {
|
|
122
|
-
filename: "build/static/[hash][ext][query]",
|
|
123
|
-
},
|
|
124
122
|
},
|
|
125
123
|
{
|
|
126
124
|
type: "asset/source",
|
|
@@ -3,7 +3,7 @@ import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
|
3
3
|
export declare const getMinimizer: () => {
|
|
4
4
|
optimization: {
|
|
5
5
|
minimize: boolean;
|
|
6
|
-
splitChunks:
|
|
6
|
+
splitChunks: false;
|
|
7
7
|
minimizer: (TerserWebpackPlugin<import("terser").MinifyOptions> | CssMinimizerPlugin<CssMinimizerPlugin.CssNanoOptionsExtended>)[];
|
|
8
8
|
};
|
|
9
9
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import {} from "webpack";
|
|
3
|
+
import {} from "../../paths.js";
|
|
4
|
+
import { merge } from "webpack-merge";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { getCommonWidgetConfig } from "../configs/webpack/common.js";
|
|
7
|
+
import { getMinimizer } from "../configs/webpack/sections/plugins/minimizer.js";
|
|
8
|
+
import { generateWidgetPaths } from "../widgetPaths.js";
|
|
9
|
+
import { runWebpackBuild } from "../../utils.js";
|
|
10
|
+
import { WIDGET_OUTPUT_FULL_FILE_NAME } from "../const.js";
|
|
11
|
+
export const runBuildScript = (args, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
var _a;
|
|
13
|
+
const mode = "production";
|
|
14
|
+
const WIDGET_PATHS = generateWidgetPaths(args);
|
|
15
|
+
const sections = {
|
|
16
|
+
entry: WIDGET_PATHS.moduleIndex,
|
|
17
|
+
output: {
|
|
18
|
+
filename: WIDGET_OUTPUT_FULL_FILE_NAME,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const configSections = [
|
|
22
|
+
getCommonWidgetConfig(mode, WIDGET_PATHS, false),
|
|
23
|
+
{
|
|
24
|
+
externals: (_a = config === null || config === void 0 ? void 0 : config.externals) !== null && _a !== void 0 ? _a : {},
|
|
25
|
+
externalsType: "window",
|
|
26
|
+
},
|
|
27
|
+
sections,
|
|
28
|
+
getMinimizer(),
|
|
29
|
+
];
|
|
30
|
+
const widgetConfig = merge(configSections);
|
|
31
|
+
try {
|
|
32
|
+
yield runWebpackBuild(widgetConfig);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(chalk.red("\nFailed to compile.\n"));
|
|
36
|
+
console.error(chalk.red(error));
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_INDEX_TEMPLATE = "import React from \"react\";\nimport ReactDOM from \"react-dom/client\";\nimport \"./index.css\";\nimport {\n type IWidget,\n type ICustomWidgetProps,\n} from \"@infomaximum/widget-sdk\";\nimport manifest from \"../manifest.json\";\nimport { type WidgetSettings } from \"./definition/settings\";\nimport { Definition } from \"./definition/definition\";\n\nclass CustomWidget implements IWidget<WidgetSettings> {\n public static definition = new Definition();\n\n private root: ReactDOM.Root | null = null;\n\n public initialize(container: HTMLElement) {\n this.root = ReactDOM.createRoot(container);\n }\n\n public update(\n container: HTMLElement,\n props: ICustomWidgetProps<WidgetSettings>\n ) {\n this.render(props);\n }\n\n public mount(\n container: HTMLElement,\n props: ICustomWidgetProps<WidgetSettings>\n ) {\n this.render(props);\n }\n\n public unmount() {\n this.root?.unmount();\n }\n\n private render(props: ICustomWidgetProps<WidgetSettings>) {\n this.root?.render(\n <React.StrictMode>\n <div>{{ capitalize packageName}}</div>\n </React.StrictMode>\n );\n }\n}\n\nwindow.im.widget.defineWidget(manifest.uuid, CustomWidget);\n";
|
|
1
|
+
export declare const WIDGET_INDEX_TEMPLATE = "import React from \"react\";\nimport ReactDOM from \"react-dom/client\";\nimport \"./index.css\";\nimport {\n type IWidget,\n type ICustomWidgetProps,\n} from \"@infomaximum/widget-sdk\";\nimport manifest from \"../manifest.json\";\nimport { type WidgetSettings } from \"./definition/settings\";\nimport { Definition } from \"./definition/definition\";\n\nclass CustomWidget implements IWidget<WidgetSettings> {\n public static definition = new Definition();\n\n private root: ReactDOM.Root | null = null;\n\n public initialize(container: HTMLElement) {\n this.root = ReactDOM.createRoot(container);\n }\n\n public update(\n container: HTMLElement,\n props: ICustomWidgetProps<WidgetSettings>\n ) {\n this.render(props);\n }\n\n public mount(\n container: HTMLElement,\n props: ICustomWidgetProps<WidgetSettings>\n ) {\n this.render(props);\n }\n\n public unmount() {\n this.root?.unmount();\n }\n\n private render(props: ICustomWidgetProps<WidgetSettings>) {\n this.root?.render(\n <React.StrictMode>\n <div>{{ capitalize packageName}}</div>\n </React.StrictMode>\n );\n }\n}\n\nwindow.im.widget.defineWidget(manifest.uuid, CustomWidget, {\n manifest,\n});\n";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_PACKAGE_JSON_TEMPLATE = "{\n \"name\": \"template_widget\",\n \"version\": \"1.0.0\",\n \"
|
|
1
|
+
export declare const WIDGET_PACKAGE_JSON_TEMPLATE = "{\n \"name\": \"template_widget\",\n \"version\": \"1.0.0\",\n \"main\": \"build/widget.js\",\n \"files\": [\n \"build\",\n \"manifest.json\"\n ],\n \"scripts\": {\n \"build\": \"im-package-cli widget build\",\n \"build:script\": \"im-package-cli widget build-script\",\n \"build:dev\": \"im-package-cli widget build --dev\",\n \"start\": \"im-package-cli widget start\",\n \"lint\": \"tsc --noEmit && eslint src/ --ext .ts,.tsx --quiet\",\n \"test\": \"jest --passWithNoTests\",\n \"release\": \"im-package-cli widget release\",\n \"changelog\":\"im-package-cli widget release --dry-run\",\n \"prepublishOnly\": \"npm run build:script\"\n },\n \"dependencies\": {\n \"@infomaximum/widget-sdk\": \"{{widgetSDKVersion}}\",\n \"react\": \"18.3.1\",\n \"react-dom\": \"18.3.1\"\n },\n \"devDependencies\": {\n \"@babel/core\": \"7.25.2\",\n \"@babel/preset-env\": \"7.25.4\",\n \"@babel/preset-react\": \"7.24.7\",\n \"@babel/preset-typescript\": \"7.24.7\",\n \"@infomaximum/package-cli\": \"^{{packageCliVersion}}\",\n \"@types/jest\": \"29.5.11\",\n \"@types/react\": \"18.3.4\",\n \"@types/react-dom\": \"18.3.0\",\n \"@typescript-eslint/eslint-plugin\": \"8.3.0\",\n \"@typescript-eslint/parser\": \"8.3.0\",\n \"eslint\": \"8.57.0\",\n \"eslint-plugin-react\": \"7.35.0\",\n \"eslint-plugin-react-hooks\": \"4.6.2\",\n \"jest\": \"29.7.0\",\n \"jest-canvas-mock\": \"2.5.2\",\n \"jest-environment-jsdom\": \"29.7.0\",\n \"jest-environment-jsdom-global\": \"4.0.0\",\n \"prettier\": \"3.1.1\",\n \"typescript\": \"5.5.4\"\n },\n \"browserslist\": [\n \"defaults and supports es6-module\"\n ]\n}\n";
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import { CUSTOM_PACKAGE_CLI_LIB_NAME } from "../../const.js";
|
|
2
|
-
import { WIDGET_SDK_LIB_NAME } from "../const.js";
|
|
1
|
+
import { CUSTOM_PACKAGE_CLI_LIB_NAME, DEFAULT_BUILD_DIR_NAME, } from "../../const.js";
|
|
2
|
+
import { WIDGET_OUTPUT_FULL_FILE_NAME, WIDGET_SDK_LIB_NAME } from "../const.js";
|
|
3
3
|
export const WIDGET_PACKAGE_JSON_TEMPLATE = `\
|
|
4
4
|
{
|
|
5
5
|
"name": "template_widget",
|
|
6
6
|
"version": "1.0.0",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"main": "${DEFAULT_BUILD_DIR_NAME}/${WIDGET_OUTPUT_FULL_FILE_NAME}",
|
|
8
|
+
"files": [
|
|
9
|
+
"build",
|
|
10
|
+
"manifest.json"
|
|
11
|
+
],
|
|
9
12
|
"scripts": {
|
|
10
13
|
"build": "im-package-cli widget build",
|
|
14
|
+
"build:script": "im-package-cli widget build-script",
|
|
11
15
|
"build:dev": "im-package-cli widget build --dev",
|
|
12
16
|
"start": "im-package-cli widget start",
|
|
13
17
|
"lint": "tsc --noEmit && eslint src/ --ext .ts,.tsx --quiet",
|
|
14
18
|
"test": "jest --passWithNoTests",
|
|
15
19
|
"release": "im-package-cli widget release",
|
|
16
|
-
"changelog":"im-package-cli widget release --dry-run"
|
|
20
|
+
"changelog":"im-package-cli widget release --dry-run",
|
|
21
|
+
"prepublishOnly": "npm run build:script"
|
|
17
22
|
},
|
|
18
23
|
"dependencies": {
|
|
19
24
|
"${WIDGET_SDK_LIB_NAME}": "{{widgetSDKVersion}}",
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { CUSTOM_PACKAGE_CLI_LIB_NAME, DEFAULT_BUILD_DIR_NAME, MANIFEST_JSON_FILE_NAME, } from "../../const.js";
|
|
2
2
|
import { WIDGET_DEFAULT_HOST, WIDGET_DEFAULT_PORT } from "../const.js";
|
|
3
3
|
export const WIDGET_RC_CONFIG = `\
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
}
|
|
4
|
+
//@ts-check
|
|
5
|
+
|
|
6
|
+
/** @type {import("${CUSTOM_PACKAGE_CLI_LIB_NAME}").WidgetRCConfig} */
|
|
7
|
+
const config = {
|
|
8
|
+
entry: "src/index.tsx",
|
|
9
|
+
widgetManifest: "${MANIFEST_JSON_FILE_NAME}",
|
|
10
|
+
packageDir: "package",
|
|
11
|
+
packageManifest: "package/${MANIFEST_JSON_FILE_NAME}",
|
|
12
|
+
assetsDir: "_resources",
|
|
13
|
+
buildDir: "${DEFAULT_BUILD_DIR_NAME}",
|
|
14
|
+
port: ${+WIDGET_DEFAULT_PORT},
|
|
15
|
+
host: "${WIDGET_DEFAULT_HOST}",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = config;
|
|
15
19
|
`;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { MergedBuildOptions } from "./commands/build.js";
|
|
2
2
|
import type { MergedStartOptions } from "./commands/start.js";
|
|
3
|
+
import type { MergedBuildScriptOptions } from "./commands/build_script.js";
|
|
3
4
|
export type WidgetPaths = ReturnType<typeof generateWidgetPaths>;
|
|
4
|
-
type Options = MergedBuildOptions | MergedStartOptions;
|
|
5
|
+
type Options = MergedBuildOptions | MergedStartOptions | MergedBuildScriptOptions;
|
|
5
6
|
export declare function generateWidgetPaths({ entry, assetsDir, widgetManifest, buildDir, }: Options): {
|
|
6
7
|
moduleIndex: string;
|
|
7
8
|
widgetManifestJsonPath: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infomaximum/package-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0-1",
|
|
4
4
|
"exports": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
"dev": "tsc",
|
|
19
19
|
"dev:w": "npm run dev -- -w",
|
|
20
20
|
"build": "rimraf dist && npm run dev",
|
|
21
|
-
"release": "tsc --noEmit && standard-version
|
|
21
|
+
"release": "tsc --noEmit && standard-version",
|
|
22
|
+
"release:rc": "standard-version -p",
|
|
22
23
|
"lint": "tsc --noEmit",
|
|
23
|
-
"prettier": "prettier --find-config-path --write 'lib/**/*'"
|
|
24
|
+
"prettier": "prettier --find-config-path --write 'lib/**/*'",
|
|
25
|
+
"prepublishOnly": "npm run lint && npm run build"
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"@babel/core": "^7.23.6",
|
|
@@ -71,6 +73,7 @@
|
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
75
|
"@infomaximum/integration-sdk": "^2.3.0",
|
|
76
|
+
"@infomaximum/widget-sdk": "5.26.0-0",
|
|
74
77
|
"@types/babel__core": "^7.20.5",
|
|
75
78
|
"@types/fs-extra": "^11.0.4",
|
|
76
79
|
"@types/node": "^20.9.0",
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"host": {
|
|
40
40
|
"type": "string",
|
|
41
41
|
"description": "хост по которому будет доступен сервер разработки"
|
|
42
|
+
},
|
|
43
|
+
"externals": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"additionalProperties": true,
|
|
46
|
+
"description": "исключает указанные зависимости из сборки, предполагая их наличие в окружении. Используется для уменьшения размера бандла. Актуально только при сборке скрипта. (https://webpack.js.org/configuration/externals/)"
|
|
42
47
|
}
|
|
43
48
|
},
|
|
44
49
|
"required": [
|