@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Astral.Soft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @astral/pack
2
+
3
+ Инструмент для сборки и релиза npm пакетов:
4
+ - Собирает пакеты в esm и cjs
5
+ - Копирует статичные файлы
6
+ - Генерирует package.json
7
+ - Semantic-release
8
+ - Проверяет актуальную версию пакета
9
+ - Создает релиз в gitlab и тэг в git
10
+
11
+ ## Installation
12
+
13
+ ```shell
14
+ npm i --save @astral/utils
15
+ ```
16
+
17
+ ```shell
18
+ yarn add @astral/utils
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Build
24
+
25
+ `pack.config.js`
26
+ ```js
27
+ const { defineConfig } = require('@astral/pack');
28
+
29
+ module.exports = defineConfig({
30
+ // Сборка в esm и cjs
31
+ format: ['esm', 'cjs'],
32
+ tsConfigName: 'tsconfig.build.json',
33
+ // Скопирует файлы в lib директорию
34
+ copyStaticFiles: {
35
+ filter: ['src/**/*.d.ts'],
36
+ ignoreSrc: true,
37
+ },
38
+ // Добавит к root exports дополнительный
39
+ packageExports: {
40
+ './server': {
41
+ module: './server/index.js',
42
+ require: './node/server/index.js',
43
+ types: './server/index.d.ts',
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ ```shell
50
+ pack build --package-version=1.0.0
51
+ ```
52
+
53
+ ### Build в связке с sematic-release
54
+
55
+ Запишет в `.pack/versions.json` новую версию пакета на основе анализа коммитов:
56
+ ```shell
57
+ pack check-package-version
58
+ ```
59
+
60
+ Заберет новую версию пакета из `.pack/versions.json`
61
+ ```shell
62
+ pack build
63
+ ```
64
+
65
+ ## Создание релиза в git и gitlab
66
+
67
+ ```shell
68
+ pack create-release
69
+ ```
70
+
71
+ Создаст git тэг и релиз в gitlab.
72
+
73
+ ## Exports
74
+
75
+ По-дефолту добавляет exports вида:
76
+ ```js
77
+ {
78
+ '.': {
79
+ module: './index.js',
80
+ require: './node/index.js',
81
+ types: './index.d.ts'
82
+ },
83
+ }
84
+ ```
85
+
86
+ Для добавления доп. exports необходимо использовать `packageExports` в `pack.config.js`:
87
+ ```js
88
+ module.exports = {
89
+ packageExports: {
90
+ './server': {
91
+ module: './server/index.js',
92
+ require: './node/server/index.js',
93
+ types: './server/index.d.ts',
94
+ },
95
+ },
96
+ };
97
+ ```
98
+
99
+ ## Синхронный релиз пакетов
100
+
101
+ Для того чтобы deps пакета были синхронизированы с основным пакетом необходимо использовать `semanticRelease.releaseGroup`:
102
+ ```js
103
+ module.exports = {
104
+ semanticRelease: {
105
+ repositoryUrl: 'https://git.astralnalog.ru/frontend.shared/pack',
106
+ releaseGroup: ['@astral/validations'],
107
+ },
108
+ };
109
+ ```
110
+
111
+ `@astral/validations` будет иметь после сборки ту же версию, что и основной пакет.
package/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin.js ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ import { build, checkPackageVersion, createRelease } from './commands';
3
+ import { ConfigService } from './config';
4
+ import { CLICommand, parseArgs } from './cli';
5
+ console.log('process', process.env.CUSTOM);
6
+ const start = async () => {
7
+ const { command, packageVersion } = parseArgs();
8
+ let configService;
9
+ try {
10
+ configService = new ConfigService();
11
+ }
12
+ catch (err) {
13
+ console.error(err);
14
+ process.exit(1);
15
+ }
16
+ switch (command) {
17
+ case CLICommand.CheckPackageVersion:
18
+ await checkPackageVersion(configService);
19
+ break;
20
+ case CLICommand.Build:
21
+ await build({ packageVersion }, configService);
22
+ break;
23
+ case CLICommand.CreateRelease:
24
+ await createRelease(configService);
25
+ break;
26
+ }
27
+ };
28
+ start();
package/cli/enums.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare enum CLICommand {
2
+ Build = "build",
3
+ CheckPackageVersion = "check-package-version",
4
+ CreateRelease = "create-release"
5
+ }
package/cli/enums.js ADDED
@@ -0,0 +1,6 @@
1
+ export var CLICommand;
2
+ (function (CLICommand) {
3
+ CLICommand["Build"] = "build";
4
+ CLICommand["CheckPackageVersion"] = "check-package-version";
5
+ CLICommand["CreateRelease"] = "create-release";
6
+ })(CLICommand || (CLICommand = {}));
package/cli/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export * from './parseArgs';
package/cli/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export * from './parseArgs';
@@ -0,0 +1 @@
1
+ export * from './parseArgs';
@@ -0,0 +1 @@
1
+ export * from './parseArgs';
@@ -0,0 +1,2 @@
1
+ import { CLIArgs } from '../types';
2
+ export declare const parseArgs: () => CLIArgs;
@@ -0,0 +1,10 @@
1
+ import { CLICommand } from '../enums';
2
+ export const parseArgs = () => process.argv.reduce((result, arg) => {
3
+ if (Object.values(CLICommand).includes(arg)) {
4
+ result.command = arg;
5
+ }
6
+ if (arg.includes('--packageVersion')) {
7
+ result.packageVersion = arg.split('=')[1];
8
+ }
9
+ return result;
10
+ }, { command: CLICommand.Build });
package/cli/types.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { CLICommand } from './enums';
2
+ export type CLIArgs = {
3
+ command: CLICommand;
4
+ packageVersion?: string;
5
+ };
package/cli/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -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,48 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { compileJs } from '../compileJs';
4
+ import { generatePackageJson } from '../generatePackageJson';
5
+ import { compileTs } from '../compileTs';
6
+ import { logger } from '../../services';
7
+ import { rmDist } from '../rmDist';
8
+ import { copyStatic } from '../copyStatic';
9
+ import { copyDoc } from '../copyDoc';
10
+ export const build = async (params, config) => {
11
+ const { packPrivateDirPath, semanticRelease, projectPath } = config;
12
+ let newPackageVersion = '';
13
+ const versionsFilePath = path.join(packPrivateDirPath, semanticRelease.versionsFileName);
14
+ if (params.packageVersion) {
15
+ newPackageVersion = params.packageVersion;
16
+ }
17
+ else {
18
+ if (fs.existsSync(versionsFilePath)) {
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ const { currentVersion, nextVersion } = require(`${packPrivateDirPath}/${semanticRelease.versionsFileName}`);
21
+ newPackageVersion = nextVersion;
22
+ logger.info('Версия пакета взята из файла', versionsFilePath, {
23
+ currentVersion,
24
+ nextVersion,
25
+ });
26
+ }
27
+ }
28
+ if (!newPackageVersion) {
29
+ const errorMessage = 'Не указана версия пакета для сборки';
30
+ logger.error(errorMessage);
31
+ throw new Error(errorMessage);
32
+ }
33
+ logger.info('Версия пакета', newPackageVersion);
34
+ rmDist(config);
35
+ if (config.copyStaticFiles) {
36
+ await copyStatic(config.copyStaticFiles, config);
37
+ }
38
+ const originPackageJson = JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json'), 'utf8'));
39
+ const { lang } = config;
40
+ if (lang === 'js') {
41
+ await compileJs({ originPackageJson }, config);
42
+ }
43
+ else {
44
+ await compileTs(config);
45
+ }
46
+ await generatePackageJson({ packageVersion: newPackageVersion, originPackageJson }, config);
47
+ await copyDoc(config);
48
+ };
@@ -0,0 +1 @@
1
+ export * from './build';
@@ -0,0 +1 @@
1
+ export * from './build';
@@ -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,19 @@
1
+ import path from 'path';
2
+ import { copyStatic } from '../copyStatic';
3
+ import { logger } from '../../services';
4
+ export const compileJs = async ({ originPackageJson }, config) => {
5
+ const { main } = originPackageJson;
6
+ if (!main) {
7
+ throw Error('В package.json отсутствует main поле');
8
+ }
9
+ const srcDir = path.dirname(main).replace('./', '').replace('.', '') || 'src';
10
+ logger.progress('Копирование js файлов');
11
+ return copyStatic({ filter: [`${srcDir}/**/*.js`], ignoreSrc: true }, config)
12
+ .then(() => {
13
+ logger.success('js файлы успешно скопированы');
14
+ })
15
+ .catch((err) => {
16
+ logger.error('Ошибка копирования js файлов', err);
17
+ throw err;
18
+ });
19
+ };
@@ -0,0 +1 @@
1
+ export * from './compileJs';
@@ -0,0 +1 @@
1
+ export * from './compileJs';
@@ -0,0 +1,2 @@
1
+ import { ConfigService } from '../../config';
2
+ export declare const compileTs: (config: ConfigService) => Promise<void>;
@@ -0,0 +1,45 @@
1
+ import path from 'path';
2
+ import { spawn } from 'node:child_process';
3
+ import { logger } from '../../services';
4
+ export const compileTs = (config) => {
5
+ const { tsConfigName, format, projectPath, distPath } = config;
6
+ const promises = [];
7
+ const execTs = (childProcess) => {
8
+ const { promise, resolve, reject } = Promise.withResolvers();
9
+ promises.push(promise);
10
+ childProcess.on('error', (err) => {
11
+ reject(err);
12
+ });
13
+ childProcess.on('exit', () => {
14
+ resolve();
15
+ });
16
+ };
17
+ logger.progress('Build ts файлов');
18
+ if (format?.includes('cjs')) {
19
+ execTs(spawn('tsc', [
20
+ '-p',
21
+ path.join(projectPath, tsConfigName),
22
+ '--module',
23
+ 'commonjs',
24
+ '--outDir',
25
+ path.join(distPath, 'node'),
26
+ ],
27
+ // Вывод логов в консоль
28
+ { stdio: 'inherit' }));
29
+ }
30
+ if (format?.includes('esm')) {
31
+ execTs(spawn('tsc', [
32
+ '-p',
33
+ path.join(projectPath, tsConfigName),
34
+ '--module',
35
+ 'es2022',
36
+ '--outDir',
37
+ distPath,
38
+ ],
39
+ // Вывод логов в консоль
40
+ { stdio: 'inherit' }));
41
+ }
42
+ return Promise.all(promises).then(() => {
43
+ logger.success('Сборка прошла успешно');
44
+ });
45
+ };
@@ -0,0 +1 @@
1
+ export * from './compileTs';
@@ -0,0 +1 @@
1
+ export * from './compileTs';
@@ -0,0 +1,5 @@
1
+ import { ConfigService } from '../../config';
2
+ /**
3
+ * Копирует README и license
4
+ */
5
+ export declare const copyDoc: (config: ConfigService) => Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { copyStatic } from '../copyStatic';
2
+ import { logger } from '../../services';
3
+ /**
4
+ * Копирует README и license
5
+ */
6
+ export const copyDoc = async (config) => {
7
+ logger.progress('Копирование README.md и LICENSE');
8
+ return copyStatic({ filter: ['README.md', 'LICENSE'] }, config);
9
+ };
@@ -0,0 +1 @@
1
+ export * from './copyDoc';
@@ -0,0 +1 @@
1
+ export * from './copyDoc';
@@ -0,0 +1,7 @@
1
+ import { ConfigService } from '../../config';
2
+ type Params = {
3
+ filter: string[];
4
+ ignoreSrc?: boolean;
5
+ };
6
+ export declare const copyStatic: ({ filter, ignoreSrc }: Params, configService: ConfigService) => Promise<void>;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import recursiveCopy from 'recursive-copy';
2
+ import { logger } from '../../services';
3
+ export const copyStatic = ({ filter, ignoreSrc }, configService) => {
4
+ const { projectPath, distPath } = configService;
5
+ logger.progress('Копирование статических файлов');
6
+ return recursiveCopy(projectPath, distPath, {
7
+ filter,
8
+ rename: (filePath) => (ignoreSrc ? filePath.replace('src/', '') : filePath),
9
+ })
10
+ .then((results) => {
11
+ logger.success('Статичные файлы скопированы:', results.map(({ src, dest }) => `${src} -> ${dest}`));
12
+ })
13
+ .catch((err) => {
14
+ logger.error('Ошибка копирования статических файлов');
15
+ throw err;
16
+ });
17
+ };
@@ -0,0 +1 @@
1
+ export * from './copyStatic';
@@ -0,0 +1 @@
1
+ export * from './copyStatic';
@@ -0,0 +1,8 @@
1
+ import { ConfigService } from '../../config';
2
+ type PackageJson = Record<string, unknown>;
3
+ type Params = {
4
+ packageVersion: string;
5
+ originPackageJson: PackageJson;
6
+ };
7
+ export declare const generatePackageJson: ({ packageVersion, originPackageJson }: Params, config: ConfigService) => Promise<void>;
8
+ export {};
@@ -0,0 +1,70 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { logger } from '../../services';
4
+ const omitDevProps = (originPackageJson) => {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ const { scripts, devDependencies, typesVersions, ...packageJson } = originPackageJson;
7
+ return packageJson;
8
+ };
9
+ /**
10
+ * Устанавливает пакетам из releaseGroup одну версию в зависимостях
11
+ */
12
+ const initUpdatingReleaseGroup = (config, packageVersion) => (originPackageJson) => {
13
+ const { semanticRelease } = config;
14
+ const { releaseGroup } = semanticRelease;
15
+ if (!releaseGroup) {
16
+ return originPackageJson;
17
+ }
18
+ const { dependencies } = originPackageJson;
19
+ return {
20
+ ...originPackageJson,
21
+ dependencies: releaseGroup.reduce((deps, packageName) => {
22
+ deps[packageName] = packageVersion;
23
+ return deps;
24
+ }, dependencies),
25
+ };
26
+ };
27
+ const initExportsGenerator = ({ packageExports, format, lang }) => (originPackageJson) => {
28
+ const rootExports = {};
29
+ if (format.includes('esm')) {
30
+ rootExports.module = './index.js';
31
+ }
32
+ if (format.includes('cjs')) {
33
+ rootExports.require = './node/index.js';
34
+ }
35
+ if (lang === 'ts') {
36
+ rootExports.types = './index.d.ts';
37
+ }
38
+ return {
39
+ ...originPackageJson,
40
+ exports: {
41
+ '.': rootExports,
42
+ ...packageExports,
43
+ },
44
+ };
45
+ };
46
+ const initAdditionalCommonProps = (packageVersion, config) => (originPackageJson) => ({
47
+ ...originPackageJson,
48
+ version: packageVersion,
49
+ sideEffects: false,
50
+ types: './index.d.ts',
51
+ main: './node/index.js',
52
+ module: './index.js',
53
+ browser: './index.js',
54
+ author: 'Astral.Soft',
55
+ license: 'MIT',
56
+ repository: {
57
+ type: 'git',
58
+ url: config.semanticRelease.repositoryUrl,
59
+ },
60
+ });
61
+ export const generatePackageJson = async ({ packageVersion, originPackageJson }, config) => {
62
+ logger.progress('Генерация package.json');
63
+ const updateReleaseGroup = initUpdatingReleaseGroup(config, packageVersion);
64
+ const updateAdditionalCommonProps = initAdditionalCommonProps(packageVersion, config);
65
+ const generateExports = initExportsGenerator(config);
66
+ const packageJson = generateExports(omitDevProps(updateAdditionalCommonProps(updateReleaseGroup(originPackageJson))));
67
+ const { distPath } = config;
68
+ fs.writeFileSync(path.join(distPath, 'package.json'), JSON.stringify(packageJson, null, 2));
69
+ logger.success('package.json успешно сформирован в ', distPath);
70
+ };
@@ -0,0 +1 @@
1
+ export * from './generatePackageJson';
@@ -0,0 +1 @@
1
+ export * from './generatePackageJson';
@@ -0,0 +1,7 @@
1
+ export * from './rmDist';
2
+ export * from './copyStatic';
3
+ export * from './compileTs';
4
+ export * from './compileJs';
5
+ export * from './build';
6
+ export * from './semanticRelease';
7
+ export * from './copyDoc';
@@ -0,0 +1,7 @@
1
+ export * from './rmDist';
2
+ export * from './copyStatic';
3
+ export * from './compileTs';
4
+ export * from './compileJs';
5
+ export * from './build';
6
+ export * from './semanticRelease';
7
+ export * from './copyDoc';
@@ -0,0 +1 @@
1
+ export * from './rmDist';
@@ -0,0 +1 @@
1
+ export * from './rmDist';
@@ -0,0 +1,2 @@
1
+ import type { ConfigService } from '../../config';
2
+ export declare const rmDist: (configService: ConfigService) => void;
@@ -0,0 +1,17 @@
1
+ import fs from 'fs';
2
+ import { logger } from '../../services';
3
+ export const rmDist = (configService) => {
4
+ const { distPath, distDirName } = configService;
5
+ if (!fs.existsSync(distPath)) {
6
+ return;
7
+ }
8
+ logger.progress(`Удаление ${distDirName} директории`);
9
+ try {
10
+ fs.rmSync(distPath, { recursive: true, force: true });
11
+ logger.success(`${distDirName} директория удалена`);
12
+ }
13
+ catch (err) {
14
+ logger.error(`Ошибка удаления ${distDirName} директории`, err);
15
+ throw err;
16
+ }
17
+ };
@@ -0,0 +1,2 @@
1
+ import { ConfigService } from '../../../config';
2
+ export declare const checkPackageVersion: (config: ConfigService) => Promise<void>;
@@ -0,0 +1,50 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import semanticRelease from 'semantic-release';
4
+ import { logger } from '../../../services';
5
+ import { commitAnalyzerPlugin, defaultBranches } from '../defaultConfig';
6
+ export const checkPackageVersion = async (config) => {
7
+ logger.progress('Анализ коммитов');
8
+ let versions;
9
+ try {
10
+ const result = await semanticRelease({
11
+ branches: defaultBranches,
12
+ plugins: [commitAnalyzerPlugin],
13
+ dryRun: true,
14
+ ci: true,
15
+ });
16
+ if (result) {
17
+ logger.success('Коммиты успешно проанализированы');
18
+ const { lastRelease, nextRelease } = result;
19
+ versions = {
20
+ currentVersion: lastRelease.version ?? null,
21
+ nextVersion: nextRelease.version ?? null,
22
+ };
23
+ logger.info('Версии пакета:', versions);
24
+ }
25
+ else {
26
+ throw new Error('Не удалось провести анализ коммитов');
27
+ }
28
+ }
29
+ catch (err) {
30
+ logger.error('Ошибка анализа коммитов', err);
31
+ throw err;
32
+ }
33
+ if (versions.currentVersion === versions.nextVersion) {
34
+ throw Error('Версии пакетов совпадают');
35
+ }
36
+ const { packPrivateDirPath, semanticRelease: semanticReleaseConfig } = config;
37
+ const versionFilePath = path.join(packPrivateDirPath, semanticReleaseConfig.versionsFileName);
38
+ logger.progress('Запись данных о версиях в файл', versionFilePath);
39
+ try {
40
+ if (!fs.existsSync(packPrivateDirPath)) {
41
+ fs.mkdirSync('.pack');
42
+ }
43
+ fs.writeFileSync(versionFilePath, JSON.stringify(versions));
44
+ logger.success('Данные о версиях в файл успешно записаны');
45
+ }
46
+ catch (err) {
47
+ logger.error('Ошибка записи данных о версиях в файл', err);
48
+ throw err;
49
+ }
50
+ };
@@ -0,0 +1 @@
1
+ export * from './checkPackageVersion';
@@ -0,0 +1 @@
1
+ export * from './checkPackageVersion';
@@ -0,0 +1,2 @@
1
+ import { ConfigService } from '../../../config';
2
+ export declare const createRelease: (config: ConfigService) => Promise<void>;