@infomaximum/package-cli 1.3.1 → 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.
- package/dist/arguments.js +29 -0
- package/dist/configs/webpack/buildPa/321/201kage.js +63 -0
- package/dist/{lib/configs → configs}/webpack/common.js +33 -37
- package/dist/configs/webpack/devServer.js +14 -0
- package/dist/index.js +7 -0
- package/dist/paths.js +67 -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 +48 -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,63 @@
|
|
|
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
|
+
const packageFilename = "main";
|
|
7
|
+
export const getPackageConfig = (mode, PATHS) => {
|
|
8
|
+
const widgetVersion = require(PATHS.appPackageJson).version;
|
|
9
|
+
const manifestPackageName = require(PATHS.packageManifest).name;
|
|
10
|
+
return {
|
|
11
|
+
mode,
|
|
12
|
+
name: "package",
|
|
13
|
+
entry: [
|
|
14
|
+
PATHS.packageManifest,
|
|
15
|
+
path.resolve(PATHS.appBuild, `${widgetArchiveName}.${archiveExt}`),
|
|
16
|
+
],
|
|
17
|
+
output: {
|
|
18
|
+
path: PATHS.appBuild,
|
|
19
|
+
filename: packageFilename,
|
|
20
|
+
clean: true,
|
|
21
|
+
},
|
|
22
|
+
module: {
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
test: /manifest.json$/i,
|
|
26
|
+
type: "asset/resource",
|
|
27
|
+
generator: {
|
|
28
|
+
filename: "manifest[ext]",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
test: new RegExp(`.${archiveExt}$`, "i"),
|
|
33
|
+
type: "asset/resource",
|
|
34
|
+
generator: {
|
|
35
|
+
filename: "[name][ext]",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
plugins: [
|
|
41
|
+
new CopyWebpackPlugin({
|
|
42
|
+
patterns: [{ from: PATHS.packagePath }],
|
|
43
|
+
}),
|
|
44
|
+
new ZipPlugin({
|
|
45
|
+
filename: `${manifestPackageName}_${widgetVersion}`,
|
|
46
|
+
extension: archiveExt,
|
|
47
|
+
exclude: [packageFilename],
|
|
48
|
+
}),
|
|
49
|
+
new JsonModifyWebpackPlugin({
|
|
50
|
+
matchers: [
|
|
51
|
+
{
|
|
52
|
+
matcher: /^manifest.json$/,
|
|
53
|
+
action: (currentJsonContent) => {
|
|
54
|
+
currentJsonContent.version = widgetVersion;
|
|
55
|
+
return currentJsonContent;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
dependencies: [buildWidgetConfigName],
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var DEV_SERVER_HOST = "0.0.0.0";
|
|
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
|
+
const { ProgressPlugin } = webpack;
|
|
10
|
+
const isProduction = (mode) => mode === "production";
|
|
11
|
+
const isDevelopment = (mode) => mode === "development";
|
|
12
|
+
export const buildWidgetConfigName = "build-widget";
|
|
13
|
+
export const widgetArchiveName = "widget";
|
|
14
|
+
export const archiveExt = "zip";
|
|
15
|
+
const DEV_SERVER_HOST = "0.0.0.0";
|
|
16
|
+
const DEV_SERVER_PORT = 5555;
|
|
17
|
+
export const getCommonWidgetConfig = (mode, PATHS) => {
|
|
21
18
|
return {
|
|
22
|
-
mode
|
|
23
|
-
name:
|
|
19
|
+
mode,
|
|
20
|
+
name: buildWidgetConfigName,
|
|
24
21
|
entry: [PATHS.moduleIndex, PATHS.manifestJson],
|
|
25
22
|
output: {
|
|
26
23
|
path: PATHS.appBuild,
|
|
@@ -29,8 +26,8 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
29
26
|
clean: true,
|
|
30
27
|
},
|
|
31
28
|
plugins: [
|
|
32
|
-
new
|
|
33
|
-
new
|
|
29
|
+
new ProgressPlugin(),
|
|
30
|
+
new ForkTsCheckerWebpackPlugin({
|
|
34
31
|
typescript: {
|
|
35
32
|
mode: "write-references",
|
|
36
33
|
diagnosticOptions: {
|
|
@@ -39,18 +36,18 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
39
36
|
},
|
|
40
37
|
},
|
|
41
38
|
}),
|
|
42
|
-
new
|
|
43
|
-
filename:
|
|
44
|
-
extension:
|
|
39
|
+
new ZipPlugin({
|
|
40
|
+
filename: widgetArchiveName,
|
|
41
|
+
extension: archiveExt,
|
|
45
42
|
}),
|
|
46
|
-
isDevelopment(mode) && new
|
|
43
|
+
isDevelopment(mode) && new ReactRefreshWebpackPlugin(),
|
|
47
44
|
isDevelopment(mode) &&
|
|
48
|
-
new
|
|
45
|
+
new JsonModifyWebpackPlugin({
|
|
49
46
|
matchers: [
|
|
50
47
|
{
|
|
51
48
|
matcher: /^manifest.json$/,
|
|
52
|
-
action:
|
|
53
|
-
currentJsonContent.entry =
|
|
49
|
+
action: (currentJsonContent) => {
|
|
50
|
+
currentJsonContent.entry = `http://${DEV_SERVER_HOST}:${DEV_SERVER_PORT}/${currentJsonContent.entry}`;
|
|
54
51
|
return currentJsonContent;
|
|
55
52
|
},
|
|
56
53
|
},
|
|
@@ -192,19 +189,18 @@ var getCommonWidgetConfig = function (mode, PATHS) {
|
|
|
192
189
|
minimize: true,
|
|
193
190
|
splitChunks: false,
|
|
194
191
|
minimizer: [
|
|
195
|
-
new
|
|
196
|
-
minify:
|
|
192
|
+
new TerserWebpackPlugin({
|
|
193
|
+
minify: TerserWebpackPlugin.terserMinify,
|
|
197
194
|
parallel: true,
|
|
198
195
|
}),
|
|
199
|
-
new
|
|
196
|
+
new CssMinimizerPlugin(),
|
|
200
197
|
],
|
|
201
198
|
}
|
|
202
199
|
: undefined,
|
|
203
200
|
resolve: {
|
|
204
|
-
extensions: [".tsx", ".ts", "
|
|
205
|
-
plugins: [new
|
|
201
|
+
extensions: [".tsx", ".ts", ""],
|
|
202
|
+
plugins: [new TsconfigPathsPlugin()],
|
|
206
203
|
},
|
|
207
204
|
devtool: isProduction(mode) ? false : "cheap-module-source-map",
|
|
208
205
|
};
|
|
209
206
|
};
|
|
210
|
-
exports.getCommonWidgetConfig = getCommonWidgetConfig;
|
package/dist/index.js
ADDED
package/dist/paths.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const appDirectory = fs.realpathSync(process.cwd());
|
|
4
|
+
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
|
|
5
|
+
const moduleFileExtensions = [
|
|
6
|
+
"web.mjs",
|
|
7
|
+
"mjs",
|
|
8
|
+
"web.js",
|
|
9
|
+
"js",
|
|
10
|
+
"web.ts",
|
|
11
|
+
"ts",
|
|
12
|
+
"web.tsx",
|
|
13
|
+
"tsx",
|
|
14
|
+
"json",
|
|
15
|
+
"web.jsx",
|
|
16
|
+
"jsx",
|
|
17
|
+
"module.ts",
|
|
18
|
+
"module.tsx",
|
|
19
|
+
];
|
|
20
|
+
const resolveModule = (resolveFn, filePath) => {
|
|
21
|
+
const extension = moduleFileExtensions.find((extension) => fs.existsSync(resolveFn(`${filePath}.${extension}`)));
|
|
22
|
+
if (extension) {
|
|
23
|
+
return resolveFn(`${filePath}.${extension}`);
|
|
24
|
+
}
|
|
25
|
+
return resolveFn(`${filePath}.js`);
|
|
26
|
+
};
|
|
27
|
+
export const generatePaths = (args) => {
|
|
28
|
+
const packagePath = resolveApp("package");
|
|
29
|
+
return {
|
|
30
|
+
appPath: resolveApp("."),
|
|
31
|
+
appBuild: resolveApp("build"),
|
|
32
|
+
moduleIndex: generateIndexPath(args.entryPath),
|
|
33
|
+
appPackageJson: resolveApp("package.json"),
|
|
34
|
+
manifestJson: resolveApp("manifest.json"),
|
|
35
|
+
packagePath,
|
|
36
|
+
packageManifest: resolveApp(path.resolve(packagePath, "manifest.json")),
|
|
37
|
+
appTsConfig: resolveApp("tsconfig.json"),
|
|
38
|
+
appNodeModules: resolveApp("node_modules"),
|
|
39
|
+
publicPath: "/",
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export const MODE = {
|
|
43
|
+
DEV: "development",
|
|
44
|
+
PROD: "production",
|
|
45
|
+
};
|
|
46
|
+
export const generateIndexPath = (entryPath) => {
|
|
47
|
+
var _a;
|
|
48
|
+
const indexSrcPath = resolveModule(resolveApp, "src/index");
|
|
49
|
+
if (entryPath && fs.existsSync(entryPath)) {
|
|
50
|
+
return entryPath;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const mainIndexPath = path.resolve(process.cwd(), (_a = require(resolveApp("package.json"))) === null || _a === void 0 ? void 0 : _a.main);
|
|
54
|
+
if (mainIndexPath && fs.existsSync(mainIndexPath)) {
|
|
55
|
+
return mainIndexPath;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error("Не найдена секция main в package.json");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
if (fs.existsSync(indexSrcPath)) {
|
|
63
|
+
return indexSrcPath;
|
|
64
|
+
}
|
|
65
|
+
console.error("Не найден входной файл");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
};
|
|
@@ -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
|
+
`;
|