t1kit 0.1.0 → 0.1.1
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/bin/t1kit.mjs +9 -9
- package/migrate-semantic-theme-ts/README.md +15 -15
- package/migrate-semantic-theme-ts/index.mjs +15 -15
- package/package.json +31 -31
- package/src/cli.mjs +35 -35
- package/src/commands/index.mjs +6 -6
- package/src/commands/semantic-migrate/command.mjs +214 -216
- package/src/commands/semantic-migrate/files.mjs +21 -21
- package/src/commands/semantic-migrate/host-tests.mjs +118 -118
- package/src/commands/semantic-migrate/submodule.mjs +208 -181
- package/src/commands/semantic-migrate/transforms.mjs +374 -29
|
@@ -1,216 +1,214 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join, resolve } from 'node:path';
|
|
3
|
-
import { createInterface } from 'node:readline/promises';
|
|
4
|
-
import { stdin, stdout } from 'node:process';
|
|
5
|
-
import { readIfExists, writeIfChanged } from './files.mjs';
|
|
6
|
-
import { patchHostTests } from './host-tests.mjs';
|
|
7
|
-
import { assertSemanticReplaceSafe, replaceSemanticSubmodule } from './submodule.mjs';
|
|
8
|
-
import {
|
|
9
|
-
SEMANTIC_SUBMODULE_PATH,
|
|
10
|
-
SEMANTIC_THEME_TS,
|
|
11
|
-
SEMANTIC_THEME_BRANCH,
|
|
12
|
-
patchEslintConfig,
|
|
13
|
-
patchGitmodules,
|
|
14
|
-
patchPackageJson,
|
|
15
|
-
patchTsconfig,
|
|
16
|
-
patchViteConfig,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (token === '--
|
|
29
|
-
else if (token === '--
|
|
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
|
-
const
|
|
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
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (skipSubmodule) {
|
|
141
|
-
writeIfChanged({
|
|
142
|
-
dryRun,
|
|
143
|
-
path: join(root, '.gitmodules'),
|
|
144
|
-
previous: readIfExists(join(root, '.gitmodules')),
|
|
145
|
-
next: patchGitmodules(readIfExists(join(root, '.gitmodules')) || ''),
|
|
146
|
-
changed,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const readmePath = join(root, 'README.md');
|
|
151
|
-
const readme = readIfExists(readmePath);
|
|
152
|
-
|
|
153
|
-
if (readme) {
|
|
154
|
-
writeIfChanged({
|
|
155
|
-
dryRun,
|
|
156
|
-
path: readmePath,
|
|
157
|
-
previous: readme,
|
|
158
|
-
next: patchGitmodules(readme),
|
|
159
|
-
changed,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
writeIfChanged({
|
|
164
|
-
dryRun,
|
|
165
|
-
path: join(root, 'tsconfig.json'),
|
|
166
|
-
previous: readIfExists(join(root, 'tsconfig.json')),
|
|
167
|
-
next: patchTsconfig(readIfExists(join(root, 'tsconfig.json')) || ''),
|
|
168
|
-
changed,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const vitePath = existsSync(join(root, 'vite.config.js')) ? join(root, 'vite.config.js') : join(root, 'vite.config.ts');
|
|
172
|
-
const hasJsxTransformer = existsSync(join(root, 'src/modules/plugins/jsxTransformer.js'));
|
|
173
|
-
|
|
174
|
-
writeIfChanged({
|
|
175
|
-
dryRun,
|
|
176
|
-
path: vitePath,
|
|
177
|
-
previous: readIfExists(vitePath),
|
|
178
|
-
next: patchViteConfig(readIfExists(vitePath) || '', { hasJsxTransformer }),
|
|
179
|
-
changed,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
writeIfChanged({
|
|
183
|
-
dryRun,
|
|
184
|
-
path: join(root, 'eslint.config.js'),
|
|
185
|
-
previous: readIfExists(join(root, 'eslint.config.js')),
|
|
186
|
-
next: patchEslintConfig(readIfExists(join(root, 'eslint.config.js')) || ''),
|
|
187
|
-
changed,
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
writeIfChanged({
|
|
191
|
-
dryRun,
|
|
192
|
-
path: join(root, 'package.json'),
|
|
193
|
-
previous: readIfExists(join(root, 'package.json')),
|
|
194
|
-
next: patchPackageJson(readIfExists(join(root, 'package.json')) || '{}'),
|
|
195
|
-
changed,
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
const testNotes = patchHostTests({ root, dryRun, changed });
|
|
199
|
-
|
|
200
|
-
log('\nfiles:');
|
|
201
|
-
for (const item of changed) log(` ${item}`);
|
|
202
|
-
|
|
203
|
-
if (replaceSubmodule) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
git submodule
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
printNextSteps({ snapshots: testNotes.includes('snapshots') });
|
|
216
|
-
};
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { createInterface } from 'node:readline/promises';
|
|
4
|
+
import { stdin, stdout } from 'node:process';
|
|
5
|
+
import { readIfExists, writeIfChanged } from './files.mjs';
|
|
6
|
+
import { patchHostTests } from './host-tests.mjs';
|
|
7
|
+
import { assertSemanticReplaceSafe, previewSemanticAddUrl, replaceSemanticSubmodule } from './submodule.mjs';
|
|
8
|
+
import {
|
|
9
|
+
SEMANTIC_SUBMODULE_PATH,
|
|
10
|
+
SEMANTIC_THEME_TS,
|
|
11
|
+
SEMANTIC_THEME_BRANCH,
|
|
12
|
+
patchEslintConfig,
|
|
13
|
+
patchGitmodules,
|
|
14
|
+
patchPackageJson,
|
|
15
|
+
patchTsconfig,
|
|
16
|
+
patchViteConfig,
|
|
17
|
+
} from './transforms.mjs';
|
|
18
|
+
|
|
19
|
+
const log = message => process.stdout.write(`${message}\n`);
|
|
20
|
+
|
|
21
|
+
export const parseArgs = argv => {
|
|
22
|
+
const args = { root: process.cwd(), dryRun: false, skipSubmodule: false, yes: false };
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
25
|
+
const token = argv[i];
|
|
26
|
+
|
|
27
|
+
if (token === '--dry-run') args.dryRun = true;
|
|
28
|
+
else if (token === '--skip-submodule') args.skipSubmodule = true;
|
|
29
|
+
else if (token === '--install') {
|
|
30
|
+
throw new Error('Флаг --install не поддерживается. После миграции выполните yarn в проекте.');
|
|
31
|
+
} else if (token === '--yes' || token === '-y') args.yes = true;
|
|
32
|
+
else if (token === '--root') {
|
|
33
|
+
if (!argv[i + 1] || argv[i + 1].startsWith('-')) {
|
|
34
|
+
throw new Error('После --root укажите путь к микрофронту.');
|
|
35
|
+
}
|
|
36
|
+
args.root = resolve(argv[i + 1]);
|
|
37
|
+
i += 1;
|
|
38
|
+
} else if (token === '--help' || token === '-h') args.help = true;
|
|
39
|
+
else throw new Error(`Неизвестный аргумент: ${token}. Справка: npx t1kit semantic-migrate --help`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return args;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const printSemanticWarning = () => {
|
|
46
|
+
log(`
|
|
47
|
+
Внимание: сейчас будет замена сабмодуля ${SEMANTIC_SUBMODULE_PATH}
|
|
48
|
+
front-semantic-theme → ${SEMANTIC_THEME_TS}
|
|
49
|
+
|
|
50
|
+
Если в semantic есть нужная работа — закоммитьте и push в front-semantic-theme.
|
|
51
|
+
Stash в src/semantic-ui недостаточно: скрипт остановится, пока в теме есть
|
|
52
|
+
stash, грязное дерево или локальные коммиты без remote. Скрипт сам не коммитит хост.
|
|
53
|
+
`);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const printNextSteps = ({ snapshots } = { snapshots: false }) => {
|
|
57
|
+
log(`
|
|
58
|
+
Что сделать после:
|
|
59
|
+
1. yarn
|
|
60
|
+
2. Прогнать тесты: yarn test`);
|
|
61
|
+
|
|
62
|
+
if (snapshots) {
|
|
63
|
+
log(' Снапшоты списков могли измениться (AutoSizer). Если тесты упали на snapshot — yarn test -u и проверьте diff.');
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const confirmSemanticReplace = async ({ yes }) => {
|
|
68
|
+
printSemanticWarning();
|
|
69
|
+
|
|
70
|
+
if (yes) {
|
|
71
|
+
log('Подтверждено флагом --yes.');
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!stdin.isTTY) {
|
|
76
|
+
log('Нет TTY: передайте --yes, чтобы подтвердить замену, или --skip-submodule / --dry-run.');
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
81
|
+
const answer = await rl.question('Продолжить замену semantic? Несохранённые изменения в теме будут потеряны. [y/N] ');
|
|
82
|
+
rl.close();
|
|
83
|
+
|
|
84
|
+
return /^(y|yes|д|да)$/i.test(answer.trim());
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const printHelp = () => {
|
|
88
|
+
log(`t1kit semantic-migrate
|
|
89
|
+
|
|
90
|
+
Usage:
|
|
91
|
+
npx t1kit semantic-migrate [--root <microfront>] [--dry-run] [--skip-submodule] [--yes]
|
|
92
|
+
|
|
93
|
+
The project root defaults to the current working directory.
|
|
94
|
+
|
|
95
|
+
Steps:
|
|
96
|
+
1. Warn and ask before switching src/semantic-ui to front-semantic-theme-ts
|
|
97
|
+
2. git rm the old theme, git submodule add -f the -ts repo, branch = main, init.sh
|
|
98
|
+
3. Patch tsconfig / vite / eslint / package.json for TS theme lint
|
|
99
|
+
4. Rewrite host AutoSizer mocks (package mock, no children destructure)
|
|
100
|
+
5. Mock semantic-ui-react Popup in click tests that do not assert a tooltip
|
|
101
|
+
|
|
102
|
+
Does not edit production host UI. --skip-submodule keeps the current theme checkout.`);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const run = async argv => {
|
|
106
|
+
const args = parseArgs(argv);
|
|
107
|
+
|
|
108
|
+
if (args.help) {
|
|
109
|
+
printHelp();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const { root, dryRun, skipSubmodule, yes } = args;
|
|
114
|
+
|
|
115
|
+
if (!existsSync(join(root, 'package.json'))) {
|
|
116
|
+
throw new Error(`Не найден package.json в ${root}. Запустите команду из корня микрофронта или передайте --root <путь>.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const changed = [];
|
|
120
|
+
const replaceSubmodule = !skipSubmodule && !dryRun;
|
|
121
|
+
|
|
122
|
+
log(`root: ${root}${dryRun ? ' (dry-run)' : ''}`);
|
|
123
|
+
|
|
124
|
+
if (dryRun && !skipSubmodule) {
|
|
125
|
+
printSemanticWarning();
|
|
126
|
+
log('(dry-run: git rm / submodule add / init.sh не выполняются)\n');
|
|
127
|
+
} else if (replaceSubmodule) {
|
|
128
|
+
const confirmed = await confirmSemanticReplace({ yes });
|
|
129
|
+
|
|
130
|
+
if (!confirmed) {
|
|
131
|
+
log('Отменено. Тема не тронута. Сначала сохраните изменения в semantic, затем запустите снова.');
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
assertSemanticReplaceSafe(root);
|
|
137
|
+
replaceSemanticSubmodule(root);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (skipSubmodule) {
|
|
141
|
+
writeIfChanged({
|
|
142
|
+
dryRun,
|
|
143
|
+
path: join(root, '.gitmodules'),
|
|
144
|
+
previous: readIfExists(join(root, '.gitmodules')),
|
|
145
|
+
next: patchGitmodules(readIfExists(join(root, '.gitmodules')) || ''),
|
|
146
|
+
changed,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const readmePath = join(root, 'README.md');
|
|
151
|
+
const readme = readIfExists(readmePath);
|
|
152
|
+
|
|
153
|
+
if (readme) {
|
|
154
|
+
writeIfChanged({
|
|
155
|
+
dryRun,
|
|
156
|
+
path: readmePath,
|
|
157
|
+
previous: readme,
|
|
158
|
+
next: patchGitmodules(readme),
|
|
159
|
+
changed,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
writeIfChanged({
|
|
164
|
+
dryRun,
|
|
165
|
+
path: join(root, 'tsconfig.json'),
|
|
166
|
+
previous: readIfExists(join(root, 'tsconfig.json')),
|
|
167
|
+
next: patchTsconfig(readIfExists(join(root, 'tsconfig.json')) || ''),
|
|
168
|
+
changed,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const vitePath = existsSync(join(root, 'vite.config.js')) ? join(root, 'vite.config.js') : join(root, 'vite.config.ts');
|
|
172
|
+
const hasJsxTransformer = existsSync(join(root, 'src/modules/plugins/jsxTransformer.js'));
|
|
173
|
+
|
|
174
|
+
writeIfChanged({
|
|
175
|
+
dryRun,
|
|
176
|
+
path: vitePath,
|
|
177
|
+
previous: readIfExists(vitePath),
|
|
178
|
+
next: patchViteConfig(readIfExists(vitePath) || '', { hasJsxTransformer }),
|
|
179
|
+
changed,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
writeIfChanged({
|
|
183
|
+
dryRun,
|
|
184
|
+
path: join(root, 'eslint.config.js'),
|
|
185
|
+
previous: readIfExists(join(root, 'eslint.config.js')),
|
|
186
|
+
next: patchEslintConfig(readIfExists(join(root, 'eslint.config.js')) || ''),
|
|
187
|
+
changed,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
writeIfChanged({
|
|
191
|
+
dryRun,
|
|
192
|
+
path: join(root, 'package.json'),
|
|
193
|
+
previous: readIfExists(join(root, 'package.json')),
|
|
194
|
+
next: patchPackageJson(readIfExists(join(root, 'package.json')) || '{}'),
|
|
195
|
+
changed,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const testNotes = patchHostTests({ root, dryRun, changed });
|
|
199
|
+
|
|
200
|
+
log('\nfiles:');
|
|
201
|
+
for (const item of changed) log(` ${item}`);
|
|
202
|
+
|
|
203
|
+
if (!replaceSubmodule && !skipSubmodule) {
|
|
204
|
+
const url = previewSemanticAddUrl(root);
|
|
205
|
+
log(`\nWould:
|
|
206
|
+
git submodule deinit -f -- ${SEMANTIC_SUBMODULE_PATH}
|
|
207
|
+
git rm -rf -- ${SEMANTIC_SUBMODULE_PATH}
|
|
208
|
+
git submodule add -f ${url} ${SEMANTIC_SUBMODULE_PATH}
|
|
209
|
+
# branch = ${SEMANTIC_THEME_BRANCH} in .gitmodules
|
|
210
|
+
sh init.sh`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
printNextSteps({ snapshots: testNotes.includes('snapshots') });
|
|
214
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { relative } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export const readIfExists = path => (existsSync(path) ? readFileSync(path, 'utf8') : null);
|
|
5
|
-
|
|
6
|
-
export const writeIfChanged = ({ dryRun, path, next, previous, changed }) => {
|
|
7
|
-
if (previous === null) {
|
|
8
|
-
changed.push(`${relative(process.cwd(), path)} (missing, skipped)`);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (previous === next) {
|
|
13
|
-
changed.push(`${relative(process.cwd(), path)} (unchanged)`);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
changed.push(relative(process.cwd(), path));
|
|
18
|
-
if (!dryRun) {
|
|
19
|
-
writeFileSync(path, next);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const readIfExists = path => (existsSync(path) ? readFileSync(path, 'utf8') : null);
|
|
5
|
+
|
|
6
|
+
export const writeIfChanged = ({ dryRun, path, next, previous, changed }) => {
|
|
7
|
+
if (previous === null) {
|
|
8
|
+
changed.push(`${relative(process.cwd(), path)} (missing, skipped)`);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (previous === next) {
|
|
13
|
+
changed.push(`${relative(process.cwd(), path)} (unchanged)`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
changed.push(relative(process.cwd(), path));
|
|
18
|
+
if (!dryRun) {
|
|
19
|
+
writeFileSync(path, next);
|
|
20
|
+
}
|
|
21
|
+
};
|