-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent-version-update.ts
More file actions
137 lines (115 loc) · 5.18 KB
/
component-version-update.ts
File metadata and controls
137 lines (115 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env node
import chalk from 'chalk';
import path from 'path';
import * as figlet from 'figlet';
import program from 'commander';
import * as pj from './package.json';
import fs from 'fs';
import QuestionModule from './core/QuestionModule.js';
import { Settings } from './core/types.js';
import { Answers } from 'inquirer';
import shelljs from 'shelljs';
import ChangelogModule from './core/ChangelogModule.js';
import Logger from './core/Logger.js';
const version: string = (<any>pj).version;
const description: string = (<any>pj).description;
const logger: Logger = new Logger();
program
.version(version)
.usage('[options] <componentName>')
.option('-u, --onlyUnrealised', 'Брать компонеты только при наличии в unrealised из changelog записей', false)
.option('--verbose', 'Вывод подробной информации', false)
.description(description)
.action(async () => {
if (!fs.existsSync('./package.json')) {
return logger.error('Missing package.json');
}
init();
// Получение конфигурации
const userPackageJson = require(path.resolve('./package.json'));
if (!userPackageJson.cvu) {
return logger.error('Missing cvu key in package.json');
}
const settings: Settings = userPackageJson.cvu;
settings.verbose = program.verbose || settings.verbose || false;
settings.onlyUnrealised = program.onlyUnrealised || settings.onlyUnrealised || false;
logger.verbose = settings.verbose || false;
const changelogFileName: string = settings.changelogFileName || 'CHANGELOG.md';
if (!settings.pathsToComponents || !settings.pathsToComponents.length) {
return logger.error("pathsToComponents c'not empty");
}
logMods(settings, logger);
const paths: string[] = settings.pathsToComponents;
// Создание вопросника
const questionModule: QuestionModule = new QuestionModule(paths, logger);
const changelogModule: ChangelogModule = new ChangelogModule(
{
changelogFileName,
pathToGlobalChangelog: settings.pathToGlobalChangelog,
globalChangelogFormat: settings.globalChangelogFormat,
},
logger
);
for (const component of questionModule.components) {
if (changelogModule.isset(component.path)) {
changelogModule.read(component.path);
} else {
logger.warn(
`Not found ${path.resolve(component.path + '/' + changelogFileName)} by ${component.data.name}`
);
}
}
if (settings.onlyUnrealised) {
questionModule.components = questionModule.components.filter(component =>
changelogModule.isUnrealized(component.path)
);
}
if (!questionModule.components.length) {
return logger.error('No components by publish');
}
// Опрос пользователя
const answer: Answers = await questionModule.ask();
const pathComponent: string = answer.component.path;
if (!changelogModule.isUnrealized(pathComponent)) {
return logger.error(`Nothing unrealized changes in ${pathComponent}/${changelogModule.changelogFileName}`);
}
// Обновление версии в package.json
shelljs.exec(`npm version ${answer.version} --prefix ${pathComponent}`);
// Обновление версии в component/Changelog.md
if (changelogModule.upVersion(pathComponent, answer.version)) {
answer.component.data.version = answer.version;
changelogModule.writeGlobalChangelog(pathComponent, answer.component);
if (settings.commitMessage) {
const message: string = settings.commitMessage
.replace(/%name%/g, answer.component.data.name)
.replace(/%version%/g, answer.component.data.version);
shelljs.exec(
`git add ${pathComponent} ${settings.pathToGlobalChangelog} && git commit -m "${message}"`
);
logger.info(`Commited "${message}"`);
}
}
// Обновление Общего changelog.md
logger.log(changelogModule.get(pathComponent).unrealised.join(', '));
})
.parse(process.argv);
function logMods(settings: Settings, logger: Logger): void {
logger.info(chalk.bold.yellow('Run with mode verbose'));
if (settings.onlyUnrealised) {
logger.info(chalk.bold.yellow('Run with mode onlyUnrealised'));
}
console.log();
}
function init(): void {
console.log(chalk.bold.blue('component-version-updater', '- v' + version));
console.log(
chalk.cyan(
figlet.textSync('Updater', {
font: 'Stop',
horizontalLayout: 'fitted',
verticalLayout: 'default',
})
)
);
console.log();
}