@infomaximum/package-cli 1.3.0 → 1.4.0-rc

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.
@@ -0,0 +1,80 @@
1
+ export const APP_D_TS_TEMPLATE = `\
2
+ /* eslint-disable @typescript-eslint/triple-slash-reference */
3
+ /// <reference types="@infomaximum/global-types" />
4
+ /// <reference types="@infomaximum/custom-widget" />
5
+
6
+ /// <reference types="node" />
7
+ /// <reference types="react" />
8
+ /// <reference types="react-dom" />
9
+
10
+ declare namespace NodeJS {
11
+ interface ProcessEnv {
12
+ readonly NODE_ENV: "development" | "production";
13
+ }
14
+ }
15
+
16
+ declare module "*.avif" {
17
+ const src: string;
18
+ export default src;
19
+ }
20
+
21
+ declare module "*.bmp" {
22
+ const src: string;
23
+ export default src;
24
+ }
25
+
26
+ declare module "*.gif" {
27
+ const src: string;
28
+ export default src;
29
+ }
30
+
31
+ declare module "*.jpg" {
32
+ const src: string;
33
+ export default src;
34
+ }
35
+
36
+ declare module "*.jpeg" {
37
+ const src: string;
38
+ export default src;
39
+ }
40
+
41
+ declare module "*.png" {
42
+ const src: string;
43
+ export default src;
44
+ }
45
+
46
+ declare module "*.webp" {
47
+ const src: string;
48
+ export default src;
49
+ }
50
+
51
+ declare module "*.svg" {
52
+ import * as React from "react";
53
+
54
+ export const ReactComponent: React.FunctionComponent<
55
+ React.SVGProps<SVGSVGElement> & { title?: string }
56
+ >;
57
+
58
+ export default ReactComponent;
59
+ }
60
+
61
+ declare module "*.svg?url" {
62
+ const src: string;
63
+ export default src;
64
+ }
65
+
66
+ declare module "*.module.css" {
67
+ const classes: { readonly [key: string]: string };
68
+ export default classes;
69
+ }
70
+
71
+ declare module "*.module.scss" {
72
+ const classes: { readonly [key: string]: string };
73
+ export default classes;
74
+ }
75
+
76
+ declare module "*.module.sass" {
77
+ const classes: { readonly [key: string]: string };
78
+ export default classes;
79
+ }
80
+ `;
@@ -0,0 +1,58 @@
1
+ export const WIDGET_INDEX_TEMPLATE = `\
2
+ import React from "react";
3
+ import ReactDOM from "react-dom/client";
4
+ import "./index.css";
5
+ import {
6
+ type IWidget,
7
+ type IPanelDescription,
8
+ type IBaseWidgetSettings,
9
+ type ICustomWidgetProps,
10
+ } from "@infomaximum/custom-widget";
11
+ import manifest from "../manifest.json";
12
+
13
+ interface Settings extends IBaseWidgetSettings {}
14
+
15
+ class CustomWidget implements IWidget<Settings> {
16
+ root: ReactDOM.Root | null = null;
17
+
18
+ public initialize(container: HTMLElement) {
19
+ this.root = ReactDOM.createRoot(container);
20
+ }
21
+
22
+ public update(container: HTMLElement, props: ICustomWidgetProps<Settings>) {
23
+ this.render(props);
24
+ }
25
+
26
+ public mount(container: HTMLElement, props: ICustomWidgetProps<Settings>) {
27
+ this.render(props);
28
+ }
29
+
30
+ public unmount() {
31
+ this.root?.unmount();
32
+
33
+ this.root = null;
34
+ }
35
+
36
+ public render(props: ICustomWidgetProps<Settings>) {
37
+ this.root?.render(
38
+ <React.StrictMode>
39
+ <div>Custom Component</div>
40
+ </React.StrictMode>
41
+ );
42
+ }
43
+
44
+ public static createPanelDescription(): IPanelDescription<Settings> {
45
+ return {
46
+ displayRecords: [],
47
+ };
48
+ }
49
+
50
+ public static fillSettings() {}
51
+
52
+ public static getDimensions() {
53
+ return [];
54
+ }
55
+ }
56
+
57
+ window.im.defineWidget(manifest.uuid, CustomWidget);
58
+ `;
@@ -0,0 +1,11 @@
1
+ export const WIDGET_INDEX_CSS_TEMPLATE = `\
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
+ }
11
+ `;
@@ -0,0 +1,98 @@
1
+ export const WIDGET_TSCONFIG_JSON = `\
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
+ }
24
+ `;
25
+ export const WIDGET_BABEL_CONFIG = `\
26
+ module.exports = {
27
+ presets: [
28
+ "@babel/preset-env",
29
+ ["@babel/preset-react", { runtime: "automatic" }],
30
+ "@babel/preset-typescript",
31
+ ],
32
+ };
33
+ `;
34
+ export const WIDGET_GITIGNORE = `\
35
+ # dependencies
36
+ /node_modules
37
+ /.pnp
38
+ .pnp.js
39
+
40
+ # testing
41
+ /coverage
42
+
43
+ # production
44
+ /build
45
+
46
+ # misc
47
+ .DS_Store
48
+ .env.local
49
+ .env.development.local
50
+ .env.test.local
51
+ .env.production.local
52
+
53
+ npm-debug.log*
54
+ yarn-debug.log*
55
+ yarn-error.log*
56
+
57
+ /build
58
+ .ultra.cache.json
59
+ *.tsbuildinfo
60
+ `;
61
+ export const WIDGET_ESLINTIGNORE = `\
62
+ node_modules
63
+ build
64
+ `;
65
+ export const WIDGET_ESLINTRC = `\
66
+ {
67
+ "root": true,
68
+ "parser": "@typescript-eslint/parser",
69
+ "plugins": ["@typescript-eslint", "react-hooks"],
70
+ "extends": [
71
+ "plugin:@typescript-eslint/recommended",
72
+ "plugin:react/recommended",
73
+ "plugin:react-hooks/recommended"
74
+ ],
75
+ "settings": {
76
+ "react": {
77
+ "version": "detect"
78
+ }
79
+ },
80
+ "rules": {
81
+ "react/jsx-uses-react": "off", // React 17+
82
+ "react/react-in-jsx-scope": "off", // React 17+
83
+ "react/prop-types": "off",
84
+ "react/no-unknown-property": ["error", { "ignore": ["css"] }],
85
+ "@typescript-eslint/no-explicit-any": "off"
86
+ }
87
+ }
88
+ `;
89
+ export const WIDGET_JEST_CONFIG = `\
90
+ /**
91
+ * @type {import("jest").Config}
92
+ */
93
+ module.exports = {
94
+ setupFilesAfterEnv: ["jest-canvas-mock"],
95
+ testEnvironment: "jest-environment-jsdom-global",
96
+ moduleDirectories: ["node_modules", "src"],
97
+ };
98
+ `;
@@ -0,0 +1,19 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { capitalizeHelperName } from "../../scripts/widget/init/helpers.js";
3
+ export const WIDGET_MANIFEST_TEMPLATE = `\
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
+ }
18
+ }
19
+ `;
@@ -0,0 +1,43 @@
1
+ export const WIDGET_PACKAGE_JSON_TEMPLATE = `\
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
+ }
43
+ `;
package/dist/utils.js ADDED
@@ -0,0 +1,48 @@
1
+ import { __awaiter } from "tslib";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import https from "node:https";
5
+ import { spawn } from "node:child_process";
6
+ export function capitalizeFirstLetter(str = "") {
7
+ return str.charAt(0).toUpperCase() + str.slice(1);
8
+ }
9
+ export function writeFile(pathToFile, contents, options) {
10
+ return __awaiter(this, void 0, void 0, function* () {
11
+ yield fs.mkdir(path.dirname(pathToFile), { recursive: true });
12
+ yield fs.writeFile(pathToFile, contents, options);
13
+ });
14
+ }
15
+ export function getLatestVersionOfLibrary(libraryName) {
16
+ return new Promise((resolve, reject) => {
17
+ https
18
+ .get(`https://registry.npmjs.org/-/package/${libraryName}/dist-tags`, (res) => {
19
+ if (res.statusCode === 200) {
20
+ let body = "";
21
+ res.on("data", (data) => (body += data));
22
+ res.on("end", () => {
23
+ resolve(JSON.parse(body).latest);
24
+ });
25
+ }
26
+ else {
27
+ reject();
28
+ }
29
+ })
30
+ .on("error", () => {
31
+ reject();
32
+ });
33
+ });
34
+ }
35
+ export function spawnCommand(command, options) {
36
+ const didSucceed = (code) => `${code}` === "0";
37
+ return new Promise((resolve, reject) => {
38
+ const childProcess = spawn(command, Object.assign({ shell: true, stdio: "inherit" }, options));
39
+ childProcess.on("close", (code) => {
40
+ if (didSucceed(code)) {
41
+ resolve();
42
+ }
43
+ else {
44
+ reject(code);
45
+ }
46
+ });
47
+ });
48
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@infomaximum/package-cli",
3
- "version": "1.3.0",
4
- "main": "dist/bin/cli.js",
3
+ "version": "1.4.0-rc",
4
+ "exports": "./dist/index.js",
5
+ "type": "module",
5
6
  "license": "Apache-2.0",
6
7
  "bin": {
7
- "im-package-cli": "dist/bin/cli.js"
8
+ "im-package-cli": "dist/index.js"
8
9
  },
9
10
  "files": [
10
11
  "dist/",
@@ -35,6 +36,7 @@
35
36
  "css-loader": "^6.8.1",
36
37
  "css-minimizer-webpack-plugin": "^5.0.1",
37
38
  "fork-ts-checker-webpack-plugin": "^9.0.2",
39
+ "node-plop": "^0.32.0",
38
40
  "less": "^4.2.0",
39
41
  "less-loader": "^11.1.3",
40
42
  "postcss": "^8.4.31",
@@ -55,7 +57,15 @@
55
57
  "devDependencies": {
56
58
  "prettier": "^3.1.0",
57
59
  "rimraf": "^5.0.5",
58
- "typescript": "^5.3.2"
60
+ "typescript": "~5.3.2"
61
+ },
62
+ "resolutions": {
63
+ "wrap-ansi": "7.0.0",
64
+ "string-width": "4.1.0",
65
+ "strip-ansi": "6.0.0"
66
+ },
67
+ "engines": {
68
+ "node": ">=16"
59
69
  },
60
70
  "repository": {
61
71
  "type": "git",
package/dist/bin/cli.js DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var tslib_1 = require("tslib");
5
- var commander_1 = tslib_1.__importDefault(require("commander"));
6
- var arguments_1 = require("../lib/arguments");
7
- var cli = new commander_1.default.Command();
8
- process.title = "im-package-cli";
9
- (0, arguments_1.registerCommands)(cli);
10
- cli.parse(process.argv);
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerCommands = void 0;
4
- var tslib_1 = require("tslib");
5
- var package_json_1 = tslib_1.__importDefault(require("../package.json"));
6
- var build_1 = require("./scripts/build");
7
- var start_1 = require("./scripts/start");
8
- var registerCommands = function (cli) {
9
- cli.helpOption("-h", "Отображает помощь по командам");
10
- cli.name("im-package-cli");
11
- cli.version(package_json_1.default.version, "-v, --version", "Текущая версия библиотеки");
12
- var widgetCommand = cli.command("widget");
13
- var widgetBuildCommand = widgetCommand.command("build");
14
- widgetBuildCommand
15
- .option("-e, --entry <path>", "Путь до entrypoint")
16
- .description("Запускает сборку проекта")
17
- .action(function (options) { return (0, build_1.runBuild)(options); });
18
- var widgetStartCommand = widgetCommand.command("start");
19
- widgetStartCommand
20
- .description("Запускает проект в dev режиме")
21
- .option("-e, --entry <path>", "Путь до entrypoint")
22
- .option("-p, --port <port>", "Порт на котором будет доступен виджет", "5555")
23
- .option("--host <host>", "host на котором будет доступен виджет", "0.0.0.0")
24
- .action(function (options) { return (0, start_1.runDevServer)(options); });
25
- };
26
- exports.registerCommands = registerCommands;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageConfig = void 0;
4
- var tslib_1 = require("tslib");
5
- var zip_webpack_plugin_1 = tslib_1.__importDefault(require("zip-webpack-plugin"));
6
- var copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
7
- var common_1 = require("./common");
8
- var path_1 = tslib_1.__importDefault(require("path"));
9
- var json_modify_webpack_plugin_1 = require("@infomaximum/json-modify-webpack-plugin");
10
- var packageFilename = "main.js";
11
- var getPackageConfig = function (mode, PATHS) {
12
- var widgetVersion = require(PATHS.appPackageJson).version;
13
- var manifestPackageName = require(PATHS.packageManifest).name;
14
- return {
15
- mode: mode,
16
- name: "package",
17
- entry: [
18
- PATHS.packageManifest,
19
- path_1.default.resolve(PATHS.appBuild, "".concat(common_1.widgetArchiveName, ".").concat(common_1.archiveExt)),
20
- ],
21
- output: {
22
- path: PATHS.appBuild,
23
- filename: packageFilename,
24
- clean: true,
25
- },
26
- module: {
27
- rules: [
28
- {
29
- test: /manifest.json$/i,
30
- type: "asset/resource",
31
- generator: {
32
- filename: "manifest[ext]",
33
- },
34
- },
35
- {
36
- test: new RegExp(".".concat(common_1.archiveExt, "$"), "i"),
37
- type: "asset/resource",
38
- generator: {
39
- filename: "[name][ext]",
40
- },
41
- },
42
- ],
43
- },
44
- plugins: [
45
- new copy_webpack_plugin_1.default({
46
- patterns: [{ from: PATHS.packagePath }],
47
- }),
48
- new zip_webpack_plugin_1.default({
49
- filename: "".concat(manifestPackageName, "_").concat(widgetVersion),
50
- extension: common_1.archiveExt,
51
- exclude: [packageFilename],
52
- }),
53
- new json_modify_webpack_plugin_1.JsonModifyWebpackPlugin({
54
- matchers: [
55
- {
56
- matcher: /^manifest.json$/,
57
- action: function (currentJsonContent) {
58
- currentJsonContent.version = widgetVersion;
59
- return currentJsonContent;
60
- },
61
- },
62
- ],
63
- }),
64
- ],
65
- dependencies: [common_1.buildWidgetConfigName],
66
- };
67
- };
68
- exports.getPackageConfig = getPackageConfig;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDevServerConfig = void 0;
4
- var getDevServerConfig = function (_a) {
5
- var host = _a.host, port = _a.port;
6
- return {
7
- open: false,
8
- hot: true,
9
- port: port,
10
- host: host,
11
- headers: {
12
- "Access-Control-Allow-Origin": "*",
13
- },
14
- devMiddleware: {
15
- writeToDisk: false,
16
- },
17
- };
18
- };
19
- exports.getDevServerConfig = getDevServerConfig;
package/dist/lib/paths.js DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateIndexPath = exports.MODE = exports.generatePaths = void 0;
4
- var tslib_1 = require("tslib");
5
- var fs_1 = tslib_1.__importDefault(require("fs"));
6
- var path_1 = tslib_1.__importDefault(require("path"));
7
- var appDirectory = fs_1.default.realpathSync(process.cwd());
8
- var resolveApp = function (relativePath) {
9
- return path_1.default.resolve(appDirectory, relativePath);
10
- };
11
- var moduleFileExtensions = [
12
- "web.mjs",
13
- "mjs",
14
- "web.js",
15
- "js",
16
- "web.ts",
17
- "ts",
18
- "web.tsx",
19
- "tsx",
20
- "json",
21
- "web.jsx",
22
- "jsx",
23
- "module.ts",
24
- "module.tsx",
25
- ];
26
- var resolveModule = function (resolveFn, filePath) {
27
- var extension = moduleFileExtensions.find(function (extension) {
28
- return fs_1.default.existsSync(resolveFn("".concat(filePath, ".").concat(extension)));
29
- });
30
- if (extension) {
31
- return resolveFn("".concat(filePath, ".").concat(extension));
32
- }
33
- return resolveFn("".concat(filePath, ".js"));
34
- };
35
- var generatePaths = function (args) {
36
- var packagePath = resolveApp("package");
37
- return {
38
- appPath: resolveApp("."),
39
- appBuild: resolveApp("build"),
40
- moduleIndex: (0, exports.generateIndexPath)(args.entryPath),
41
- appPackageJson: resolveApp("package.json"),
42
- manifestJson: resolveApp("manifest.json"),
43
- packagePath: packagePath,
44
- packageManifest: resolveApp(path_1.default.resolve(packagePath, "manifest.json")),
45
- appTsConfig: resolveApp("tsconfig.json"),
46
- appNodeModules: resolveApp("node_modules"),
47
- publicPath: "/",
48
- };
49
- };
50
- exports.generatePaths = generatePaths;
51
- exports.MODE = {
52
- DEV: "development",
53
- PROD: "production",
54
- };
55
- var generateIndexPath = function (entryPath) {
56
- var _a;
57
- var indexSrcPath = resolveModule(resolveApp, "src/index");
58
- if (entryPath && fs_1.default.existsSync(entryPath)) {
59
- return entryPath;
60
- }
61
- try {
62
- var mainIndexPath = path_1.default.resolve(process.cwd(), (_a = require(resolveApp("package.json"))) === null || _a === void 0 ? void 0 : _a.main);
63
- if (mainIndexPath && fs_1.default.existsSync(mainIndexPath)) {
64
- return mainIndexPath;
65
- }
66
- }
67
- catch (error) {
68
- console.error("Не найдена секция main в package.json");
69
- process.exit(1);
70
- }
71
- if (fs_1.default.existsSync(indexSrcPath)) {
72
- return indexSrcPath;
73
- }
74
- console.error("Не найден входной файл");
75
- process.exit(1);
76
- };
77
- exports.generateIndexPath = generateIndexPath;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runBuild = void 0;
4
- var tslib_1 = require("tslib");
5
- var webpack_1 = tslib_1.__importDefault(require("webpack"));
6
- var paths_1 = require("../paths");
7
- var common_1 = require("../configs/webpack/common");
8
- var buildPa_kage_1 = require("../configs/webpack/buildPa\u0441kage");
9
- var runBuild = function (args) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
10
- var mode, PATHS, configList;
11
- return tslib_1.__generator(this, function (_a) {
12
- mode = "production";
13
- PATHS = (0, paths_1.generatePaths)({
14
- entryPath: args.entry,
15
- });
16
- configList = [
17
- (0, common_1.getCommonWidgetConfig)(mode, PATHS),
18
- (0, buildPa_kage_1.getPackageConfig)(mode, PATHS),
19
- ];
20
- try {
21
- build(configList);
22
- }
23
- catch (error) {
24
- console.error("Failed to compile.\n");
25
- console.error(error);
26
- process.exit(1);
27
- }
28
- return [2];
29
- });
30
- }); };
31
- exports.runBuild = runBuild;
32
- function build(config) {
33
- var compiler = (0, webpack_1.default)(config);
34
- return compiler.run(function (err, stats) {
35
- if (err) {
36
- console.error(err.stack || err);
37
- if (err === null || err === void 0 ? void 0 : err.details) {
38
- console.error(err.details);
39
- }
40
- return;
41
- }
42
- stats &&
43
- console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
44
- chunks: false,
45
- colors: true,
46
- }));
47
- });
48
- }