@infomaximum/package-cli 1.4.0-rc4 → 1.4.0-rc6

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/arguments.js CHANGED
@@ -1,6 +1,8 @@
1
1
  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
+ import { systemRequire } from "./utils.js";
5
+ const packageJson = systemRequire("../package.json");
4
6
  const registerWidgetCommands = (cli) => {
5
7
  const widgetCommand = cli.command("widget");
6
8
  const widgetBuildCommand = widgetCommand.command("build");
@@ -15,15 +17,16 @@ const registerWidgetCommands = (cli) => {
15
17
  .option("-p, --port <port>", "Порт на котором будет доступен виджет", "5555")
16
18
  .option("--host <host>", "host на котором будет доступен виджет", "0.0.0.0")
17
19
  .action((options) => runDevServer(options));
18
- const widgetInitCommand = widgetCommand.command("init <path>");
20
+ const widgetInitCommand = widgetCommand.command("init <project-directory>");
19
21
  widgetInitCommand
20
22
  .description("Создание виджета")
21
- .action((initPath) => {
22
- runInitWidget(initPath);
23
+ .action((dirName) => {
24
+ runInitWidget(dirName);
23
25
  });
24
26
  };
25
27
  export const registerCommands = (cli) => {
26
28
  cli.helpOption("-h", "Отображает помощь по командам");
27
29
  cli.name("im-package-cli");
30
+ cli.version(packageJson.version, "-v, --version", "Текущая версия библиотеки");
28
31
  registerWidgetCommands(cli);
29
32
  };
@@ -4,7 +4,7 @@ import { archiveExt, buildWidgetConfigName, widgetArchiveName, } from "./common.
4
4
  import path from "path";
5
5
  import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
6
6
  import { systemRequire } from "../../utils.js";
7
- const packageFilename = "main";
7
+ const packageFilename = "main.js";
8
8
  export const getPackageConfig = (mode, PATHS) => {
9
9
  const widgetVersion = systemRequire(PATHS.appPackageJson).version;
10
10
  const manifestPackageName = systemRequire(PATHS.packageManifest).name;
package/dist/const.js ADDED
@@ -0,0 +1 @@
1
+ export const CUSTOM_WIDGET_LIB_NAME = "@infomaximum/custom-widget";
@@ -3,8 +3,11 @@ import webpack, {} from "webpack";
3
3
  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
+ import { checkLatestVersion } from "../../utils.js";
7
+ import { CUSTOM_WIDGET_LIB_NAME } from "../../const.js";
6
8
  export const runBuild = (args) => __awaiter(void 0, void 0, void 0, function* () {
7
9
  const mode = "production";
10
+ yield checkLatestVersion(CUSTOM_WIDGET_LIB_NAME);
8
11
  const PATHS = generatePaths({
9
12
  entryPath: args.entry,
10
13
  });
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import path from "node:path";
3
- import { getLatestVersionOfLibrary, writeFile } from "../../../utils.js";
3
+ import { getLatestVersionOfLibrary, safeWriteFile } from "../../../utils.js";
4
4
  import { PACKAGE_MANIFEST_TEMPLATE } from "../../../templates/package/packageManifest.js";
5
5
  import { PACKAGE_ICON_TEMPLATE } from "../../../templates/package/packageIcon.js";
6
6
  import { WIDGET_MANIFEST_TEMPLATE } from "../../../templates/widget/widgetManifest.js";
@@ -9,12 +9,13 @@ import { WIDGET_INDEX_TEMPLATE } from "../../../templates/widget/src/widgetIndex
9
9
  import { APP_D_TS_TEMPLATE } from "../../../templates/widget/src/widgetAppDTs.js";
10
10
  import { WIDGET_INDEX_CSS_TEMPLATE } from "../../../templates/widget/src/widgetIndexCSS.js";
11
11
  import { WIDGET_PACKAGE_JSON_TEMPLATE } from "../../../templates/widget/widgetPackageJson.js";
12
+ import { CUSTOM_WIDGET_LIB_NAME } from "../../../const.js";
12
13
  const addIconActionName = "addIcon";
13
14
  const addInitActions = (basePath, plop) => {
14
15
  plop.setActionType(addIconActionName, function (answers, config, plop) {
15
16
  return __awaiter(this, void 0, void 0, function* () {
16
17
  try {
17
- yield writeFile(path.resolve(basePath, config.path), config.template, {
18
+ yield safeWriteFile(path.resolve(basePath, config.path), config.template, {
18
19
  encoding: "base64",
19
20
  });
20
21
  return config.path;
@@ -104,7 +105,7 @@ const getInitWidgetActions = (basePath, plop) => __awaiter(void 0, void 0, void
104
105
  addInitActions(basePath, plop);
105
106
  const [packageCliVersion, customWidgetVersion] = yield Promise.all([
106
107
  getLatestVersionOfLibrary("@infomaximum/package-cli"),
107
- getLatestVersionOfLibrary("@infomaximum/custom-widget"),
108
+ getLatestVersionOfLibrary(CUSTOM_WIDGET_LIB_NAME),
108
109
  ]);
109
110
  return (data) => actions(Object.assign(Object.assign({}, data), { packageCliVersion,
110
111
  customWidgetVersion }));
@@ -3,17 +3,18 @@ import path from "node:path";
3
3
  import nodePlop from "node-plop";
4
4
  import { getInitWidgetGenerator } from "./generators.js";
5
5
  import { spawnCommand } from "../../../utils.js";
6
- const runInitWidget = (initPath) => __awaiter(void 0, void 0, void 0, function* () {
7
- const createPath = path.resolve(process.cwd(), initPath);
6
+ const runInitWidget = (dirName) => __awaiter(void 0, void 0, void 0, function* () {
7
+ const createPath = path.join(process.cwd(), dirName);
8
8
  const plop = yield nodePlop(undefined, {
9
9
  destBasePath: createPath,
10
10
  force: false,
11
11
  });
12
12
  const initGenerator = yield getInitWidgetGenerator(createPath, plop);
13
- const answers = yield initGenerator.runPrompts();
13
+ const answers = (yield initGenerator.runPrompts());
14
14
  yield initGenerator.runActions(answers);
15
+ const packageManager = answers.packageManager;
15
16
  try {
16
- yield spawnCommand("npm install", {
17
+ yield spawnCommand(packageManager, ["install"], {
17
18
  cwd: createPath,
18
19
  });
19
20
  }
@@ -21,7 +22,7 @@ const runInitWidget = (initPath) => __awaiter(void 0, void 0, void 0, function*
21
22
  console.error(error);
22
23
  }
23
24
  try {
24
- yield spawnCommand("git init", {
25
+ yield spawnCommand("git", ["init"], {
25
26
  cwd: createPath,
26
27
  });
27
28
  }
@@ -1,22 +1,38 @@
1
1
  const notEmptyValidator = (input) => !!input;
2
2
  const prompts = [
3
3
  {
4
- message: "Введите название пакета: ",
4
+ message: "Enter the name of the package: ",
5
5
  type: "input",
6
6
  name: "packageName",
7
7
  validate: notEmptyValidator,
8
8
  },
9
9
  {
10
- message: "Введите описание для пакета: ",
10
+ message: "Enter a description for the package: ",
11
11
  type: "input",
12
12
  name: "packageDescription",
13
13
  default: "",
14
14
  },
15
15
  {
16
- message: "Имя автора пакета: ",
16
+ message: "Enter the name of the package author: ",
17
17
  type: "input",
18
18
  name: "author",
19
19
  validate: notEmptyValidator,
20
20
  },
21
+ {
22
+ message: "Select the package manager: ",
23
+ type: "list",
24
+ name: "packageManager",
25
+ default: "yarn",
26
+ choices: [
27
+ {
28
+ name: "npm",
29
+ value: "npm",
30
+ },
31
+ {
32
+ name: "yarn",
33
+ value: "yarn",
34
+ },
35
+ ],
36
+ },
21
37
  ];
22
38
  export { prompts };
@@ -5,11 +5,14 @@ import WebpackDevServer from "webpack-dev-server";
5
5
  import { getDevServerConfig } from "../../configs/webpack/devServer.js";
6
6
  import { merge } from "webpack-merge";
7
7
  import { getCommonWidgetConfig } from "../../configs/webpack/common.js";
8
+ import { checkLatestVersion } from "../../utils.js";
9
+ import { CUSTOM_WIDGET_LIB_NAME } from "../../const.js";
8
10
  const { webpack } = _webpack;
9
11
  export const runDevServer = (options) => __awaiter(void 0, void 0, void 0, function* () {
10
12
  const PATHS = generatePaths({
11
13
  entryPath: options.entry,
12
14
  });
15
+ yield checkLatestVersion(CUSTOM_WIDGET_LIB_NAME);
13
16
  try {
14
17
  yield run(PATHS, options);
15
18
  }
@@ -1,11 +1,11 @@
1
1
  export const WIDGET_INDEX_CSS_TEMPLATE = `\
2
2
  body {
3
- margin: 0;
4
- overflow: hidden;
5
- font-family: -apple-system, BlinkMacSystemFont, "Montserrat Segoe UI",
6
- "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
7
- "Helvetica Neue", sans-serif;
8
- -webkit-font-smoothing: antialiased;
9
- -moz-osx-font-smoothing: grayscale;
10
- }
3
+ margin: 0;
4
+ overflow: hidden;
5
+ font-family: -apple-system, BlinkMacSystemFont, "Montserrat Segoe UI",
6
+ "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
7
+ "Helvetica Neue", sans-serif;
8
+ -webkit-font-smoothing: antialiased;
9
+ -moz-osx-font-smoothing: grayscale;
10
+ }
11
11
  `;
@@ -1,26 +1,26 @@
1
1
  export const WIDGET_TSCONFIG_JSON = `\
2
2
  {
3
- "compilerOptions": {
4
- "baseUrl": "./src",
5
- "target": "ES2015",
6
- "lib": ["dom", "dom.iterable", "esnext"],
7
- "allowJs": true,
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "allowSyntheticDefaultImports": true,
11
- "strict": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "noFallthroughCasesInSwitch": true,
14
- "module": "esnext",
15
- "moduleResolution": "node",
16
- "resolveJsonModule": true,
17
- "isolatedModules": true,
18
- "verbatimModuleSyntax": true,
19
- "noEmit": true,
20
- "jsx": "react-jsx"
21
- },
22
- "include": ["src"]
23
- }
3
+ "compilerOptions": {
4
+ "baseUrl": "./src",
5
+ "target": "ES2015",
6
+ "lib": ["dom", "dom.iterable", "esnext"],
7
+ "allowJs": true,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "strict": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "module": "esnext",
15
+ "moduleResolution": "node",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "verbatimModuleSyntax": true,
19
+ "noEmit": true,
20
+ "jsx": "react-jsx"
21
+ },
22
+ "include": ["src"]
23
+ }
24
24
  `;
25
25
  export const WIDGET_BABEL_CONFIG = `\
26
26
  module.exports = {
@@ -2,18 +2,18 @@ import { randomUUID } from "node:crypto";
2
2
  import { capitalizeHelperName } from "../../scripts/widget/init/helpers.js";
3
3
  export const WIDGET_MANIFEST_TEMPLATE = `\
4
4
  {
5
- "uuid": "${randomUUID()}",
6
- "entry": "index.js",
7
- "api_version": 1,
8
- "name": {
9
- "en": "{{${capitalizeHelperName} packageName}}",
10
- "ru": "{{${capitalizeHelperName} packageName}}"
11
- },
12
- "default_size_percentage": {
13
- "width": 60,
14
- "height": 20,
15
- "min_width": 8,
16
- "min_height": 4
17
- }
5
+ "uuid": "${randomUUID()}",
6
+ "entry": "index.js",
7
+ "api_version": 1,
8
+ "name": {
9
+ "en": "{{${capitalizeHelperName} packageName}}",
10
+ "ru": "{{${capitalizeHelperName} packageName}}"
11
+ },
12
+ "default_size_percentage": {
13
+ "width": 60,
14
+ "height": 20,
15
+ "min_width": 8,
16
+ "min_height": 4
18
17
  }
18
+ }
19
19
  `;
@@ -1,43 +1,43 @@
1
1
  export const WIDGET_PACKAGE_JSON_TEMPLATE = `\
2
2
  {
3
- "name": "template_widget",
4
- "version": "1.0.0",
5
- "private": true,
6
- "main": "src/index.tsx",
7
- "scripts": {
8
- "build": "im-package-cli widget build --entry ./src/index.tsx",
9
- "start": "im-package-cli widget start --entry ./src/index.tsx",
10
- "lint": "tsc --noEmit && eslint src/ --ext .ts,.tsx --quiet",
11
- "test": "jest --passWithNoTests"
12
- },
13
- "dependencies": {
14
- "react": "18.2.0",
15
- "react-dom": "18.2.0",
16
- "@infomaximum/custom-widget": "^{{customWidgetVersion}}"
17
- },
18
- "devDependencies": {
19
- "@babel/core": "7.23.3",
20
- "@babel/preset-env": "7.23.3",
21
- "@babel/preset-react": "7.23.3",
22
- "@babel/preset-typescript": "7.23.3",
23
- "@infomaximum/package-cli": "^{{packageCliVersion}}",
24
- "@types/jest": "29.5.10",
25
- "@types/react": "18.2.39",
26
- "@types/react-dom": "18.2.17",
27
- "@typescript-eslint/eslint-plugin": "6.13.0",
28
- "@typescript-eslint/parser": "6.13.0",
29
- "eslint": "8.54.0",
30
- "eslint-plugin-react": "7.33.2",
31
- "eslint-plugin-react-hooks": "4.6.0",
32
- "jest": "29.7.0",
33
- "jest-canvas-mock": "2.5.2",
34
- "jest-environment-jsdom": "29.7.0",
35
- "jest-environment-jsdom-global": "4.0.0",
36
- "prettier": "3.1.0",
37
- "typescript": "~5.3.2"
38
- },
39
- "browserslist": [
40
- "defaults and supports es6-module"
41
- ]
42
- }
3
+ "name": "template_widget",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "main": "src/index.tsx",
7
+ "scripts": {
8
+ "build": "im-package-cli widget build --entry ./src/index.tsx",
9
+ "start": "im-package-cli widget start --entry ./src/index.tsx",
10
+ "lint": "tsc --noEmit && eslint src/ --ext .ts,.tsx --quiet",
11
+ "test": "jest --passWithNoTests"
12
+ },
13
+ "dependencies": {
14
+ "@infomaximum/custom-widget": "^{{customWidgetVersion}}",
15
+ "react": "18.2.0",
16
+ "react-dom": "18.2.0"
17
+ },
18
+ "devDependencies": {
19
+ "@babel/core": "7.23.3",
20
+ "@babel/preset-env": "7.23.3",
21
+ "@babel/preset-react": "7.23.3",
22
+ "@babel/preset-typescript": "7.23.3",
23
+ "@infomaximum/package-cli": "^{{packageCliVersion}}",
24
+ "@types/jest": "29.5.10",
25
+ "@types/react": "18.2.39",
26
+ "@types/react-dom": "18.2.17",
27
+ "@typescript-eslint/eslint-plugin": "6.13.0",
28
+ "@typescript-eslint/parser": "6.13.0",
29
+ "eslint": "8.54.0",
30
+ "eslint-plugin-react": "7.33.2",
31
+ "eslint-plugin-react-hooks": "4.6.0",
32
+ "jest": "29.7.0",
33
+ "jest-canvas-mock": "2.5.2",
34
+ "jest-environment-jsdom": "29.7.0",
35
+ "jest-environment-jsdom-global": "4.0.0",
36
+ "prettier": "3.1.0",
37
+ "typescript": "~5.3.2"
38
+ },
39
+ "browserslist": [
40
+ "defaults and supports es6-module"
41
+ ]
42
+ }
43
43
  `;
package/dist/utils.js CHANGED
@@ -1,43 +1,38 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
- import https from "node:https";
5
- import { spawn } from "node:child_process";
4
+ import { spawn, exec } from "node:child_process";
5
+ import util from "node:util";
6
6
  import Module from "node:module";
7
+ import semver from "semver";
8
+ import chalk from "chalk";
9
+ const execPromise = util.promisify(exec);
7
10
  export const systemRequire = Module.createRequire(import.meta.url);
8
11
  export function capitalizeFirstLetter(str = "") {
9
12
  return str.charAt(0).toUpperCase() + str.slice(1);
10
13
  }
11
- export function writeFile(pathToFile, contents, options) {
14
+ export function safeWriteFile(pathToFile, contents, options) {
12
15
  return __awaiter(this, void 0, void 0, function* () {
13
16
  yield fs.mkdir(path.dirname(pathToFile), { recursive: true });
14
17
  yield fs.writeFile(pathToFile, contents, options);
15
18
  });
16
19
  }
17
20
  export function getLatestVersionOfLibrary(libraryName) {
18
- return new Promise((resolve, reject) => {
19
- https
20
- .get(`https://registry.npmjs.org/-/package/${libraryName}/dist-tags`, (res) => {
21
- if (res.statusCode === 200) {
22
- let body = "";
23
- res.on("data", (data) => (body += data));
24
- res.on("end", () => {
25
- resolve(JSON.parse(body).latest);
26
- });
27
- }
28
- else {
29
- reject();
30
- }
31
- })
32
- .on("error", () => {
33
- reject();
34
- });
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const { stdout } = yield execPromise(`npm show -j -p ${libraryName} version`);
23
+ return JSON.parse(stdout);
35
24
  });
36
25
  }
37
- export function spawnCommand(command, options) {
26
+ export function getLibraryVersionInProject(libraryName) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const { stdout } = yield execPromise(`npm ls -j -p ${libraryName} version`);
29
+ return JSON.parse(stdout);
30
+ });
31
+ }
32
+ export function spawnCommand(command, args, options) {
38
33
  const didSucceed = (code) => `${code}` === "0";
39
34
  return new Promise((resolve, reject) => {
40
- const childProcess = spawn(command, Object.assign({ shell: true, stdio: "inherit" }, options));
35
+ const childProcess = spawn(command, args, Object.assign({ shell: true, stdio: "inherit" }, options));
41
36
  childProcess.on("close", (code) => {
42
37
  if (didSucceed(code)) {
43
38
  resolve();
@@ -48,3 +43,23 @@ export function spawnCommand(command, options) {
48
43
  });
49
44
  });
50
45
  }
46
+ export function checkLatestVersion(libName) {
47
+ var _a, _b, _c;
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const libVersionInProject = yield getLibraryVersionInProject(libName);
50
+ const libVersionFromProject = (_c = (((_a = libVersionInProject === null || libVersionInProject === void 0 ? void 0 : libVersionInProject.dependencies) === null || _a === void 0 ? void 0 : _a[libName]) ||
51
+ ((_b = libVersionInProject === null || libVersionInProject === void 0 ? void 0 : libVersionInProject.devDependencies) === null || _b === void 0 ? void 0 : _b[libName]))) === null || _c === void 0 ? void 0 : _c.version;
52
+ if (!libVersionFromProject)
53
+ return;
54
+ const latestVersion = yield getLatestVersionOfLibrary(libName);
55
+ const isOldVersion = semver.gt(latestVersion, libVersionFromProject);
56
+ if (isOldVersion) {
57
+ console.error(chalk.yellow(`A new version of the ${chalk.underline(`${libName}@${latestVersion}`)} library has been released,\n` +
58
+ `old version ${libVersionFromProject} is used in the project, it is recommended to ` +
59
+ `update to the latest version \n` +
60
+ chalk.green.bold(chalk.underline(`npm i --save ${libName}@${latestVersion}`) +
61
+ " or " +
62
+ chalk.underline(`yarn upgrade ${libName}@${latestVersion}\n\n`))));
63
+ }
64
+ });
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/package-cli",
3
- "version": "1.4.0-rc4",
3
+ "version": "1.4.0-rc6",
4
4
  "exports": "./dist/index.js",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -27,24 +27,27 @@
27
27
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
28
28
  "@svgr/webpack": "^8.1.0",
29
29
  "@types/node": "^20.9.0",
30
+ "@types/semver": "^7.5.6",
30
31
  "@types/zip-webpack-plugin": "^3.0.6",
31
32
  "autoprefixer": "^10.4.16",
32
33
  "babel-loader": "^9.1.3",
33
34
  "babel-plugin-inline-json-import": "^0.3.2",
35
+ "chalk": "^5.3.0",
34
36
  "commander": "^11.1.0",
35
37
  "copy-webpack-plugin": "^11.0.0",
36
38
  "css-loader": "^6.8.1",
37
39
  "css-minimizer-webpack-plugin": "^5.0.1",
38
40
  "fork-ts-checker-webpack-plugin": "^9.0.2",
39
- "node-plop": "^0.32.0",
40
41
  "less": "^4.2.0",
41
42
  "less-loader": "^11.1.3",
43
+ "node-plop": "^0.32.0",
42
44
  "postcss": "^8.4.31",
43
45
  "postcss-loader": "^7.3.3",
44
46
  "postcss-preset-env": "^9.3.0",
45
47
  "react-refresh": "^0.14.0",
46
48
  "sass": "^1.69.5",
47
49
  "sass-loader": "^13.3.2",
50
+ "semver": "^7.5.4",
48
51
  "standard-version": "^9.5.0",
49
52
  "style-loader": "^3.3.3",
50
53
  "terser-webpack-plugin": "^5.3.9",