@infomaximum/package-cli 2.0.1 → 2.1.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 CHANGED
@@ -2,6 +2,29 @@
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.1.1](https://github.com/Infomaximum/package-cli/compare/v2.1.0...v2.1.1) (2024-03-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * исправлено копирование директории с ресурсами во время сборки ([e351a48](https://github.com/Infomaximum/package-cli/commit/e351a48d5bcb274b03e0ee2a97361d6a5c526ada))
11
+
12
+ ## [2.1.0](https://github.com/Infomaximum/package-cli/compare/v2.0.1...v2.1.0) (2024-03-05)
13
+
14
+
15
+ ### Features
16
+
17
+ * добавление api_version в манифест при сборке для обратной совместимости ([7d2a9d8](https://github.com/Infomaximum/package-cli/commit/7d2a9d8ea1bf9bf6399057df89bbb8fe02fc51e7))
18
+ * новый путь регистрации виджета ([1b2cf4a](https://github.com/Infomaximum/package-cli/commit/1b2cf4a71ba101a3e16f16d9fede3b64f3a546c8))
19
+ * sdk_version -> manifest.json ([ee5aa42](https://github.com/Infomaximum/package-cli/commit/ee5aa42b1a71db5c3ed96b5ed6ea18b9f68c770f))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * 10 секунд ожидание ([f829632](https://github.com/Infomaximum/package-cli/commit/f829632b7c314aa806d506a9bbcc0433c91a1104))
25
+ * без дополнительных свойств ([8a2b08d](https://github.com/Infomaximum/package-cli/commit/8a2b08d74171ed9b5c94e43292d1032f4ed75e90))
26
+ * типизация ([c7482c5](https://github.com/Infomaximum/package-cli/commit/c7482c50647c0f6461fb42de521bd511f87cc08a))
27
+
5
28
  ### [2.0.1](https://github.com/Infomaximum/package-cli/compare/v2.0.0...v2.0.1) (2024-03-05)
6
29
 
7
30
 
package/dist/utils.js CHANGED
@@ -29,7 +29,7 @@ export function safeWriteFile(pathToFile, contents, options) {
29
29
  export function getLatestVersionOfLibrary(libraryName) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  const { stdout } = yield execPromise(`npm show -j -p ${libraryName} version`, {
32
- timeout: 5000,
32
+ timeout: 10000,
33
33
  });
34
34
  return JSON.parse(stdout);
35
35
  });
@@ -3,7 +3,7 @@ import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
3
3
  import CopyWebpackPlugin from "copy-webpack-plugin";
4
4
  import webpack, {} from "webpack";
5
5
  import { cssLoaders } from "./sections/loaders/cssLoaders.js";
6
- import { systemRequire } from "../../../utils.js";
6
+ import { compact, systemRequire } from "../../../utils.js";
7
7
  import { MANIFEST_REG_EXP } from "../../../const.js";
8
8
  import path from "path";
9
9
  const { ProgressPlugin } = webpack;
@@ -19,7 +19,7 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
19
19
  asyncChunks: false,
20
20
  clean: true,
21
21
  },
22
- plugins: [
22
+ plugins: compact([
23
23
  new ProgressPlugin(),
24
24
  new ForkTsCheckerWebpackPlugin({
25
25
  typescript: {
@@ -31,17 +31,18 @@ export const getCommonWidgetConfig = (mode, PATHS) => {
31
31
  },
32
32
  }),
33
33
  PATHS.widgetResourcesPath &&
34
+ PATHS.widgetResourcesDirName &&
34
35
  new CopyWebpackPlugin({
35
36
  patterns: [
36
37
  {
37
38
  from: PATHS.widgetResourcesPath,
38
39
  toType: "dir",
39
- to: path.basename(PATHS.widgetResourcesPath),
40
+ to: PATHS.widgetResourcesDirName,
40
41
  noErrorOnMissing: true,
41
42
  },
42
43
  ],
43
44
  }),
44
- ].filter(Boolean),
45
+ ]),
45
46
  module: {
46
47
  rules: [
47
48
  {
@@ -1,7 +1,9 @@
1
1
  import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
2
2
  import { DEV_POSTFIX } from "../../../../../const.js";
3
3
  import { removeServiceFieldsForDevelopment } from "../../../../../utils.js";
4
- export const getModifyManifestWidgetPlugin = ({ host, port, isBuildDevMode, }) => {
4
+ import { WIDGET_SDK_VERSION_FIELD_NAME } from "../../../../const.js";
5
+ import { getSdkVersionFromPackageJson } from "../../../../utils.js";
6
+ export const getModifyManifestWidgetPlugin = ({ host, port, isBuildDevMode, WIDGET_PATHS, }) => {
5
7
  return new JsonModifyWebpackPlugin({
6
8
  matchers: [
7
9
  {
@@ -18,6 +20,9 @@ export const getModifyManifestWidgetPlugin = ({ host, port, isBuildDevMode, }) =
18
20
  });
19
21
  }
20
22
  }
23
+ const sdkVersion = getSdkVersionFromPackageJson(WIDGET_PATHS.appPackageJson);
24
+ currentJsonContent[WIDGET_SDK_VERSION_FIELD_NAME] = sdkVersion;
25
+ currentJsonContent["api_version"] = sdkVersion;
21
26
  removeServiceFieldsForDevelopment(currentJsonContent);
22
27
  return currentJsonContent;
23
28
  },
@@ -2,12 +2,12 @@ import ZipPlugin from "zip-webpack-plugin";
2
2
  import { WIDGET_ARCHIVE_NAME } from "../../../../const.js";
3
3
  import { BUILD_ARCHIVE_EXT, MANIFEST_JSON_FILE_NAME, } from "../../../../../const.js";
4
4
  import { compact } from "../../../../../utils.js";
5
- export const getZipWidgetPlugin = ({ isOnlyManifest, widgetResourcesPath, }) => {
5
+ export const getZipWidgetPlugin = ({ isOnlyManifest, widgetResourcesDirName, }) => {
6
6
  return new ZipPlugin({
7
7
  filename: WIDGET_ARCHIVE_NAME,
8
8
  extension: BUILD_ARCHIVE_EXT,
9
9
  include: isOnlyManifest
10
- ? compact([MANIFEST_JSON_FILE_NAME, widgetResourcesPath])
10
+ ? compact([MANIFEST_JSON_FILE_NAME, widgetResourcesDirName])
11
11
  : undefined,
12
12
  });
13
13
  };
@@ -6,3 +6,4 @@ export const WIDGET_ARCHIVE_NAME = "widget";
6
6
  export const WIDGET_ARCHIVE_FULL_NAME = `${WIDGET_ARCHIVE_NAME}.${BUILD_ARCHIVE_EXT}`;
7
7
  export const WIDGET_DEFAULT_HOST = "localhost";
8
8
  export const WIDGET_DEFAULT_PORT = "5555";
9
+ export const WIDGET_SDK_VERSION_FIELD_NAME = "sdk_version";
@@ -15,18 +15,19 @@ import { generatePackagePaths } from "../../package/packagePaths.js";
15
15
  import { checkLatestLibsVersion } from "../utils.js";
16
16
  export const runBuild = (args) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  const mode = "production";
18
- const { buildDir, host, port, dev: isBuildDevMode, packageDir, packageManifest, assetsDir, } = args;
18
+ const { buildDir, host, port, dev: isBuildDevMode, packageDir, packageManifest, } = args;
19
19
  const WIDGET_PATHS = generateWidgetPaths(args);
20
20
  const sections = {
21
21
  plugins: [
22
22
  getZipWidgetPlugin({
23
23
  isOnlyManifest: isBuildDevMode,
24
- widgetResourcesPath: WIDGET_PATHS.widgetResourcesPath,
24
+ widgetResourcesDirName: WIDGET_PATHS.widgetResourcesDirName,
25
25
  }),
26
26
  getModifyManifestWidgetPlugin({
27
27
  isBuildDevMode,
28
28
  host,
29
29
  port,
30
+ WIDGET_PATHS,
30
31
  }),
31
32
  ],
32
33
  };
@@ -23,7 +23,7 @@ export const runDevServer = (options) => __awaiter(void 0, void 0, void 0, funct
23
23
  process.exit(1);
24
24
  }
25
25
  });
26
- const run = (PATHS, options) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const run = (WIDGET_PATHS, options) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  const { host, port } = options;
28
28
  const mode = "development";
29
29
  const pluginsSection = {
@@ -32,12 +32,13 @@ const run = (PATHS, options) => __awaiter(void 0, void 0, void 0, function* () {
32
32
  isBuildDevMode: true,
33
33
  host,
34
34
  port,
35
+ WIDGET_PATHS,
35
36
  }),
36
37
  getReactRefresh(),
37
38
  ],
38
39
  };
39
40
  const configWebpack = [
40
- getCommonWidgetConfig(mode, PATHS),
41
+ getCommonWidgetConfig(mode, WIDGET_PATHS),
41
42
  pluginsSection,
42
43
  devtoolSection,
43
44
  ];
@@ -49,5 +49,5 @@ class CustomWidget implements IWidget<WidgetSettings> {
49
49
  }
50
50
  }
51
51
 
52
- window.im.defineWidget(manifest.uuid, CustomWidget);
52
+ window.im.widget.defineWidget(manifest.uuid, CustomWidget);
53
53
  `;
@@ -5,8 +5,8 @@ export const WIDGET_RC_CONFIG = `\
5
5
  "$schema": "node_modules/${CUSTOM_PACKAGE_CLI_LIB_NAME}/schemas/widgetConfigSchema.json",
6
6
  "entry": "src/index.tsx",
7
7
  "widgetManifest": "${MANIFEST_JSON_FILE_NAME}",
8
- "packageManifest": "package/${MANIFEST_JSON_FILE_NAME}",
9
8
  "packageDir": "package",
9
+ "packageManifest": "package/${MANIFEST_JSON_FILE_NAME}",
10
10
  "assetsDir": "_resources",
11
11
  "buildDir": "${DEFAULT_BUILD_DIR_NAME}",
12
12
  "port": ${+WIDGET_DEFAULT_PORT},
@@ -1,7 +1,7 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import semver from "semver";
3
3
  import chalk from "chalk";
4
- import { getLatestVersionOfLibrary, getLibraryVersionInProject, } from "../utils.js";
4
+ import { getLatestVersionOfLibrary, getLibraryVersionInProject, systemRequire, } from "../utils.js";
5
5
  import { WIDGET_SDK_LIB_NAME } from "./const.js";
6
6
  import { CUSTOM_PACKAGE_CLI_LIB_NAME } from "../const.js";
7
7
  export function checkLatestVersion(libName) {
@@ -39,3 +39,20 @@ export function checkLatestLibsVersion() {
39
39
  catch (error) { }
40
40
  });
41
41
  }
42
+ export function getSdkVersionFromPackageJson(appPackageJsonPath) {
43
+ var _a;
44
+ const packageJson = systemRequire(appPackageJsonPath);
45
+ let version = 0;
46
+ for (const field of ["dependencies", "devDependencies"]) {
47
+ const tempVersion = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson[field]) === null || _a === void 0 ? void 0 : _a[WIDGET_SDK_LIB_NAME];
48
+ if (tempVersion && semver.valid(tempVersion)) {
49
+ version = semver.major(tempVersion);
50
+ break;
51
+ }
52
+ if (tempVersion && semver.validRange(tempVersion)) {
53
+ version = semver.major(semver.minVersion(tempVersion) || "0.0.0");
54
+ break;
55
+ }
56
+ }
57
+ return version;
58
+ }
@@ -1,8 +1,9 @@
1
+ import path from "node:path";
1
2
  import { _resolveApp, generateGlobalPaths, generateIndexPath, } from "../paths.js";
2
3
  export function generateWidgetPaths({ entry, assetsDir, widgetManifest, buildDir, }) {
3
4
  const globalPaths = generateGlobalPaths({ buildDirPath: buildDir });
4
5
  const resolveApp = _resolveApp();
5
6
  return Object.assign(Object.assign({}, globalPaths), { get moduleIndex() {
6
7
  return generateIndexPath(entry);
7
- }, widgetManifestJsonPath: resolveApp(widgetManifest), widgetResourcesPath: assetsDir ? resolveApp(assetsDir) : null, widgetBuildDirPath: resolveApp(buildDir) });
8
+ }, widgetManifestJsonPath: resolveApp(widgetManifest), widgetResourcesPath: assetsDir ? resolveApp(assetsDir) : null, widgetResourcesDirName: assetsDir ? path.basename(assetsDir) : null, widgetBuildDirPath: resolveApp(buildDir) });
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/package-cli",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "exports": "./dist/index.js",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "type": "object",
4
+ "additionalProperties": false,
4
5
  "properties": {
6
+ "$schema": {
7
+ "type": "string"
8
+ },
5
9
  "entry": {
6
10
  "type": "string",
7
11
  "description": "файл который является точкой входа"
@@ -14,9 +14,6 @@
14
14
  "pattern": "\\w+\\.js$",
15
15
  "examples": ["index.js", "main.js"]
16
16
  },
17
- "api_version": {
18
- "type": "integer"
19
- },
20
17
  "name": {
21
18
  "type": "object",
22
19
  "title": "Локализованное имя виджета",
@@ -52,5 +49,5 @@
52
49
  }
53
50
  }
54
51
  },
55
- "required": ["uuid", "entry", "api_version", "name"]
52
+ "required": ["uuid", "entry", "name"]
56
53
  }