@infomaximum/package-cli 1.3.1 → 1.4.0-rc2
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 +29 -0
- package/dist/configs/webpack/buildPa/321/201kage.js +64 -0
- package/dist/{lib/configs → configs}/webpack/common.js +34 -37
- package/dist/configs/webpack/devServer.js +14 -0
- package/dist/index.js +7 -0
- package/dist/paths.js +68 -0
- package/dist/scripts/widget/build.js +40 -0
- package/dist/scripts/widget/init/actions.js +112 -0
- package/dist/scripts/widget/init/generators.js +15 -0
- package/dist/scripts/widget/init/helpers.js +6 -0
- package/dist/scripts/widget/init/init.js +32 -0
- package/dist/scripts/widget/init/prompts.js +22 -0
- package/dist/scripts/widget/start.js +44 -0
- package/dist/templates/package/packageIcon.js +1 -0
- package/dist/templates/package/packageManifest.js +33 -0
- package/dist/templates/widget/src/widgetAppDTs.js +80 -0
- package/dist/templates/widget/src/widgetIndex.js +58 -0
- package/dist/templates/widget/src/widgetIndexCSS.js +11 -0
- package/dist/templates/widget/widgetConfigs.js +98 -0
- package/dist/templates/widget/widgetManifest.js +19 -0
- package/dist/templates/widget/widgetPackageJson.js +43 -0
- package/dist/utils.js +50 -0
- package/package.json +14 -4
- package/dist/bin/cli.js +0 -10
- package/dist/lib/arguments.js +0 -26
- package/dist/lib/configs/webpack/buildPa/321/201kage.js +0 -68
- package/dist/lib/configs/webpack/devServer.js +0 -19
- package/dist/lib/paths.js +0 -77
- package/dist/lib/scripts/build.js +0 -48
- package/dist/lib/scripts/start.js +0 -68
- package/dist/package.json +0 -72
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { runBuild } from "./scripts/widget/build.js";
|
|
2
|
+
import { runDevServer } from "./scripts/widget/start.js";
|
|
3
|
+
import { runInitWidget } from "./scripts/widget/init/init.js";
|
|
4
|
+
const registerWidgetCommands = (cli) => {
|
|
5
|
+
const widgetCommand = cli.command("widget");
|
|
6
|
+
const widgetBuildCommand = widgetCommand.command("build");
|
|
7
|
+
widgetBuildCommand
|
|
8
|
+
.option("-e, --entry <path>", "Путь до entrypoint")
|
|
9
|
+
.description("Запускает сборку проекта")
|
|
10
|
+
.action((options) => runBuild(options));
|
|
11
|
+
const widgetStartCommand = widgetCommand.command("start");
|
|
12
|
+
widgetStartCommand
|
|
13
|
+
.description("Запускает проект в dev режиме")
|
|
14
|
+
.option("-e, --entry <path>", "Путь до entrypoint")
|
|
15
|
+
.option("-p, --port <port>", "Порт на котором будет доступен виджет", "5555")
|
|
16
|
+
.option("--host <host>", "host на котором будет доступен виджет", "0.0.0.0")
|
|
17
|
+
.action((options) => runDevServer(options));
|
|
18
|
+
const widgetInitCommand = widgetCommand.command("init <path>");
|
|
19
|
+
widgetInitCommand
|
|
20
|
+
.description("Создание виджета")
|
|
21
|
+
.action((initPath) => {
|
|
22
|
+
runInitWidget(initPath);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export const registerCommands = (cli) => {
|
|
26
|
+
cli.helpOption("-h", "Отображает помощь по командам");
|
|
27
|
+
cli.name("im-package-cli");
|
|
28
|
+
registerWidgetCommands(cli);
|
|
29
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import ZipPlugin from "zip-webpack-plugin";
|
|
2
|
+
import CopyWebpackPlugin from "copy-webpack-plugin";
|
|
3
|
+
import { archiveExt, buildWidgetConfigName, widgetArchiveName, } from "./common.js";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
|
|
6
|
+
import { require } from "../../utils.js";
|
|
7
|
+
const packageFilename = "main";
|
|
8
|
+
export const getPackageConfig = (mode, PATHS) => {
|
|
9
|
+
const widgetVersion = require(PATHS.appPackageJson).version;
|
|
10
|
+
const manifestPackageName = require(PATHS.packageManifest).name;
|
|
11
|
+
return {
|
|
12
|
+
mode,
|
|
13
|
+
name: "package",
|
|
14
|
+
entry: [
|
|
15
|
+
PATHS.packageManifest,
|
|
16
|
+
path.resolve(PATHS.appBuild, `${widgetArchiveName}.${archiveExt}`),
|
|
17
|
+
],
|
|
18
|
+
output: {
|
|
19
|
+
path: PATHS.appBuild,
|
|
20
|
+
filename: packageFilename,
|
|
21
|
+
clean: true,
|
|
22
|
+
},
|
|
23
|
+
module: {
|
|
24
|
+
rules: [
|
|
25
|
+
{
|
|
26
|
+
test: /manifest.json$/i,
|
|
27
|
+
type: "asset/resource",
|
|
28
|
+
generator: {
|
|
29
|
+
filename: "manifest[ext]",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
test: new RegExp(`.${archiveExt}$`, "i"),
|
|
34
|
+
type: "asset/resource",
|
|
35
|
+
generator: {
|
|
36
|
+
filename: "[name][ext]",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
plugins: [
|
|
42
|
+
new CopyWebpackPlugin({
|
|
43
|
+
patterns: [{ from: PATHS.packagePath }],
|
|
44
|
+
}),
|
|
45
|
+
new ZipPlugin({
|
|
46
|
+
filename: `${manifestPackageName}_${widgetVersion}`,
|
|
47
|
+
extension: archiveExt,
|
|
48
|
+
exclude: [packageFilename],
|
|
49
|
+
}),
|
|
50
|
+
new JsonModifyWebpackPlugin({
|
|
51
|
+
matchers: [
|
|
52
|
+
{
|
|
53
|
+
matcher: /^manifest.json$/,
|
|
54
|
+
action: (currentJsonContent) => {
|
|
55
|
+
currentJsonContent.version = widgetVersion;
|
|
56
|
+
return currentJsonContent;
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
}),
|
|
61
|
+
],
|
|
62
|
+
dependencies: [buildWidgetConfigName],
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var DEV_SERVER_PORT = 5555;
|
|
20
|
-
var getCommonWidgetConfig = function (mode, PATHS) {
|
|
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
|
+
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
|
5
|
+
import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
6
|
+
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
|
|
7
|
+
import { JsonModifyWebpackPlugin } from "@infomaximum/json-modify-webpack-plugin";
|
|
8
|
+
import webpack, {} from "webpack";
|
|
9
|
+
import { require } from "../../utils.js";
|
|
10
|
+
const { ProgressPlugin } = webpack;
|
|
11
|
+
const isProduction = (mode) => mode === "production";
|
|
12
|
+
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
|
+
export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
21
19
|
return {
|
|
22
|
-
mode
|
|
23
|
-
name:
|
|
20
|
+
mode,
|
|
21
|
+
name: buildWidgetConfigName,
|
|
24
22
|
entry: [PATHS.moduleIndex, PATHS.manifestJson],
|
|
25
23
|
output: {
|
|
26
24
|
path: PATHS.appBuild,
|
|
@@ -29,8 +27,8 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
29
27
|
clean: true,
|
|
30
28
|
},
|
|
31
29
|
plugins: [
|
|
32
|
-
new
|
|
33
|
-
new
|
|
30
|
+
new ProgressPlugin(),
|
|
31
|
+
new ForkTsCheckerWebpackPlugin({
|
|
34
32
|
typescript: {
|
|
35
33
|
mode: "write-references",
|
|
36
34
|
diagnosticOptions: {
|
|
@@ -39,18 +37,18 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
39
37
|
},
|
|
40
38
|
},
|
|
41
39
|
}),
|
|
42
|
-
new
|
|
43
|
-
filename:
|
|
44
|
-
extension:
|
|
40
|
+
new ZipPlugin({
|
|
41
|
+
filename: widgetArchiveName,
|
|
42
|
+
extension: archiveExt,
|
|
45
43
|
}),
|
|
46
|
-
isDevelopment(mode) && new
|
|
44
|
+
isDevelopment(mode) && new ReactRefreshWebpackPlugin(),
|
|
47
45
|
isDevelopment(mode) &&
|
|
48
|
-
new
|
|
46
|
+
new JsonModifyWebpackPlugin({
|
|
49
47
|
matchers: [
|
|
50
48
|
{
|
|
51
49
|
matcher: /^manifest.json$/,
|
|
52
|
-
action:
|
|
53
|
-
currentJsonContent.entry =
|
|
50
|
+
action: (currentJsonContent) => {
|
|
51
|
+
currentJsonContent.entry = `http://${DEV_SERVER_HOST}:${DEV_SERVER_PORT}/${currentJsonContent.entry}`;
|
|
54
52
|
return currentJsonContent;
|
|
55
53
|
},
|
|
56
54
|
},
|
|
@@ -192,19 +190,18 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
192
190
|
minimize: true,
|
|
193
191
|
splitChunks: false,
|
|
194
192
|
minimizer: [
|
|
195
|
-
new
|
|
196
|
-
minify:
|
|
193
|
+
new TerserWebpackPlugin({
|
|
194
|
+
minify: TerserWebpackPlugin.terserMinify,
|
|
197
195
|
parallel: true,
|
|
198
196
|
}),
|
|
199
|
-
new
|
|
197
|
+
new CssMinimizerPlugin(),
|
|
200
198
|
],
|
|
201
199
|
}
|
|
202
200
|
: undefined,
|
|
203
201
|
resolve: {
|
|
204
|
-
extensions: [".tsx", ".ts", "
|
|
205
|
-
plugins: [new
|
|
202
|
+
extensions: [".tsx", ".ts", ""],
|
|
203
|
+
plugins: [new TsconfigPathsPlugin()],
|
|
206
204
|
},
|
|
207
205
|
devtool: isProduction(mode) ? false : "cheap-module-source-map",
|
|
208
206
|
};
|
|
209
207
|
};
|
|
210
|
-
exports.getCommonWidgetConfig = getCommonWidgetConfig;
|
package/dist/index.js
ADDED
package/dist/paths.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { require } from "./utils.js";
|
|
4
|
+
const appDirectory = fs.realpathSync(process.cwd());
|
|
5
|
+
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
|
|
6
|
+
const moduleFileExtensions = [
|
|
7
|
+
"web.mjs",
|
|
8
|
+
"mjs",
|
|
9
|
+
"web.js",
|
|
10
|
+
"js",
|
|
11
|
+
"web.ts",
|
|
12
|
+
"ts",
|
|
13
|
+
"web.tsx",
|
|
14
|
+
"tsx",
|
|
15
|
+
"json",
|
|
16
|
+
"web.jsx",
|
|
17
|
+
"jsx",
|
|
18
|
+
"module.ts",
|
|
19
|
+
"module.tsx",
|
|
20
|
+
];
|
|
21
|
+
const resolveModule = (resolveFn, filePath) => {
|
|
22
|
+
const extension = moduleFileExtensions.find((extension) => fs.existsSync(resolveFn(`${filePath}.${extension}`)));
|
|
23
|
+
if (extension) {
|
|
24
|
+
return resolveFn(`${filePath}.${extension}`);
|
|
25
|
+
}
|
|
26
|
+
return resolveFn(`${filePath}.js`);
|
|
27
|
+
};
|
|
28
|
+
export const generatePaths = (args) => {
|
|
29
|
+
const packagePath = resolveApp("package");
|
|
30
|
+
return {
|
|
31
|
+
appPath: resolveApp("."),
|
|
32
|
+
appBuild: resolveApp("build"),
|
|
33
|
+
moduleIndex: generateIndexPath(args.entryPath),
|
|
34
|
+
appPackageJson: resolveApp("package.json"),
|
|
35
|
+
manifestJson: resolveApp("manifest.json"),
|
|
36
|
+
packagePath,
|
|
37
|
+
packageManifest: resolveApp(path.resolve(packagePath, "manifest.json")),
|
|
38
|
+
appTsConfig: resolveApp("tsconfig.json"),
|
|
39
|
+
appNodeModules: resolveApp("node_modules"),
|
|
40
|
+
publicPath: "/",
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const MODE = {
|
|
44
|
+
DEV: "development",
|
|
45
|
+
PROD: "production",
|
|
46
|
+
};
|
|
47
|
+
export const generateIndexPath = (entryPath) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const indexSrcPath = resolveModule(resolveApp, "src/index");
|
|
50
|
+
if (entryPath && fs.existsSync(entryPath)) {
|
|
51
|
+
return entryPath;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const mainIndexPath = path.resolve(process.cwd(), (_a = require(resolveApp("package.json"))) === null || _a === void 0 ? void 0 : _a.main);
|
|
55
|
+
if (mainIndexPath && fs.existsSync(mainIndexPath)) {
|
|
56
|
+
return mainIndexPath;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error("Не найдена секция main в package.json");
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (fs.existsSync(indexSrcPath)) {
|
|
64
|
+
return indexSrcPath;
|
|
65
|
+
}
|
|
66
|
+
console.error("Не найден входной файл");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import webpack, {} from "webpack";
|
|
3
|
+
import { generatePaths } from "../../paths.js";
|
|
4
|
+
import { getCommonWidgetConfig } from "../../configs/webpack/common.js";
|
|
5
|
+
import { getPackageConfig } from "../../configs/webpack/buildPaсkage.js";
|
|
6
|
+
export const runBuild = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
+
const mode = "production";
|
|
8
|
+
const PATHS = generatePaths({
|
|
9
|
+
entryPath: args.entry,
|
|
10
|
+
});
|
|
11
|
+
const configList = [
|
|
12
|
+
getCommonWidgetConfig(mode, PATHS),
|
|
13
|
+
getPackageConfig(mode, PATHS),
|
|
14
|
+
];
|
|
15
|
+
try {
|
|
16
|
+
build(configList);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error("Failed to compile.\n");
|
|
20
|
+
console.error(error);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
function build(config) {
|
|
25
|
+
const compiler = webpack(config);
|
|
26
|
+
return compiler.run((err, stats) => {
|
|
27
|
+
if (err) {
|
|
28
|
+
console.error(err.stack || err);
|
|
29
|
+
if (err === null || err === void 0 ? void 0 : err.details) {
|
|
30
|
+
console.error(err.details);
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
stats &&
|
|
35
|
+
console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
|
|
36
|
+
chunks: false,
|
|
37
|
+
colors: true,
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getLatestVersionOfLibrary, writeFile } from "../../../utils.js";
|
|
4
|
+
import { PACKAGE_MANIFEST_TEMPLATE } from "../../../templates/package/packageManifest.js";
|
|
5
|
+
import { PACKAGE_ICON_TEMPLATE } from "../../../templates/package/packageIcon.js";
|
|
6
|
+
import { WIDGET_MANIFEST_TEMPLATE } from "../../../templates/widget/widgetManifest.js";
|
|
7
|
+
import { WIDGET_BABEL_CONFIG, WIDGET_ESLINTIGNORE, WIDGET_ESLINTRC, WIDGET_GITIGNORE, WIDGET_JEST_CONFIG, WIDGET_TSCONFIG_JSON, } from "../../../templates/widget/widgetConfigs.js";
|
|
8
|
+
import { WIDGET_INDEX_TEMPLATE } from "../../../templates/widget/src/widgetIndex.js";
|
|
9
|
+
import { APP_D_TS_TEMPLATE } from "../../../templates/widget/src/widgetAppDTs.js";
|
|
10
|
+
import { WIDGET_INDEX_CSS_TEMPLATE } from "../../../templates/widget/src/widgetIndexCSS.js";
|
|
11
|
+
import { WIDGET_PACKAGE_JSON_TEMPLATE } from "../../../templates/widget/widgetPackageJson.js";
|
|
12
|
+
const addIconActionName = "addIcon";
|
|
13
|
+
const addInitActions = (basePath, plop) => {
|
|
14
|
+
plop.setActionType(addIconActionName, function (answers, config, plop) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
yield writeFile(path.resolve(basePath, config.path), config.template, {
|
|
18
|
+
encoding: "base64",
|
|
19
|
+
});
|
|
20
|
+
return config.path;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const actions = ({ customWidgetVersion, packageCliVersion }) => {
|
|
29
|
+
const packageIconName = "Widget";
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
type: "add",
|
|
33
|
+
path: "package/manifest.json",
|
|
34
|
+
template: PACKAGE_MANIFEST_TEMPLATE,
|
|
35
|
+
data: {
|
|
36
|
+
packageIconName,
|
|
37
|
+
packageType: "widget",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: addIconActionName,
|
|
42
|
+
path: `package/resources/${packageIconName}.png`,
|
|
43
|
+
template: PACKAGE_ICON_TEMPLATE,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "add",
|
|
47
|
+
path: "manifest.json",
|
|
48
|
+
template: WIDGET_MANIFEST_TEMPLATE,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "add",
|
|
52
|
+
path: "src/index.tsx",
|
|
53
|
+
template: WIDGET_INDEX_TEMPLATE,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: "add",
|
|
57
|
+
path: "src/app.d.ts",
|
|
58
|
+
template: APP_D_TS_TEMPLATE,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "add",
|
|
62
|
+
path: "src/index.css",
|
|
63
|
+
template: WIDGET_INDEX_CSS_TEMPLATE,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "add",
|
|
67
|
+
path: "tsconfig.json",
|
|
68
|
+
template: WIDGET_TSCONFIG_JSON,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "add",
|
|
72
|
+
path: "babel.config.js",
|
|
73
|
+
template: WIDGET_BABEL_CONFIG,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "add",
|
|
77
|
+
path: ".gitignore",
|
|
78
|
+
template: WIDGET_GITIGNORE,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: "add",
|
|
82
|
+
path: ".eslintignore",
|
|
83
|
+
template: WIDGET_ESLINTIGNORE,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "add",
|
|
87
|
+
path: ".eslintrc",
|
|
88
|
+
template: WIDGET_ESLINTRC,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "add",
|
|
92
|
+
path: "jest.config.js",
|
|
93
|
+
template: WIDGET_JEST_CONFIG,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: "add",
|
|
97
|
+
path: "package.json",
|
|
98
|
+
template: WIDGET_PACKAGE_JSON_TEMPLATE,
|
|
99
|
+
data: { customWidgetVersion, packageCliVersion },
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
};
|
|
103
|
+
const getInitWidgetActions = (basePath, plop) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
addInitActions(basePath, plop);
|
|
105
|
+
const [packageCliVersion, customWidgetVersion] = yield Promise.all([
|
|
106
|
+
getLatestVersionOfLibrary("@infomaximum/package-cli"),
|
|
107
|
+
getLatestVersionOfLibrary("@infomaximum/custom-widget"),
|
|
108
|
+
]);
|
|
109
|
+
return (data) => actions(Object.assign(Object.assign({}, data), { packageCliVersion,
|
|
110
|
+
customWidgetVersion }));
|
|
111
|
+
});
|
|
112
|
+
export { getInitWidgetActions };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { getInitWidgetActions } from "./actions.js";
|
|
3
|
+
import { prompts } from "./prompts.js";
|
|
4
|
+
import { addHelpers } from "./helpers.js";
|
|
5
|
+
const generateWidgetGeneratorName = "widget-generate";
|
|
6
|
+
const getInitWidgetGenerator = (basePath, plop) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
+
addHelpers(plop);
|
|
8
|
+
const actions = yield getInitWidgetActions(basePath, plop);
|
|
9
|
+
plop.setGenerator(generateWidgetGeneratorName, {
|
|
10
|
+
prompts,
|
|
11
|
+
actions,
|
|
12
|
+
});
|
|
13
|
+
return plop.getGenerator(generateWidgetGeneratorName);
|
|
14
|
+
});
|
|
15
|
+
export { getInitWidgetGenerator };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import nodePlop from "node-plop";
|
|
4
|
+
import { getInitWidgetGenerator } from "./generators.js";
|
|
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);
|
|
8
|
+
const plop = yield nodePlop(undefined, {
|
|
9
|
+
destBasePath: createPath,
|
|
10
|
+
force: false,
|
|
11
|
+
});
|
|
12
|
+
const initGenerator = yield getInitWidgetGenerator(createPath, plop);
|
|
13
|
+
const answers = yield initGenerator.runPrompts();
|
|
14
|
+
yield initGenerator.runActions(answers);
|
|
15
|
+
try {
|
|
16
|
+
yield spawnCommand("npm install", {
|
|
17
|
+
cwd: createPath,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(error);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
yield spawnCommand("git init", {
|
|
25
|
+
cwd: createPath,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export { runInitWidget };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const notEmptyValidator = (input) => !!input;
|
|
2
|
+
const prompts = [
|
|
3
|
+
{
|
|
4
|
+
message: "Введите название пакета: ",
|
|
5
|
+
type: "input",
|
|
6
|
+
name: "packageName",
|
|
7
|
+
validate: notEmptyValidator,
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
message: "Введите описание для пакета: ",
|
|
11
|
+
type: "input",
|
|
12
|
+
name: "packageDescription",
|
|
13
|
+
default: "",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
message: "Имя автора пакета: ",
|
|
17
|
+
type: "input",
|
|
18
|
+
name: "author",
|
|
19
|
+
validate: notEmptyValidator,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
export { prompts };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import _webpack from "webpack";
|
|
3
|
+
import { generatePaths } from "../../paths.js";
|
|
4
|
+
import WebpackDevServer from "webpack-dev-server";
|
|
5
|
+
import { getDevServerConfig } from "../../configs/webpack/devServer.js";
|
|
6
|
+
import { merge } from "webpack-merge";
|
|
7
|
+
import { getCommonWidgetConfig } from "../../configs/webpack/common.js";
|
|
8
|
+
const { webpack } = _webpack;
|
|
9
|
+
export const runDevServer = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
+
const PATHS = generatePaths({
|
|
11
|
+
entryPath: options.entry,
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
yield run(PATHS, options);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error === null || error === void 0 ? void 0 : error.message) {
|
|
18
|
+
console.error(error.message);
|
|
19
|
+
}
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const run = (PATHS, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { host, port } = options;
|
|
25
|
+
const mode = "development";
|
|
26
|
+
const configWebpack = [getCommonWidgetConfig(mode, PATHS)];
|
|
27
|
+
const compiler = webpack(merge(configWebpack));
|
|
28
|
+
const devServerConfig = getDevServerConfig({
|
|
29
|
+
host,
|
|
30
|
+
port,
|
|
31
|
+
});
|
|
32
|
+
const devServer = new WebpackDevServer(devServerConfig, compiler);
|
|
33
|
+
["SIGINT", "SIGTERM"].forEach(function (sig) {
|
|
34
|
+
process.on(sig, function () {
|
|
35
|
+
devServer.close();
|
|
36
|
+
process.exit();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
process.stdin.on("end", function () {
|
|
40
|
+
devServer.close();
|
|
41
|
+
process.exit();
|
|
42
|
+
});
|
|
43
|
+
yield devServer.start();
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PACKAGE_ICON_TEMPLATE = "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAAAAACo4kLRAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAACYktHRAD/h4/MvwAAAAd0SU1FB+cFDwwSOXn9HwMAAAC7SURBVBjTbdC7DoJAEAVQ/l1jocIHCCTysBLBF2qIAVQSQ2HUgmgJLAV2yuz2xkZ3hKkmp5k7V6gaRvhulNYQXo71BIzwKFSFPBBC0ZGXrtJKgUMWuHpy01Ye4/G4zfvdNNjzSIml76KhldIfApFMG+h0JObwRRbPLz5j4XkRMx6vHzzNOAQiGhOgjikRwIfCg2ZnFEXyiNjLwgih7xrJXd+g8EDag8Vaxm9WVVmoalbWqrPH/9U1l4zmDYoMYiSNLbKEAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIzLTA1LTE1VDEyOjE4OjQzKzAwOjAwbDmPMwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMy0wNS0xNVQxMjoxODo0MyswMDowMB1kN48AAAAodEVYdGRhdGU6dGltZXN0YW1wADIwMjMtMDUtMTVUMTI6MTg6NTcrMDA6MDBylDLdAAAAAElFTkSuQmCC";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { capitalizeHelperName } from "../../scripts/widget/init/helpers.js";
|
|
3
|
+
export const PACKAGE_MANIFEST_TEMPLATE = `\
|
|
4
|
+
{
|
|
5
|
+
"manifest_version": "1",
|
|
6
|
+
"author": "{{author}}",
|
|
7
|
+
"guid": "${randomUUID()}",
|
|
8
|
+
"type": "{{packageType}}",
|
|
9
|
+
"name": "{{${capitalizeHelperName} packageName}}",
|
|
10
|
+
"systems": [
|
|
11
|
+
{
|
|
12
|
+
"name": "{{packageIconName}}"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"description": {
|
|
16
|
+
"ru": "{{${capitalizeHelperName} packageDescription}}",
|
|
17
|
+
"en": "{{${capitalizeHelperName} packageDescription}}"
|
|
18
|
+
},
|
|
19
|
+
"categories": {
|
|
20
|
+
"ru": [
|
|
21
|
+
{
|
|
22
|
+
"name": "Сторонние"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"en": [
|
|
26
|
+
{
|
|
27
|
+
"name": "Other"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
`;
|