@astral/pack 0.1.0

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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/bin.d.ts +2 -0
  4. package/bin.js +28 -0
  5. package/cli/enums.d.ts +5 -0
  6. package/cli/enums.js +6 -0
  7. package/cli/index.d.ts +2 -0
  8. package/cli/index.js +2 -0
  9. package/cli/parseArgs/index.d.ts +1 -0
  10. package/cli/parseArgs/index.js +1 -0
  11. package/cli/parseArgs/parseArgs.d.ts +2 -0
  12. package/cli/parseArgs/parseArgs.js +10 -0
  13. package/cli/types.d.ts +5 -0
  14. package/cli/types.js +1 -0
  15. package/commands/build/build.d.ts +6 -0
  16. package/commands/build/build.js +48 -0
  17. package/commands/build/index.d.ts +1 -0
  18. package/commands/build/index.js +1 -0
  19. package/commands/compileJs/compileJs.d.ts +6 -0
  20. package/commands/compileJs/compileJs.js +19 -0
  21. package/commands/compileJs/index.d.ts +1 -0
  22. package/commands/compileJs/index.js +1 -0
  23. package/commands/compileTs/compileTs.d.ts +2 -0
  24. package/commands/compileTs/compileTs.js +45 -0
  25. package/commands/compileTs/index.d.ts +1 -0
  26. package/commands/compileTs/index.js +1 -0
  27. package/commands/copyDoc/copyDoc.d.ts +5 -0
  28. package/commands/copyDoc/copyDoc.js +9 -0
  29. package/commands/copyDoc/index.d.ts +1 -0
  30. package/commands/copyDoc/index.js +1 -0
  31. package/commands/copyStatic/copyStatic.d.ts +7 -0
  32. package/commands/copyStatic/copyStatic.js +17 -0
  33. package/commands/copyStatic/index.d.ts +1 -0
  34. package/commands/copyStatic/index.js +1 -0
  35. package/commands/generatePackageJson/generatePackageJson.d.ts +8 -0
  36. package/commands/generatePackageJson/generatePackageJson.js +70 -0
  37. package/commands/generatePackageJson/index.d.ts +1 -0
  38. package/commands/generatePackageJson/index.js +1 -0
  39. package/commands/index.d.ts +7 -0
  40. package/commands/index.js +7 -0
  41. package/commands/rmDist/index.d.ts +1 -0
  42. package/commands/rmDist/index.js +1 -0
  43. package/commands/rmDist/rmDist.d.ts +2 -0
  44. package/commands/rmDist/rmDist.js +17 -0
  45. package/commands/semanticRelease/checkPackageVersion/checkPackageVersion.d.ts +2 -0
  46. package/commands/semanticRelease/checkPackageVersion/checkPackageVersion.js +50 -0
  47. package/commands/semanticRelease/checkPackageVersion/index.d.ts +1 -0
  48. package/commands/semanticRelease/checkPackageVersion/index.js +1 -0
  49. package/commands/semanticRelease/createRelease/createRelease.d.ts +2 -0
  50. package/commands/semanticRelease/createRelease/createRelease.js +25 -0
  51. package/commands/semanticRelease/createRelease/index.d.ts +1 -0
  52. package/commands/semanticRelease/createRelease/index.js +1 -0
  53. package/commands/semanticRelease/defaultConfig.d.ts +39 -0
  54. package/commands/semanticRelease/defaultConfig.js +63 -0
  55. package/commands/semanticRelease/index.d.ts +2 -0
  56. package/commands/semanticRelease/index.js +2 -0
  57. package/config/ConfigService/ConfigService.d.ts +27 -0
  58. package/config/ConfigService/ConfigService.js +76 -0
  59. package/config/ConfigService/index.d.ts +1 -0
  60. package/config/ConfigService/index.js +1 -0
  61. package/config/ConfigService/validation.d.ts +3 -0
  62. package/config/ConfigService/validation.js +28 -0
  63. package/config/defineConfig/defineConfig.d.ts +2 -0
  64. package/config/defineConfig/defineConfig.js +1 -0
  65. package/config/defineConfig/index.d.ts +1 -0
  66. package/config/defineConfig/index.js +1 -0
  67. package/config/index.d.ts +3 -0
  68. package/config/index.js +3 -0
  69. package/config/types.d.ts +54 -0
  70. package/config/types.js +1 -0
  71. package/index.d.ts +1 -0
  72. package/index.js +1 -0
  73. package/node/bin.d.ts +2 -0
  74. package/node/bin.js +30 -0
  75. package/node/cli/enums.d.ts +5 -0
  76. package/node/cli/enums.js +9 -0
  77. package/node/cli/index.d.ts +2 -0
  78. package/node/cli/index.js +18 -0
  79. package/node/cli/parseArgs/index.d.ts +1 -0
  80. package/node/cli/parseArgs/index.js +17 -0
  81. package/node/cli/parseArgs/parseArgs.d.ts +2 -0
  82. package/node/cli/parseArgs/parseArgs.js +14 -0
  83. package/node/cli/types.d.ts +5 -0
  84. package/node/cli/types.js +2 -0
  85. package/node/commands/build/build.d.ts +6 -0
  86. package/node/commands/build/build.js +55 -0
  87. package/node/commands/build/index.d.ts +1 -0
  88. package/node/commands/build/index.js +17 -0
  89. package/node/commands/compileJs/compileJs.d.ts +6 -0
  90. package/node/commands/compileJs/compileJs.js +26 -0
  91. package/node/commands/compileJs/index.d.ts +1 -0
  92. package/node/commands/compileJs/index.js +17 -0
  93. package/node/commands/compileTs/compileTs.d.ts +2 -0
  94. package/node/commands/compileTs/compileTs.js +52 -0
  95. package/node/commands/compileTs/index.d.ts +1 -0
  96. package/node/commands/compileTs/index.js +17 -0
  97. package/node/commands/copyDoc/copyDoc.d.ts +5 -0
  98. package/node/commands/copyDoc/copyDoc.js +13 -0
  99. package/node/commands/copyDoc/index.d.ts +1 -0
  100. package/node/commands/copyDoc/index.js +17 -0
  101. package/node/commands/copyStatic/copyStatic.d.ts +7 -0
  102. package/node/commands/copyStatic/copyStatic.js +24 -0
  103. package/node/commands/copyStatic/index.d.ts +1 -0
  104. package/node/commands/copyStatic/index.js +17 -0
  105. package/node/commands/generatePackageJson/generatePackageJson.d.ts +8 -0
  106. package/node/commands/generatePackageJson/generatePackageJson.js +77 -0
  107. package/node/commands/generatePackageJson/index.d.ts +1 -0
  108. package/node/commands/generatePackageJson/index.js +17 -0
  109. package/node/commands/index.d.ts +7 -0
  110. package/node/commands/index.js +23 -0
  111. package/node/commands/rmDist/index.d.ts +1 -0
  112. package/node/commands/rmDist/index.js +17 -0
  113. package/node/commands/rmDist/rmDist.d.ts +2 -0
  114. package/node/commands/rmDist/rmDist.js +24 -0
  115. package/node/commands/semanticRelease/checkPackageVersion/checkPackageVersion.d.ts +2 -0
  116. package/node/commands/semanticRelease/checkPackageVersion/checkPackageVersion.js +57 -0
  117. package/node/commands/semanticRelease/checkPackageVersion/index.d.ts +1 -0
  118. package/node/commands/semanticRelease/checkPackageVersion/index.js +17 -0
  119. package/node/commands/semanticRelease/createRelease/createRelease.d.ts +2 -0
  120. package/node/commands/semanticRelease/createRelease/createRelease.js +32 -0
  121. package/node/commands/semanticRelease/createRelease/index.d.ts +1 -0
  122. package/node/commands/semanticRelease/createRelease/index.js +17 -0
  123. package/node/commands/semanticRelease/defaultConfig.d.ts +39 -0
  124. package/node/commands/semanticRelease/defaultConfig.js +67 -0
  125. package/node/commands/semanticRelease/index.d.ts +2 -0
  126. package/node/commands/semanticRelease/index.js +18 -0
  127. package/node/config/ConfigService/ConfigService.d.ts +27 -0
  128. package/node/config/ConfigService/ConfigService.js +116 -0
  129. package/node/config/ConfigService/index.d.ts +1 -0
  130. package/node/config/ConfigService/index.js +17 -0
  131. package/node/config/ConfigService/validation.d.ts +3 -0
  132. package/node/config/ConfigService/validation.js +64 -0
  133. package/node/config/defineConfig/defineConfig.d.ts +2 -0
  134. package/node/config/defineConfig/defineConfig.js +5 -0
  135. package/node/config/defineConfig/index.d.ts +1 -0
  136. package/node/config/defineConfig/index.js +17 -0
  137. package/node/config/index.d.ts +3 -0
  138. package/node/config/index.js +19 -0
  139. package/node/config/types.d.ts +54 -0
  140. package/node/config/types.js +2 -0
  141. package/node/index.d.ts +1 -0
  142. package/node/index.js +5 -0
  143. package/node/services/Logger/Logger.d.ts +7 -0
  144. package/node/services/Logger/Logger.js +19 -0
  145. package/node/services/Logger/index.d.ts +1 -0
  146. package/node/services/Logger/index.js +17 -0
  147. package/node/services/index.d.ts +1 -0
  148. package/node/services/index.js +17 -0
  149. package/package.json +45 -0
  150. package/services/Logger/Logger.d.ts +7 -0
  151. package/services/Logger/Logger.js +15 -0
  152. package/services/Logger/index.d.ts +1 -0
  153. package/services/Logger/index.js +1 -0
  154. package/services/index.d.ts +1 -0
  155. package/services/index.js +1 -0
@@ -0,0 +1,25 @@
1
+ import semanticRelease from 'semantic-release';
2
+ import { logger } from '../../../services';
3
+ import { getDefaultConfig } from '../defaultConfig';
4
+ export const createRelease = async (config) => {
5
+ logger.progress('Добавление git тэгов и создание релиза в gitlab');
6
+ try {
7
+ const semanticReleaseConfig = getDefaultConfig(config.semanticRelease);
8
+ const result = await semanticRelease({
9
+ ...semanticReleaseConfig,
10
+ plugins: semanticReleaseConfig.plugins,
11
+ ci: true,
12
+ });
13
+ if (result) {
14
+ const { nextRelease } = result;
15
+ logger.success(`Релиз ${nextRelease.version} успешно создан`);
16
+ }
17
+ else {
18
+ throw new Error('Не удалось провести анализ коммитов');
19
+ }
20
+ }
21
+ catch (err) {
22
+ logger.error('Ошибка создания релиза', err);
23
+ throw err;
24
+ }
25
+ };
@@ -0,0 +1 @@
1
+ export * from './createRelease';
@@ -0,0 +1 @@
1
+ export * from './createRelease';
@@ -0,0 +1,39 @@
1
+ type Params = {
2
+ repositoryUrl: string;
3
+ };
4
+ export declare const defaultBranches: (string | {
5
+ name: string;
6
+ prerelease: boolean;
7
+ })[];
8
+ export declare const commitAnalyzerPlugin: (string | {
9
+ releaseRules: {
10
+ type: string;
11
+ release: string;
12
+ }[];
13
+ })[];
14
+ export declare const getDefaultConfig: ({ repositoryUrl }: Params) => {
15
+ branches: (string | {
16
+ name: string;
17
+ prerelease: boolean;
18
+ })[];
19
+ repositoryUrl: string;
20
+ plugins: ((string | {
21
+ releaseRules: {
22
+ type: string;
23
+ release: string;
24
+ }[];
25
+ })[] | (string | {
26
+ preset: string;
27
+ linkReferences: boolean;
28
+ presetConfig: {
29
+ types: {
30
+ type: string;
31
+ section: string;
32
+ hidden: boolean;
33
+ }[];
34
+ };
35
+ })[] | (string | {
36
+ gitlabUrl: string;
37
+ })[])[];
38
+ };
39
+ export {};
@@ -0,0 +1,63 @@
1
+ export const defaultBranches = [
2
+ 'main',
3
+ 'feat/build',
4
+ { name: 'rc', prerelease: true },
5
+ ];
6
+ export const commitAnalyzerPlugin = [
7
+ '@semantic-release/commit-analyzer',
8
+ {
9
+ releaseRules: [
10
+ { type: 'bug', release: 'patch' },
11
+ { type: 'build', release: 'patch' },
12
+ { type: 'feat', release: 'minor' },
13
+ { type: 'refactor', release: 'patch' },
14
+ { type: 'major', release: 'major' },
15
+ { type: 'doc', release: 'patch' },
16
+ ],
17
+ },
18
+ ];
19
+ export const getDefaultConfig = ({ repositoryUrl }) => ({
20
+ branches: defaultBranches,
21
+ repositoryUrl,
22
+ plugins: [
23
+ commitAnalyzerPlugin,
24
+ [
25
+ '@semantic-release/release-notes-generator',
26
+ {
27
+ // cspell:ignore conventionalcommits
28
+ preset: 'conventionalcommits',
29
+ linkReferences: true,
30
+ presetConfig: {
31
+ types: [
32
+ {
33
+ type: 'bug',
34
+ section: '🐞 Bugs',
35
+ hidden: false,
36
+ },
37
+ {
38
+ type: 'feat',
39
+ section: '✨ Features',
40
+ hidden: false,
41
+ },
42
+ {
43
+ type: 'build',
44
+ section: '📦 Build',
45
+ hidden: false,
46
+ },
47
+ {
48
+ type: 'doc',
49
+ section: '📄 Docs',
50
+ hidden: false,
51
+ },
52
+ ],
53
+ },
54
+ },
55
+ ],
56
+ [
57
+ '@semantic-release/gitlab',
58
+ {
59
+ gitlabUrl: 'https://git.astralnalog.ru',
60
+ },
61
+ ],
62
+ ],
63
+ });
@@ -0,0 +1,2 @@
1
+ export * from './checkPackageVersion';
2
+ export * from './createRelease';
@@ -0,0 +1,2 @@
1
+ export * from './checkPackageVersion';
2
+ export * from './createRelease';
@@ -0,0 +1,27 @@
1
+ import { CopyStaticFilesConfig, Lang, PackConfig } from '../types';
2
+ export declare class ConfigService {
3
+ readonly projectPath: string;
4
+ /**
5
+ * Директория, где хранятся приватные файлы для @astral/pack
6
+ */
7
+ readonly packPrivateDirPath: string;
8
+ readonly lang: Lang;
9
+ private readonly configName;
10
+ private readonly logger;
11
+ private readonly config;
12
+ constructor();
13
+ get sourcePath(): string;
14
+ get distDirName(): string;
15
+ get distPath(): string;
16
+ get copyStaticFiles(): CopyStaticFilesConfig | undefined;
17
+ get format(): PackConfig['format'];
18
+ get tsConfigName(): string;
19
+ get semanticRelease(): {
20
+ versionsFileName: string;
21
+ repositoryUrl: string;
22
+ releaseGroup?: string[];
23
+ };
24
+ get packageExports(): import("../types").PackageExports | undefined;
25
+ private parseConfig;
26
+ private checkLanguage;
27
+ }
@@ -0,0 +1,76 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import * as v from '@astral/validations';
4
+ import { Logger } from '../../services';
5
+ import { validateConfig } from './validation';
6
+ export class ConfigService {
7
+ projectPath = process.cwd();
8
+ /**
9
+ * Директория, где хранятся приватные файлы для @astral/pack
10
+ */
11
+ packPrivateDirPath;
12
+ lang;
13
+ configName = 'pack.config.js';
14
+ logger = new Logger();
15
+ config;
16
+ constructor() {
17
+ this.config = this.parseConfig();
18
+ this.lang = this.checkLanguage();
19
+ this.packPrivateDirPath = path.join(this.projectPath, '.pack');
20
+ }
21
+ get sourcePath() {
22
+ if (fs.existsSync(path.join(this.projectPath, 'src'))) {
23
+ return path.join(this.projectPath, 'src');
24
+ }
25
+ return this.projectPath;
26
+ }
27
+ get distDirName() {
28
+ return this.config.distDirName || 'lib';
29
+ }
30
+ get distPath() {
31
+ return path.join(this.projectPath, this.distDirName);
32
+ }
33
+ get copyStaticFiles() {
34
+ if (!this.config.copyStaticFiles) {
35
+ return undefined;
36
+ }
37
+ return { ignoreSrc: true, ...this.config.copyStaticFiles };
38
+ }
39
+ get format() {
40
+ return this.config.format;
41
+ }
42
+ get tsConfigName() {
43
+ return this.config.tsConfigName || 'tsconfig.json';
44
+ }
45
+ get semanticRelease() {
46
+ return {
47
+ ...this.config.semanticRelease,
48
+ versionsFileName: 'versions.json',
49
+ };
50
+ }
51
+ get packageExports() {
52
+ return this.config.packageExports;
53
+ }
54
+ parseConfig = () => {
55
+ const configPath = path.join(this.projectPath, this.configName);
56
+ if (!fs.existsSync(configPath)) {
57
+ this.logger.error('pack.config.js не найден');
58
+ throw Error('pack.config.js не найден');
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
61
+ const config = require(configPath);
62
+ const validationError = validateConfig(config);
63
+ if (validationError) {
64
+ this.logger.error('Ошибка валидации config', v.toPrettyError(validationError));
65
+ throw new Error('Ошибка валидации config');
66
+ }
67
+ return config;
68
+ };
69
+ checkLanguage = () => {
70
+ const tsConfigPath = path.join(this.projectPath, this.tsConfigName);
71
+ if (fs.existsSync(tsConfigPath)) {
72
+ return 'ts';
73
+ }
74
+ return 'js';
75
+ };
76
+ }
@@ -0,0 +1 @@
1
+ export * from './ConfigService';
@@ -0,0 +1 @@
1
+ export * from './ConfigService';
@@ -0,0 +1,3 @@
1
+ export declare const validateConfig: import("@astral/validations/core").Guard<{}, {
2
+ isPartial?: boolean;
3
+ }>;
@@ -0,0 +1,28 @@
1
+ import * as v from '@astral/validations';
2
+ export const validateConfig = v.object({
3
+ distDirName: v.optional(v.string()),
4
+ copyStaticFiles: v.optional(v.object({
5
+ filter: v.array(v.arrayItem(v.string())),
6
+ ignoreSrc: v.optional(v.boolean()),
7
+ })),
8
+ tsConfigName: v.optional(v.string()),
9
+ format: v.array(v.arrayItem(v.string())),
10
+ semanticRelease: v.object({
11
+ repositoryUrl: v.string(),
12
+ releaseGroup: v.optional(v.array(v.arrayItem(v.string()))),
13
+ }),
14
+ packageExports: (value) => {
15
+ const objectError = v.optional(v.object({}))(value);
16
+ if (objectError) {
17
+ return objectError;
18
+ }
19
+ const errors = Object.values(value)
20
+ .map((exportValue) => v.object({
21
+ require: v.string(),
22
+ module: v.string(),
23
+ types: v.string(),
24
+ })(exportValue))
25
+ .filter(Boolean);
26
+ return errors[0];
27
+ },
28
+ });
@@ -0,0 +1,2 @@
1
+ import { PackConfig } from '../types';
2
+ export declare const defineConfig: (config: PackConfig) => PackConfig;
@@ -0,0 +1 @@
1
+ export const defineConfig = (config) => config;
@@ -0,0 +1 @@
1
+ export * from './defineConfig';
@@ -0,0 +1 @@
1
+ export * from './defineConfig';
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './ConfigService';
3
+ export * from './defineConfig';
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './ConfigService';
3
+ export * from './defineConfig';
@@ -0,0 +1,54 @@
1
+ export type CopyStaticFilesConfig = {
2
+ /**
3
+ * Используется glob паттерн
4
+ * @example ['src/declarations/*d.ts']
5
+ */
6
+ filter: string[];
7
+ /**
8
+ * Если true, то при перемещении в пакет удалит src в пути
9
+ * @default true
10
+ */
11
+ ignoreSrc?: boolean;
12
+ };
13
+ export type SemanticReleaseConfig = {
14
+ /**
15
+ * @example https://git.astralnalog.ru/frontend.shared/pack
16
+ */
17
+ repositoryUrl: string;
18
+ /**
19
+ * Имена пакетов, которые должны релизиться синхронно одной версией.
20
+ * Подменить версии этих пакетов в deps на текущую версию пакета
21
+ */
22
+ releaseGroup?: string[];
23
+ };
24
+ export type PackageExportsItem = {
25
+ module: string;
26
+ require: string;
27
+ types: string;
28
+ };
29
+ export type PackageExports = Record<string, PackageExportsItem>;
30
+ export type PackConfig = {
31
+ /**
32
+ * @default берет module из tsconfig.json
33
+ */
34
+ format: Array<'esm' | 'cjs'>;
35
+ /**
36
+ * @default lib
37
+ */
38
+ distDirName?: string;
39
+ /**
40
+ * Копирует статичные файлы в пакет. Используется glob паттерн
41
+ * @example src/declarations/*d.ts
42
+ */
43
+ copyStaticFiles?: CopyStaticFilesConfig;
44
+ /**
45
+ * @default tsconfig.json
46
+ */
47
+ tsConfigName?: string;
48
+ semanticRelease: SemanticReleaseConfig;
49
+ /**
50
+ * exports свойство package.json
51
+ */
52
+ packageExports?: PackageExports;
53
+ };
54
+ export type Lang = 'js' | 'ts';
@@ -0,0 +1 @@
1
+ export {};
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { type PackConfig, defineConfig } from './config';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { defineConfig } from './config';
package/node/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/node/bin.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commands_1 = require("./commands");
5
+ const config_1 = require("./config");
6
+ const cli_1 = require("./cli");
7
+ console.log('process', process.env.CUSTOM);
8
+ const start = async () => {
9
+ const { command, packageVersion } = (0, cli_1.parseArgs)();
10
+ let configService;
11
+ try {
12
+ configService = new config_1.ConfigService();
13
+ }
14
+ catch (err) {
15
+ console.error(err);
16
+ process.exit(1);
17
+ }
18
+ switch (command) {
19
+ case cli_1.CLICommand.CheckPackageVersion:
20
+ await (0, commands_1.checkPackageVersion)(configService);
21
+ break;
22
+ case cli_1.CLICommand.Build:
23
+ await (0, commands_1.build)({ packageVersion }, configService);
24
+ break;
25
+ case cli_1.CLICommand.CreateRelease:
26
+ await (0, commands_1.createRelease)(configService);
27
+ break;
28
+ }
29
+ };
30
+ start();
@@ -0,0 +1,5 @@
1
+ export declare enum CLICommand {
2
+ Build = "build",
3
+ CheckPackageVersion = "check-package-version",
4
+ CreateRelease = "create-release"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLICommand = void 0;
4
+ var CLICommand;
5
+ (function (CLICommand) {
6
+ CLICommand["Build"] = "build";
7
+ CLICommand["CheckPackageVersion"] = "check-package-version";
8
+ CLICommand["CreateRelease"] = "create-release";
9
+ })(CLICommand || (exports.CLICommand = CLICommand = {}));
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export * from './parseArgs';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./enums"), exports);
18
+ __exportStar(require("./parseArgs"), exports);
@@ -0,0 +1 @@
1
+ export * from './parseArgs';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./parseArgs"), exports);
@@ -0,0 +1,2 @@
1
+ import { CLIArgs } from '../types';
2
+ export declare const parseArgs: () => CLIArgs;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseArgs = void 0;
4
+ const enums_1 = require("../enums");
5
+ const parseArgs = () => process.argv.reduce((result, arg) => {
6
+ if (Object.values(enums_1.CLICommand).includes(arg)) {
7
+ result.command = arg;
8
+ }
9
+ if (arg.includes('--packageVersion')) {
10
+ result.packageVersion = arg.split('=')[1];
11
+ }
12
+ return result;
13
+ }, { command: enums_1.CLICommand.Build });
14
+ exports.parseArgs = parseArgs;
@@ -0,0 +1,5 @@
1
+ import { CLICommand } from './enums';
2
+ export type CLIArgs = {
3
+ command: CLICommand;
4
+ packageVersion?: string;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { ConfigService } from '../../config';
2
+ type Params = {
3
+ packageVersion?: string;
4
+ };
5
+ export declare const build: (params: Params, config: ConfigService) => Promise<void>;
6
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.build = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const compileJs_1 = require("../compileJs");
10
+ const generatePackageJson_1 = require("../generatePackageJson");
11
+ const compileTs_1 = require("../compileTs");
12
+ const services_1 = require("../../services");
13
+ const rmDist_1 = require("../rmDist");
14
+ const copyStatic_1 = require("../copyStatic");
15
+ const copyDoc_1 = require("../copyDoc");
16
+ const build = async (params, config) => {
17
+ const { packPrivateDirPath, semanticRelease, projectPath } = config;
18
+ let newPackageVersion = '';
19
+ const versionsFilePath = path_1.default.join(packPrivateDirPath, semanticRelease.versionsFileName);
20
+ if (params.packageVersion) {
21
+ newPackageVersion = params.packageVersion;
22
+ }
23
+ else {
24
+ if (fs_1.default.existsSync(versionsFilePath)) {
25
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
26
+ const { currentVersion, nextVersion } = require(`${packPrivateDirPath}/${semanticRelease.versionsFileName}`);
27
+ newPackageVersion = nextVersion;
28
+ services_1.logger.info('Версия пакета взята из файла', versionsFilePath, {
29
+ currentVersion,
30
+ nextVersion,
31
+ });
32
+ }
33
+ }
34
+ if (!newPackageVersion) {
35
+ const errorMessage = 'Не указана версия пакета для сборки';
36
+ services_1.logger.error(errorMessage);
37
+ throw new Error(errorMessage);
38
+ }
39
+ services_1.logger.info('Версия пакета', newPackageVersion);
40
+ (0, rmDist_1.rmDist)(config);
41
+ if (config.copyStaticFiles) {
42
+ await (0, copyStatic_1.copyStatic)(config.copyStaticFiles, config);
43
+ }
44
+ const originPackageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(projectPath, 'package.json'), 'utf8'));
45
+ const { lang } = config;
46
+ if (lang === 'js') {
47
+ await (0, compileJs_1.compileJs)({ originPackageJson }, config);
48
+ }
49
+ else {
50
+ await (0, compileTs_1.compileTs)(config);
51
+ }
52
+ await (0, generatePackageJson_1.generatePackageJson)({ packageVersion: newPackageVersion, originPackageJson }, config);
53
+ await (0, copyDoc_1.copyDoc)(config);
54
+ };
55
+ exports.build = build;
@@ -0,0 +1 @@
1
+ export * from './build';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./build"), exports);
@@ -0,0 +1,6 @@
1
+ import { ConfigService } from '../../config';
2
+ type Params = {
3
+ originPackageJson: Record<string, unknown>;
4
+ };
5
+ export declare const compileJs: ({ originPackageJson }: Params, config: ConfigService) => Promise<void>;
6
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compileJs = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const copyStatic_1 = require("../copyStatic");
9
+ const services_1 = require("../../services");
10
+ const compileJs = async ({ originPackageJson }, config) => {
11
+ const { main } = originPackageJson;
12
+ if (!main) {
13
+ throw Error('В package.json отсутствует main поле');
14
+ }
15
+ const srcDir = path_1.default.dirname(main).replace('./', '').replace('.', '') || 'src';
16
+ services_1.logger.progress('Копирование js файлов');
17
+ return (0, copyStatic_1.copyStatic)({ filter: [`${srcDir}/**/*.js`], ignoreSrc: true }, config)
18
+ .then(() => {
19
+ services_1.logger.success('js файлы успешно скопированы');
20
+ })
21
+ .catch((err) => {
22
+ services_1.logger.error('Ошибка копирования js файлов', err);
23
+ throw err;
24
+ });
25
+ };
26
+ exports.compileJs = compileJs;
@@ -0,0 +1 @@
1
+ export * from './compileJs';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compileJs"), exports);
@@ -0,0 +1,2 @@
1
+ import { ConfigService } from '../../config';
2
+ export declare const compileTs: (config: ConfigService) => Promise<void>;