@infomaximum/package-cli 1.4.2 → 1.5.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/CHANGELOG.md +10 -0
- package/README.md +10 -2
- package/dist/arguments.js +7 -3
- package/dist/configs/webpack/buildPa/321/201kage.js +5 -5
- package/dist/configs/webpack/common.js +2 -42
- package/dist/configs/webpack/{devServer.js → sections/devServer.js} +1 -1
- package/dist/configs/webpack/sections/devtool.js +3 -0
- package/dist/configs/webpack/sections/plugins/minimizer.js +17 -0
- package/dist/configs/webpack/sections/plugins/modifyManifestWidget.js +14 -0
- package/dist/configs/webpack/sections/plugins/reactRefresh.js +4 -0
- package/dist/configs/webpack/sections/plugins/zipWidget.js +8 -0
- package/dist/const.js +5 -0
- package/dist/scripts/widget/build.js +23 -3
- package/dist/scripts/widget/start.js +19 -3
- package/dist/templates/widget/src/widgetIndex.js +2 -1
- package/dist/templates/widget/widgetPackageJson.js +2 -1
- package/package.json +4 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## [1.5.0](https://github.com/Infomaximum/package-cli/compare/v1.4.2...v1.5.0) (2023-12-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* добавлена возможность собрать пакет (виджет) с произвольным хостом и портом ([155be21](https://github.com/Infomaximum/package-cli/commit/155be21cc013fa70b3db3d1a5048810710fb0510))
|
package/README.md
CHANGED
|
@@ -12,15 +12,23 @@ Package-cli - предоставляет разработчикам набор
|
|
|
12
12
|
yarn add -D @infomaximum/package-cli
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Примеры использования
|
|
16
|
+
|
|
17
|
+
Сборка пакета с виджетом:
|
|
16
18
|
|
|
17
19
|
```bash
|
|
18
20
|
yarn im-package-cli widget build --entry ./src/index.tsx
|
|
19
21
|
```
|
|
20
22
|
|
|
23
|
+
Создание нового пакета с виджетом:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx @infomaximum/package-cli widget init project_name
|
|
27
|
+
```
|
|
28
|
+
|
|
21
29
|
## Вывод всех доступных команд
|
|
22
30
|
|
|
23
|
-
Вы можете использовать флаг `-h
|
|
31
|
+
Вы можете использовать флаг `-h`, чтобы просмотреть список всех доступных команд и их описаний:
|
|
24
32
|
|
|
25
33
|
```bash
|
|
26
34
|
yarn im-package-cli -h
|
package/dist/arguments.js
CHANGED
|
@@ -2,20 +2,24 @@ import { runBuild } from "./scripts/widget/build.js";
|
|
|
2
2
|
import { runDevServer } from "./scripts/widget/start.js";
|
|
3
3
|
import { runInitWidget } from "./scripts/widget/init/init.js";
|
|
4
4
|
import { systemRequire } from "./utils.js";
|
|
5
|
+
import { DEFAULT_HOST, DEFAULT_PORT } from "./const.js";
|
|
5
6
|
const packageJson = systemRequire("../package.json");
|
|
6
7
|
const registerWidgetCommands = (cli) => {
|
|
7
8
|
const widgetCommand = cli.command("widget");
|
|
8
9
|
const widgetBuildCommand = widgetCommand.command("build");
|
|
9
10
|
widgetBuildCommand
|
|
11
|
+
.description("Выполняет сборку пакета для дальнейшей загрузки в систему")
|
|
10
12
|
.option("-e, --entry <path>", "Путь до entrypoint")
|
|
13
|
+
.option("-p, --port <port>", "Порт который будет указан в манифесте виджета")
|
|
14
|
+
.option("--host <host>", "host который будет указан в манифесте виджета")
|
|
11
15
|
.description("Запускает сборку проекта")
|
|
12
16
|
.action((options) => runBuild(options));
|
|
13
17
|
const widgetStartCommand = widgetCommand.command("start");
|
|
14
18
|
widgetStartCommand
|
|
15
|
-
.description("
|
|
19
|
+
.description("Выполняет запуск проекта для разработки")
|
|
16
20
|
.option("-e, --entry <path>", "Путь до entrypoint")
|
|
17
|
-
.option("-p, --port <port>", "Порт на котором будет доступен виджет",
|
|
18
|
-
.option("--host <host>", "host на котором будет доступен виджет",
|
|
21
|
+
.option("-p, --port <port>", "Порт на котором будет доступен виджет", DEFAULT_PORT)
|
|
22
|
+
.option("--host <host>", "host на котором будет доступен виджет", DEFAULT_HOST)
|
|
19
23
|
.action((options) => runDevServer(options));
|
|
20
24
|
const widgetInitCommand = widgetCommand.command("init <project-directory>");
|
|
21
25
|
widgetInitCommand
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ZipPlugin from "zip-webpack-plugin";
|
|
2
2
|
import CopyWebpackPlugin from "copy-webpack-plugin";
|
|
3
|
-
import { archiveExt, buildWidgetConfigName, widgetArchiveName, } from "./common.js";
|
|
4
3
|
import path from "path";
|
|
5
4
|
import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
|
|
6
5
|
import { systemRequire } from "../../utils.js";
|
|
6
|
+
import { BUILD_ARCHIVE_EXT, BUILD_WIDGET_CONFIG_NAME, WIDGET_ARCHIVE_NAME, } from "../../const.js";
|
|
7
7
|
const packageFilename = "main.js";
|
|
8
8
|
export const getPackageConfig = (mode, PATHS) => {
|
|
9
9
|
const widgetVersion = systemRequire(PATHS.appPackageJson).version;
|
|
@@ -13,7 +13,7 @@ export const getPackageConfig = (mode, PATHS) => {
|
|
|
13
13
|
name: "package",
|
|
14
14
|
entry: [
|
|
15
15
|
PATHS.packageManifest,
|
|
16
|
-
path.resolve(PATHS.appBuild, `${
|
|
16
|
+
path.resolve(PATHS.appBuild, `${WIDGET_ARCHIVE_NAME}.${BUILD_ARCHIVE_EXT}`),
|
|
17
17
|
],
|
|
18
18
|
output: {
|
|
19
19
|
path: PATHS.appBuild,
|
|
@@ -30,7 +30,7 @@ export const getPackageConfig = (mode, PATHS) => {
|
|
|
30
30
|
},
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
test: new RegExp(`.${
|
|
33
|
+
test: new RegExp(`.${BUILD_ARCHIVE_EXT}$`, "i"),
|
|
34
34
|
type: "asset/resource",
|
|
35
35
|
generator: {
|
|
36
36
|
filename: "[name][ext]",
|
|
@@ -44,7 +44,7 @@ export const getPackageConfig = (mode, PATHS) => {
|
|
|
44
44
|
}),
|
|
45
45
|
new ZipPlugin({
|
|
46
46
|
filename: `${manifestPackageName}_${widgetVersion}`,
|
|
47
|
-
extension:
|
|
47
|
+
extension: BUILD_ARCHIVE_EXT,
|
|
48
48
|
exclude: [packageFilename],
|
|
49
49
|
}),
|
|
50
50
|
new JsonModifyWebpackPlugin({
|
|
@@ -59,6 +59,6 @@ export const getPackageConfig = (mode, PATHS) => {
|
|
|
59
59
|
],
|
|
60
60
|
}),
|
|
61
61
|
],
|
|
62
|
-
dependencies: [
|
|
62
|
+
dependencies: [BUILD_WIDGET_CONFIG_NAME],
|
|
63
63
|
};
|
|
64
64
|
};
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import ZipPlugin from "zip-webpack-plugin";
|
|
2
|
-
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
3
|
-
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
4
1
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
|
5
|
-
import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
6
2
|
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
|
|
7
|
-
import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
|
|
8
3
|
import webpack, {} from "webpack";
|
|
9
4
|
import { systemRequire } from "../../utils.js";
|
|
5
|
+
import { BUILD_WIDGET_CONFIG_NAME } from "../../const.js";
|
|
10
6
|
const { ProgressPlugin } = webpack;
|
|
11
7
|
const isProduction = (mode) => mode === "production";
|
|
12
8
|
const isDevelopment = (mode) => mode === "development";
|
|
13
|
-
export const buildWidgetConfigName = "build-widget";
|
|
14
|
-
export const widgetArchiveName = "widget";
|
|
15
|
-
export const archiveExt = "zip";
|
|
16
|
-
const DEV_SERVER_HOST = "0.0.0.0";
|
|
17
|
-
const DEV_SERVER_PORT = 5555;
|
|
18
9
|
export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
19
10
|
return {
|
|
20
11
|
mode,
|
|
21
|
-
name:
|
|
12
|
+
name: BUILD_WIDGET_CONFIG_NAME,
|
|
22
13
|
entry: [PATHS.moduleIndex, PATHS.manifestJson],
|
|
23
14
|
output: {
|
|
24
15
|
path: PATHS.appBuild,
|
|
@@ -37,23 +28,6 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
|
37
28
|
},
|
|
38
29
|
},
|
|
39
30
|
}),
|
|
40
|
-
new ZipPlugin({
|
|
41
|
-
filename: widgetArchiveName,
|
|
42
|
-
extension: archiveExt,
|
|
43
|
-
}),
|
|
44
|
-
isDevelopment(mode) && new ReactRefreshWebpackPlugin(),
|
|
45
|
-
isDevelopment(mode) &&
|
|
46
|
-
new JsonModifyWebpackPlugin({
|
|
47
|
-
matchers: [
|
|
48
|
-
{
|
|
49
|
-
matcher: /^manifest.json$/,
|
|
50
|
-
action: (currentJsonContent) => {
|
|
51
|
-
currentJsonContent.entry = `http://${DEV_SERVER_HOST}:${DEV_SERVER_PORT}/${currentJsonContent.entry}`;
|
|
52
|
-
return currentJsonContent;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
}),
|
|
57
31
|
].filter(Boolean),
|
|
58
32
|
module: {
|
|
59
33
|
rules: [
|
|
@@ -186,23 +160,9 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
|
186
160
|
},
|
|
187
161
|
],
|
|
188
162
|
},
|
|
189
|
-
optimization: isProduction(mode)
|
|
190
|
-
? {
|
|
191
|
-
minimize: true,
|
|
192
|
-
splitChunks: false,
|
|
193
|
-
minimizer: [
|
|
194
|
-
new TerserWebpackPlugin({
|
|
195
|
-
minify: TerserWebpackPlugin.terserMinify,
|
|
196
|
-
parallel: true,
|
|
197
|
-
}),
|
|
198
|
-
new CssMinimizerPlugin(),
|
|
199
|
-
],
|
|
200
|
-
}
|
|
201
|
-
: undefined,
|
|
202
163
|
resolve: {
|
|
203
164
|
extensions: [".tsx", ".ts", ".js"],
|
|
204
165
|
plugins: [new TsconfigPathsPlugin()],
|
|
205
166
|
},
|
|
206
|
-
devtool: isProduction(mode) ? false : "cheap-module-source-map",
|
|
207
167
|
};
|
|
208
168
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
2
|
+
import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
3
|
+
export const getMinimizer = () => {
|
|
4
|
+
return {
|
|
5
|
+
optimization: {
|
|
6
|
+
minimize: true,
|
|
7
|
+
splitChunks: false,
|
|
8
|
+
minimizer: [
|
|
9
|
+
new TerserWebpackPlugin({
|
|
10
|
+
minify: TerserWebpackPlugin.terserMinify,
|
|
11
|
+
parallel: true,
|
|
12
|
+
}),
|
|
13
|
+
new CssMinimizerPlugin(),
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
|
|
2
|
+
export const getModifyManifestWidgetPlugin = ({ host, port }) => {
|
|
3
|
+
return new JsonModifyWebpackPlugin({
|
|
4
|
+
matchers: [
|
|
5
|
+
{
|
|
6
|
+
matcher: /^manifest.json$/,
|
|
7
|
+
action: (currentJsonContent) => {
|
|
8
|
+
currentJsonContent.entry = `http://${host}:${port}/${currentJsonContent.entry}`;
|
|
9
|
+
return currentJsonContent;
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ZipPlugin from "zip-webpack-plugin";
|
|
2
|
+
import { BUILD_ARCHIVE_EXT, WIDGET_ARCHIVE_NAME } from "../../../../const.js";
|
|
3
|
+
export const getZipWidgetPlugin = () => {
|
|
4
|
+
return new ZipPlugin({
|
|
5
|
+
filename: WIDGET_ARCHIVE_NAME,
|
|
6
|
+
extension: BUILD_ARCHIVE_EXT,
|
|
7
|
+
});
|
|
8
|
+
};
|
package/dist/const.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export const CUSTOM_WIDGET_LIB_NAME = "@infomaximum/custom-widget";
|
|
2
2
|
export const CUSTOM_PACKAGE_CLI_LIB_NAME = "@infomaximum/package-cli";
|
|
3
|
+
export const BUILD_WIDGET_CONFIG_NAME = "build-widget";
|
|
4
|
+
export const WIDGET_ARCHIVE_NAME = "widget";
|
|
5
|
+
export const BUILD_ARCHIVE_EXT = "zip";
|
|
6
|
+
export const DEFAULT_HOST = "localhost";
|
|
7
|
+
export const DEFAULT_PORT = "5555";
|
|
@@ -4,18 +4,38 @@ import { generatePaths } from "../../paths.js";
|
|
|
4
4
|
import { getCommonWidgetConfig } from "../../configs/webpack/common.js";
|
|
5
5
|
import { getPackageConfig } from "../../configs/webpack/buildPaсkage.js";
|
|
6
6
|
import { checkLatestLibsVersion } from "../../utils.js";
|
|
7
|
+
import { merge } from "webpack-merge";
|
|
8
|
+
import { getModifyManifestWidgetPlugin } from "../../configs/webpack/sections/plugins/modifyManifestWidget.js";
|
|
9
|
+
import { getMinimizer } from "../../configs/webpack/sections/plugins/minimizer.js";
|
|
10
|
+
import { getZipWidgetPlugin } from "../../configs/webpack/sections/plugins/zipWidget.js";
|
|
7
11
|
export const runBuild = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
12
|
const mode = "production";
|
|
13
|
+
const { entry, host, port } = args;
|
|
9
14
|
yield checkLatestLibsVersion();
|
|
10
15
|
const PATHS = generatePaths({
|
|
11
|
-
entryPath:
|
|
16
|
+
entryPath: entry,
|
|
12
17
|
});
|
|
13
|
-
const
|
|
18
|
+
const pluginsSection = {
|
|
19
|
+
plugins: [getZipWidgetPlugin()],
|
|
20
|
+
};
|
|
21
|
+
if (host && port) {
|
|
22
|
+
pluginsSection.plugins.push(getModifyManifestWidgetPlugin({
|
|
23
|
+
host,
|
|
24
|
+
port,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
const configSections = [
|
|
14
28
|
getCommonWidgetConfig(mode, PATHS),
|
|
29
|
+
pluginsSection,
|
|
30
|
+
getMinimizer(),
|
|
31
|
+
];
|
|
32
|
+
const widgetConfig = merge(configSections);
|
|
33
|
+
const configs = [
|
|
34
|
+
widgetConfig,
|
|
15
35
|
getPackageConfig(mode, PATHS),
|
|
16
36
|
];
|
|
17
37
|
try {
|
|
18
|
-
build(
|
|
38
|
+
build(configs);
|
|
19
39
|
}
|
|
20
40
|
catch (error) {
|
|
21
41
|
console.error("Failed to compile.\n");
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import _webpack from "webpack";
|
|
2
|
+
import _webpack, {} from "webpack";
|
|
3
3
|
import { generatePaths } from "../../paths.js";
|
|
4
4
|
import WebpackDevServer from "webpack-dev-server";
|
|
5
|
-
import { getDevServerConfig } from "../../configs/webpack/devServer.js";
|
|
5
|
+
import { getDevServerConfig } from "../../configs/webpack/sections/devServer.js";
|
|
6
6
|
import { merge } from "webpack-merge";
|
|
7
7
|
import { getCommonWidgetConfig } from "../../configs/webpack/common.js";
|
|
8
8
|
import { checkLatestLibsVersion } from "../../utils.js";
|
|
9
|
+
import { getModifyManifestWidgetPlugin } from "../../configs/webpack/sections/plugins/modifyManifestWidget.js";
|
|
10
|
+
import { getReactRefresh } from "../../configs/webpack/sections/plugins/reactRefresh.js";
|
|
11
|
+
import { devtoolSection } from "../../configs/webpack/sections/devtool.js";
|
|
9
12
|
const { webpack } = _webpack;
|
|
10
13
|
export const runDevServer = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
14
|
const PATHS = generatePaths({
|
|
@@ -25,7 +28,20 @@ export const runDevServer = (options) => __awaiter(void 0, void 0, void 0, funct
|
|
|
25
28
|
const run = (PATHS, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
29
|
const { host, port } = options;
|
|
27
30
|
const mode = "development";
|
|
28
|
-
const
|
|
31
|
+
const pluginsSection = {
|
|
32
|
+
plugins: [
|
|
33
|
+
getModifyManifestWidgetPlugin({
|
|
34
|
+
host,
|
|
35
|
+
port,
|
|
36
|
+
}),
|
|
37
|
+
getReactRefresh(),
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const configWebpack = [
|
|
41
|
+
getCommonWidgetConfig(mode, PATHS),
|
|
42
|
+
pluginsSection,
|
|
43
|
+
devtoolSection,
|
|
44
|
+
];
|
|
29
45
|
const compiler = webpack(merge(configWebpack));
|
|
30
46
|
const devServerConfig = getDevServerConfig({
|
|
31
47
|
host,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { capitalizeHelperName } from "../../../scripts/widget/init/helpers.js";
|
|
1
2
|
export const WIDGET_INDEX_TEMPLATE = `\
|
|
2
3
|
import React from "react";
|
|
3
4
|
import ReactDOM from "react-dom/client";
|
|
@@ -36,7 +37,7 @@ class CustomWidget implements IWidget<Settings> {
|
|
|
36
37
|
public render(props: ICustomWidgetProps<Settings>) {
|
|
37
38
|
this.root?.render(
|
|
38
39
|
<React.StrictMode>
|
|
39
|
-
<div>
|
|
40
|
+
<div>{{ ${capitalizeHelperName} packageName}}</div>
|
|
40
41
|
</React.StrictMode>
|
|
41
42
|
);
|
|
42
43
|
}
|
|
@@ -6,7 +6,8 @@ export const WIDGET_PACKAGE_JSON_TEMPLATE = `\
|
|
|
6
6
|
"main": "src/index.tsx",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "im-package-cli widget build --entry ./src/index.tsx",
|
|
9
|
-
"
|
|
9
|
+
"build:dev": "im-package-cli widget build --port 5555 --host localhost --entry ./src/index.tsx",
|
|
10
|
+
"start": "im-package-cli widget start --port 5555 --host localhost --entry ./src/index.tsx",
|
|
10
11
|
"lint": "tsc --noEmit && eslint src/ --ext .ts,.tsx --quiet",
|
|
11
12
|
"test": "jest --passWithNoTests"
|
|
12
13
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infomaximum/package-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"exports": "./dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -75,8 +75,9 @@
|
|
|
75
75
|
"url": "git+https://github.com/Infomaximum/package-cli.git"
|
|
76
76
|
},
|
|
77
77
|
"keywords": [
|
|
78
|
-
"
|
|
79
|
-
"
|
|
78
|
+
"package",
|
|
79
|
+
"builder",
|
|
80
|
+
"widgets",
|
|
80
81
|
"cli"
|
|
81
82
|
],
|
|
82
83
|
"bugs": {
|