create-mirta 0.3.4 → 0.4.3
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/classic.mjs +120 -0
- package/dist/index.mjs +800 -690
- package/dist/mono.mjs +208 -0
- package/dist/resolver.mjs +843 -0
- package/locales/en-US.json +109 -0
- package/locales/ru-RU.json +109 -0
- package/package.json +25 -22
- package/templates/classic/starter/content/package.json +11 -0
- package/{dist/templates/config/typescript → templates/classic/starter/content}/tsconfig.json +0 -5
- package/{dist/templates/eslint/eslint.config.mjs.ejs → templates/classic/starter/features/eslint/eslint.config.mjs.tt} +11 -6
- package/{dist/templates/base/_env → templates/classic/starter/features/examples/_.env} +1 -1
- package/templates/classic/starter/features/examples/src/wb-rules/01-counter.ts +12 -0
- package/templates/classic/starter/features/examples/src/wb-rules-modules/counter.ts +42 -0
- package/templates/classic/starter/features/examples-vitest/tests/wb-rules-modules/counter.test.ts +56 -0
- package/templates/classic/starter/features/vitest/package.json +10 -0
- package/templates/classic/starter/features/vitest-eslint/package.json +5 -0
- package/templates/classic/starter/template.json +10 -0
- package/{dist/templates/config/store → templates/classic/store/content}/package.json +1 -1
- package/templates/classic/store/features/examples/src/wb-rules/01-counter.ts +13 -0
- package/templates/classic/store/features/examples/src/wb-rules/02-counter.ts +19 -0
- package/templates/classic/store/features/examples/src/wb-rules-modules/counter-store.ts +33 -0
- package/templates/classic/store/features/examples/src/wb-rules-modules/counter.ts +44 -0
- package/templates/classic/store/features/examples-vitest/tests/wb-rules-modules/counter.test.ts +49 -0
- package/templates/classic/store/template.json +14 -0
- package/templates/mono/core/content/package.json +6 -0
- package/templates/mono/core/content/pnpm-workspace.yaml +3 -0
- package/templates/mono/core/content/sites/.gitkeep +0 -0
- package/templates/mono/core/content/tsconfig.json +31 -0
- package/templates/mono/core/features/eslint/eslint.config.mjs.tt +126 -0
- package/templates/mono/core/features/vitest/package.json +10 -0
- package/templates/mono/core/template.json +5 -0
- package/templates/mono/package/features/package/packages/{{package}}/package.json.tt +25 -0
- package/templates/mono/package/features/package/packages/{{package}}/src/.gitkeep +0 -0
- package/templates/mono/package/features/package/packages/{{package}}/tsconfig.build.json +10 -0
- package/templates/mono/package/features/package/sites/{{package}}-demo/package.json.tt +19 -0
- package/templates/mono/package/features/package/sites/{{package}}-demo/src/wb-rules/.gitkeep +0 -0
- package/templates/mono/package/features/package/sites/{{package}}-demo/src/wb-rules-modules/.gitkeep +0 -0
- package/templates/mono/package/features/package/sites/{{package}}-demo/tsconfig.build.json +10 -0
- package/templates/mono/package/features/package-examples/packages/{{package}}/src/index.ts +2 -0
- package/templates/mono/package/features/package-examples/packages/{{package}}/src/thermostat.ts +99 -0
- package/templates/mono/package/features/package-examples/packages/{{package}}/src/types.ts +25 -0
- package/templates/mono/package/features/package-examples/sites/{{package}}-demo/src/wb-rules/01-thermo.ts.tt +11 -0
- package/templates/mono/package/features/package-examples-vitest/packages/{{package}}/tests/mirta-thermostat.test.ts +72 -0
- package/templates/mono/package/features/package-github/packages/{{package}}/package.json.tt +11 -0
- package/templates/mono/package/template.json +16 -0
- package/templates/mono/sites/content/mirta.config.json +37 -0
- package/templates/mono/sites/content/sites/home/package.json +17 -0
- package/templates/mono/sites/content/sites/home/src/wb-rules/.gitkeep +0 -0
- package/templates/mono/sites/content/sites/home/src/wb-rules-modules/.gitkeep +0 -0
- package/templates/mono/sites/content/sites/home-staging/package.json +17 -0
- package/templates/mono/sites/content/sites/home-staging/src/wb-rules/.gitkeep +0 -0
- package/templates/mono/sites/content/sites/home-staging/src/wb-rules-modules/.gitkeep +0 -0
- package/templates/mono/sites/template.json +9 -0
- package/{dist/templates/base/_editorconfig → templates/shared/base/content/_.editorconfig} +1 -1
- package/{dist/templates/base/_gitignore → templates/shared/base/content/_.gitignore} +1 -3
- package/templates/shared/base/content/_.node-version +1 -0
- package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/settings.json +12 -1
- package/templates/shared/base/content/package.json +22 -0
- package/templates/shared/base/features/connection/_.env.local.tt +1 -0
- package/templates/shared/base/features/connection/mirta.config.json +6 -0
- package/templates/shared/base/features/eslint/package.json +9 -0
- package/templates/shared/base/features/examples/mirta.config.json.tt +51 -0
- package/templates/shared/base/features/github/_.github/workflows/build.yml.tt +56 -0
- package/templates/shared/base/features/github-vitest/_.github/workflows/test.yml +30 -0
- package/templates/shared/base/template.json +16 -0
- package/dist/locales/en-US.json +0 -85
- package/dist/locales/ru-RU.json +0 -86
- package/dist/templates/base/package.json +0 -27
- package/dist/templates/base/rollup.config.mjs +0 -15
- package/dist/templates/config/typescript/package.json +0 -8
- package/dist/templates/config/vitest/package.json +0 -10
- package/dist/templates/config/vitest/tests/setup/dotenv.ts +0 -5
- package/dist/templates/config/vitest/tests/setup/mirta.ts +0 -41
- package/dist/templates/config/vitest/tests/tsconfig.json +0 -9
- package/dist/templates/config/vitest/vitest.config.ts +0 -37
- package/dist/templates/example/base/src/wb-rules/00-dotenv.ts +0 -52
- package/dist/templates/example/base/src/wb-rules/01-count.ts +0 -6
- package/dist/templates/example/base/src/wb-rules-modules/counter.ts +0 -14
- package/dist/templates/example/store/src/wb-rules/01-count.ts +0 -10
- package/dist/templates/example/store/src/wb-rules-modules/counter-store.ts +0 -7
- package/dist/templates/example/store/src/wb-rules-modules/counter.ts +0 -20
- package/dist/templates/example/vitest/base/tests/wb-rules-modules/counter.test.ts +0 -10
- package/dist/templates/example/vitest/store/tests/wb-rules-modules/counter-store.test.ts +0 -13
- /package/{dist/assets → assets}/logo.art +0 -0
- /package/{dist/templates/base → templates/classic/starter/content}/src/wb-rules/.gitkeep +0 -0
- /package/{dist/templates/base → templates/classic/starter/content}/src/wb-rules-modules/.gitkeep +0 -0
- /package/{dist/templates/base → templates/classic/starter/content}/types/env.d.ts +0 -0
- /package/{dist/templates/config → templates/classic/starter/features}/vitest/tests/wb-rules-modules/.gitkeep +0 -0
- /package/{dist/templates/config → templates/classic/starter/features}/vitest/tsconfig.json +0 -0
- /package/{dist/templates/base/_gitattributes → templates/shared/base/content/_.gitattributes} +0 -0
- /package/{dist/templates/base/_npmrc → templates/shared/base/content/_.npmrc} +0 -0
- /package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/extensions.json +0 -0
- /package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/tasks.json +0 -0
- /package/{dist/templates/config/eslint/.vscode → templates/shared/base/features/eslint/_.vscode}/extensions.json +0 -0
- /package/{dist/templates/config/eslint/.vscode → templates/shared/base/features/eslint/_.vscode}/settings.json +0 -0
- /package/{dist/templates/config/vitest/.vscode → templates/shared/base/features/vitest/_.vscode}/extensions.json +0 -0
package/dist/mono.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { a as assertNoParseErrors, l as logger, t, p as prompts, c as clearDirAsync, i as isExistsAsync } from './index.mjs';
|
|
2
|
+
import { r as resolveFeaturesAsync, t as toTemplateData, a as resolveGithubInfoAsync, b as resolveConnectionStringAsync, c as renderDirectoryAsync, p as promptInstallDependenciesAsync, D as DEFAULT_SSH_USERNAME, d as DEFAULT_SSH_HOSTNAME } from './resolver.mjs';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import '../package.json' with { type: 'json' };
|
|
6
|
+
import '@mirta/staged-args';
|
|
7
|
+
import '@mirta/i18n';
|
|
8
|
+
import 'node:path';
|
|
9
|
+
import 'node:fs';
|
|
10
|
+
import 'gradient-string';
|
|
11
|
+
import 'prompts';
|
|
12
|
+
import '@mirta/basics';
|
|
13
|
+
import 'jsonc-parser';
|
|
14
|
+
import 'node:child_process';
|
|
15
|
+
|
|
16
|
+
// Опции режима сборки mono
|
|
17
|
+
const options = {
|
|
18
|
+
eslint: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
},
|
|
21
|
+
vitest: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
},
|
|
24
|
+
ssh: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
},
|
|
27
|
+
rutoken: {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Парсит аргументы командной строки для сборки в режиме `mono`.
|
|
33
|
+
*
|
|
34
|
+
* @param args - Объект с аргументами, управляемый `StagedArgs`.
|
|
35
|
+
* @returns Объект с распарсенными значениями и позиционными аргументами.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.4.0
|
|
38
|
+
*
|
|
39
|
+
**/
|
|
40
|
+
function parseArgs(args) {
|
|
41
|
+
const parseResult = args.parseFinal(options);
|
|
42
|
+
assertNoParseErrors(parseResult);
|
|
43
|
+
const { values, positionals } = parseResult.data;
|
|
44
|
+
return {
|
|
45
|
+
values,
|
|
46
|
+
positionals,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const SCOPED_PACKAGE_REGEX = /^(@[^/]+)\/(.+)$/;
|
|
51
|
+
const MAX_LENGTH = 214;
|
|
52
|
+
/**
|
|
53
|
+
* Проверяет, что длина имени пакета не превышает разрешённую величину.
|
|
54
|
+
*
|
|
55
|
+
* @since 0.4.0
|
|
56
|
+
*
|
|
57
|
+
**/
|
|
58
|
+
function hasValidLength(packageName) {
|
|
59
|
+
return packageName.length <= MAX_LENGTH;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Проверяет, является ли строка валидным именем NPM-пакета.
|
|
63
|
+
*
|
|
64
|
+
* Поддерживает как обычные, так и scoped-имена.
|
|
65
|
+
* Основывается на официальных правилах именования пакетов в npm.
|
|
66
|
+
*
|
|
67
|
+
* @param packageName - Проверяемая строка
|
|
68
|
+
* @returns `true`, если имя валидно, иначе `false`
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* hasValidFormat('my-package') // → true
|
|
73
|
+
* hasValidFormat('@org/module') // → true
|
|
74
|
+
* hasValidFormat('invalid/name') // → false
|
|
75
|
+
* ```
|
|
76
|
+
* @since 0.4.0
|
|
77
|
+
*
|
|
78
|
+
**/
|
|
79
|
+
function hasValidFormat(packageName) {
|
|
80
|
+
return /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/
|
|
81
|
+
.test(packageName);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Асинхронно запрашивает у пользователя информацию о пакете.
|
|
85
|
+
*
|
|
86
|
+
* Если передано валидное имя — используется оно.
|
|
87
|
+
* Иначе — показывается интерактивный ввод с валидацией.
|
|
88
|
+
* Автоматически нормализует ввод через `toValidPackageName`.
|
|
89
|
+
*
|
|
90
|
+
* @param input - Опциональное имя пакета (например, из аргументов команды)
|
|
91
|
+
* @returns Объект с полями `name` и `fullName`.
|
|
92
|
+
*
|
|
93
|
+
* @throws Может выбросить ошибку, если прерван ввод (редкий случай)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const info = await resolvePackageInfoAsync('my-module')
|
|
98
|
+
* console.log(info.fullName) // → 'my-module'
|
|
99
|
+
* ```
|
|
100
|
+
* @since 0.4.0
|
|
101
|
+
*
|
|
102
|
+
**/
|
|
103
|
+
async function resolvePackageInfoAsync(input) {
|
|
104
|
+
let packageName;
|
|
105
|
+
{
|
|
106
|
+
logger.step(t('package.caption'));
|
|
107
|
+
const answer = await prompts({
|
|
108
|
+
type: 'text',
|
|
109
|
+
name: 'packageName',
|
|
110
|
+
message: t('packageName.prompt'),
|
|
111
|
+
initial: undefined,
|
|
112
|
+
validate: (value) => {
|
|
113
|
+
if (!hasValidLength(value))
|
|
114
|
+
return t('packageName.tooLong', { maxLength: MAX_LENGTH });
|
|
115
|
+
if (!hasValidFormat(value))
|
|
116
|
+
return t(`packageName.invalidFormat`);
|
|
117
|
+
return true;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
packageName = answer.packageName;
|
|
121
|
+
}
|
|
122
|
+
const scopeMatch = SCOPED_PACKAGE_REGEX.exec(packageName);
|
|
123
|
+
return {
|
|
124
|
+
// Короткое название пакета
|
|
125
|
+
name: scopeMatch ? scopeMatch[2] : packageName,
|
|
126
|
+
// Полное название пакета
|
|
127
|
+
fullName: packageName,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function runAsync(args, context) {
|
|
132
|
+
const { values: argv } = parseArgs(args);
|
|
133
|
+
const { rootDir } = context;
|
|
134
|
+
// Дополнительный функционал, который будет задействован.
|
|
135
|
+
const features = await resolveFeaturesAsync(context, {
|
|
136
|
+
eslint: argv.eslint,
|
|
137
|
+
vitest: argv.vitest,
|
|
138
|
+
connection: argv.ssh,
|
|
139
|
+
});
|
|
140
|
+
const data = toTemplateData({
|
|
141
|
+
name: context.name,
|
|
142
|
+
templates: context.templates.map(x => x.name),
|
|
143
|
+
features: features,
|
|
144
|
+
barebone: context.barebone,
|
|
145
|
+
defaultConnectionString: `ssh://${DEFAULT_SSH_USERNAME}@${DEFAULT_SSH_HOSTNAME}`,
|
|
146
|
+
});
|
|
147
|
+
// Если задействована опция настройки GitHub-репозитория.
|
|
148
|
+
if (features.includes('github')) {
|
|
149
|
+
const githubInfo = await resolveGithubInfoAsync();
|
|
150
|
+
data.githubOwner = githubInfo.owner;
|
|
151
|
+
data.githubRepository = githubInfo.repository;
|
|
152
|
+
data.githubBranch = githubInfo.branch;
|
|
153
|
+
}
|
|
154
|
+
// Если задействована опция создания NPM-пакета.
|
|
155
|
+
if (features.includes('package')) {
|
|
156
|
+
const packageInfo = await resolvePackageInfoAsync();
|
|
157
|
+
data.package = packageInfo.name;
|
|
158
|
+
data.packageFull = packageInfo.fullName;
|
|
159
|
+
}
|
|
160
|
+
// Если добавлено подключение к контроллеру.
|
|
161
|
+
if (features.includes('connection')) {
|
|
162
|
+
data.connectionString
|
|
163
|
+
= await resolveConnectionStringAsync(argv.ssh, argv.rutoken);
|
|
164
|
+
}
|
|
165
|
+
// Удаляем содержимое, если директория существует и получено подтверждение.
|
|
166
|
+
if (context.shouldOverwrite) {
|
|
167
|
+
logger.step(chalk.red(t('step.removingFiles')));
|
|
168
|
+
await clearDirAsync(rootDir);
|
|
169
|
+
}
|
|
170
|
+
// Создаём директорию при её отсутствии.
|
|
171
|
+
else if (context.shouldCreate) {
|
|
172
|
+
await fs.mkdir(rootDir, { recursive: true });
|
|
173
|
+
}
|
|
174
|
+
logger.step(t('step.scaffolding', {
|
|
175
|
+
folder: chalk.yellow(rootDir),
|
|
176
|
+
}));
|
|
177
|
+
const seenCompounds = new Map();
|
|
178
|
+
for (const template of context.templates) {
|
|
179
|
+
await renderDirectoryAsync(`${template.rootDir}/content`, rootDir, data);
|
|
180
|
+
for (const feature of features) {
|
|
181
|
+
const featurePath = `${template.rootDir}/features/${feature}`;
|
|
182
|
+
if (!await isExistsAsync(featurePath))
|
|
183
|
+
continue;
|
|
184
|
+
await renderDirectoryAsync(featurePath, rootDir, data);
|
|
185
|
+
}
|
|
186
|
+
const compoundFeatures = template.features?.compound;
|
|
187
|
+
if (!compoundFeatures)
|
|
188
|
+
continue;
|
|
189
|
+
for (const feature of compoundFeatures) {
|
|
190
|
+
let isApplicable = seenCompounds.get(feature);
|
|
191
|
+
if (isApplicable === undefined) {
|
|
192
|
+
isApplicable = feature
|
|
193
|
+
.split('-')
|
|
194
|
+
.every(x => features.includes(x));
|
|
195
|
+
seenCompounds.set(feature, isApplicable);
|
|
196
|
+
}
|
|
197
|
+
if (!isApplicable)
|
|
198
|
+
continue;
|
|
199
|
+
const featurePath = `${template.rootDir}/features/${feature}`;
|
|
200
|
+
if (!await isExistsAsync(featurePath))
|
|
201
|
+
continue;
|
|
202
|
+
await renderDirectoryAsync(featurePath, rootDir, data);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
await promptInstallDependenciesAsync(rootDir);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { runAsync };
|