create-mirta 0.0.2 → 0.0.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/index.mjs CHANGED
@@ -140,7 +140,7 @@ function usePrompts(messages) {
140
140
  cancel,
141
141
  prompt,
142
142
  step: p.log.step,
143
- note: p.note,
143
+ message: p.log.message,
144
144
  inlineSub,
145
145
  };
146
146
  }
@@ -174,6 +174,10 @@ ${yellow$1('Feature flags:')}
174
174
  ${dim$1('Add store for state management')}
175
175
 
176
176
  ${yellow$1('Options:')}
177
+ --ssh
178
+ ${dim$1('Set SSH destination of deployment process as [username@][hostname][:port]')}
179
+ --rutoken
180
+ ${dim$1('Use Rutoken ECP as encrypted store of SSH private key')}
177
181
  -v, --version
178
182
  ${dim$1('Display the version number of this CLI')}
179
183
  -f, --force
@@ -203,6 +207,10 @@ ${yellow$1('Флаги функционала:')}
203
207
  ${dim$1('Добавить хранилище состояний')}
204
208
 
205
209
  ${yellow$1('Опции:')}
210
+ --ssh
211
+ ${dim$1('Настроить подключение SSH для деплоя в формате [username@][hostname][:port]')}
212
+ --rutoken
213
+ ${dim$1('Использовать Рутокен ЭЦП в качестве хранилища для закрытого ключа SSH')}
206
214
  -v, --version
207
215
  ${dim$1('Отобразить номер версии данного CLI')}
208
216
  -f, --force
@@ -232,6 +240,12 @@ const featureFlags = ({
232
240
  });
233
241
  const allOptions = ({
234
242
  ...featureFlags,
243
+ ssh: {
244
+ type: 'string',
245
+ },
246
+ rutoken: {
247
+ type: 'boolean',
248
+ },
235
249
  version: {
236
250
  type: 'boolean',
237
251
  short: 'v',
@@ -240,16 +254,23 @@ const allOptions = ({
240
254
  type: 'boolean',
241
255
  short: 'f',
242
256
  },
243
- help: {
244
- type: 'boolean',
245
- short: 'h',
246
- },
247
257
  bare: {
248
258
  type: 'boolean',
249
259
  short: 'b',
250
260
  },
261
+ help: {
262
+ type: 'boolean',
263
+ short: 'h',
264
+ },
251
265
  });
252
266
 
267
+ const urlRegex = /(?:(?<username>.+?)@)?(?:(?<hostname>[^:@\s]+))?(?::(?<port>\d+))?/;
268
+ function parseUrl(value) {
269
+ if (!value)
270
+ return {};
271
+ return (urlRegex.exec(value))?.groups ?? {};
272
+ }
273
+
253
274
  const isObject = (val) => typeof val === 'object';
254
275
 
255
276
  function sortDependencies(packageJson) {
@@ -329,7 +350,7 @@ function renderTemplate(sourcePath, targetPath) {
329
350
  renderJson(sourcePath, targetPath, result => sortDependencies(result));
330
351
  return;
331
352
  }
332
- if (['extensions.json', 'settings.json', 'tasks.json'].includes(filename) && fs.existsSync(targetPath)) {
353
+ if (['extensions.json', 'settings.json', 'tasks.json', 'tsconfig.json'].includes(filename) && fs.existsSync(targetPath)) {
333
354
  renderJson(sourcePath, targetPath);
334
355
  return;
335
356
  }
@@ -500,7 +521,7 @@ const featureOptions = [
500
521
  hint: messages.addVitest.hint,
501
522
  },
502
523
  ];
503
- const { prompt, cancel, step, inlineSub } = usePrompts(messages);
524
+ const { prompt, cancel, step, message, inlineSub } = usePrompts(messages);
504
525
  function isValidPackageName(packageName) {
505
526
  return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/
506
527
  .test(packageName);
@@ -536,17 +557,26 @@ async function run() {
536
557
  const hasPositionalDir = targetDir && targetDir !== '.';
537
558
  const defaultProjectName = hasPositionalDir ? targetDir : 'wb-rules-mirta';
538
559
  const shouldOverwrite = argv.force;
560
+ const sshAddress = parseUrl(argv.ssh);
561
+ const sshDefaultUser = 'root';
562
+ const sshDefaultHost = '10.200.200.1';
563
+ const sshDefaultPort = '22';
564
+ const sshFullyDefined = !!(sshAddress.username && sshAddress.hostname);
539
565
  const scope = {
540
566
  projectName: defaultProjectName,
541
567
  projectRoot: '',
542
568
  packageName: defaultProjectName,
543
569
  shouldOverwrite,
544
570
  features: [],
571
+ sshUsername: sshAddress.username,
572
+ sshHostname: sshAddress.hostname,
573
+ sshPort: sshAddress.port,
574
+ rutoken: argv.rutoken,
545
575
  };
546
576
  console.log(banner);
547
577
  console.log(messages.title);
548
578
  console.log();
549
- intro(chalk.bgYellow.black(` ${messages.intro} `));
579
+ intro(chalk.bgBlackBright.black(` ${messages.captions.intro} `));
550
580
  if (!targetDir) {
551
581
  const answer = await prompt(text({
552
582
  message: messages.projectName.message,
@@ -590,6 +620,58 @@ async function run() {
590
620
  process.exit(0);
591
621
  }
592
622
  }
623
+ message(chalk.bgBlackBright.black(` ${messages.captions.deploy} `));
624
+ if (!scope.sshUsername) {
625
+ scope.sshUsername = await prompt(text({
626
+ message: messages.ssh.username,
627
+ placeholder: sshDefaultUser,
628
+ defaultValue: sshDefaultUser,
629
+ validate: (value) => {
630
+ if (value.length !== 0 && value.trim().length === 0)
631
+ return messages.validation.required;
632
+ },
633
+ }));
634
+ }
635
+ else {
636
+ step(`${messages.ssh.username}\n${dim(scope.sshUsername)}`);
637
+ }
638
+ if (!scope.sshHostname) {
639
+ scope.sshHostname = await prompt(text({
640
+ message: messages.ssh.host,
641
+ placeholder: sshDefaultHost,
642
+ defaultValue: sshDefaultHost,
643
+ validate: (value) => {
644
+ if (value.length !== 0 && value.trim().length === 0)
645
+ return messages.validation.required;
646
+ },
647
+ }));
648
+ }
649
+ else {
650
+ step(`${messages.ssh.host}\n${dim(scope.sshHostname)}`);
651
+ }
652
+ if (!sshFullyDefined && !scope.sshPort) {
653
+ scope.sshPort = await prompt(text({
654
+ message: messages.ssh.port,
655
+ placeholder: sshDefaultPort,
656
+ defaultValue: sshDefaultPort,
657
+ validate: (value) => {
658
+ if (value.length !== 0 && value.trim().length === 0)
659
+ return messages.validation.required;
660
+ },
661
+ }));
662
+ }
663
+ else if (scope.sshPort) {
664
+ step(`${messages.ssh.port}\n${dim(scope.sshPort)}`);
665
+ }
666
+ if (!sshFullyDefined && !scope.rutoken) {
667
+ scope.rutoken = await prompt(confirm({
668
+ message: `${messages.ssh.useRutoken} ${dim(messages.accent.ifConfigured)}`,
669
+ initialValue: false,
670
+ }));
671
+ }
672
+ else if (scope.rutoken) {
673
+ step(`${messages.ssh.useRutoken} ${dim(messages.accent.ifConfigured)}\n${dim('Yes')}`);
674
+ }
593
675
  if (!isFeatureFlagsUsed) {
594
676
  scope.features = await prompt(multiselect({
595
677
  message: `${messages.featureSelection.message}${inlineSub(dim(messages.featureSelection.hint))}`,
@@ -610,7 +692,30 @@ async function run() {
610
692
  fs.mkdirSync(root);
611
693
  }
612
694
  step(`${messages.status.scaffolding} ${yellow(root)}`);
613
- const pkg = { name: scope.packageName, version: '0.0.0' };
695
+ const pkg = {
696
+ name: scope.packageName,
697
+ version: '0.0.0',
698
+ scripts: {
699
+ 'wb:deploy': '',
700
+ },
701
+ };
702
+ const deployScript = ['rsync'];
703
+ if (process.platform === 'win32') {
704
+ // Run rsync trough WSL on Windows systems.
705
+ deployScript.unshift('wsl ');
706
+ }
707
+ if (scope.rutoken || scope.sshPort) {
708
+ deployScript.push(' -e \'ssh');
709
+ if (scope.rutoken)
710
+ deployScript.push(' -I /usr/lib/librtpkcs11ecp.so');
711
+ if (scope.sshPort)
712
+ deployScript.push(` -p ${scope.sshPort}`);
713
+ deployScript.push('\'');
714
+ }
715
+ deployScript.push(' -rltzvgO --progress --delete --exclude=\'alarms.conf\'');
716
+ deployScript.push(' --groupmap=\'*:developers\' dist/es5/*');
717
+ deployScript.push(` '${scope.sshUsername}@${scope.sshHostname}:/mnt/data/etc/'`);
718
+ pkg.scripts['wb:deploy'] = deployScript.join('');
614
719
  fs.writeFileSync(resolve(root, 'package.json'), JSON.stringify(pkg, null, 2));
615
720
  const templateRoot = fileURLToPath(new URL(templatesPath, import.meta.url));
616
721
  const render = function (templateName) {
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "title": "The Framework to write wb-rules in TypeScript",
3
- "intro": "Project Settings",
3
+ "captions": {
4
+ "intro": "Project Settings",
5
+ "deploy": "Deploy Settings"
6
+ },
4
7
  "projectName": {
5
8
  "message": "Project Name (target directory):"
6
9
  },
@@ -16,6 +19,12 @@
16
19
  "message": "is not empty.",
17
20
  "confirmDelete": "Remove existing files before continue?"
18
21
  },
22
+ "ssh": {
23
+ "username": "🔑 SSH Username:",
24
+ "host": "🌐 SSH Host:",
25
+ "port": "🚩 SSH Port:",
26
+ "useRutoken": "Use Rutoken ECP"
27
+ },
19
28
  "featureSelection": {
20
29
  "message": "Select features to include in your project:",
21
30
  "hint": "↑/↓ to navigate, space to select, A to toggle all, Enter to confirm"
@@ -44,7 +53,8 @@
44
53
  "installingDependencies": "Calling the package manager"
45
54
  },
46
55
  "accent": {
47
- "recommended": "(recommended)"
56
+ "recommended": "(recommended)",
57
+ "ifConfigured": "(if configured)"
48
58
  },
49
59
  "dependencies": {
50
60
  "question": "Install project dependencies?",
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "title": "Фреймворк для создания правил wb-rules на TypeScript",
3
- "intro": "Параметры проекта",
3
+ "captions": {
4
+ "intro": "Параметры проекта",
5
+ "deploy": "Параметры деплоя на контроллер"
6
+ },
4
7
  "projectName": {
5
8
  "message": "Название (целевая директория):",
6
9
  "errorMessage": "Требуется указать значение"
@@ -17,6 +20,12 @@
17
20
  "message": "содержит файлы.",
18
21
  "confirmDelete": "Удалить их?"
19
22
  },
23
+ "ssh": {
24
+ "username": "🔑 Пользователь SSH:",
25
+ "host": "🌐 Хост SSH:",
26
+ "port": "🚩 Порт SSH:",
27
+ "useRutoken": "Использовать Рутокен ЭЦП?"
28
+ },
20
29
  "featureSelection": {
21
30
  "message": "Выберите добавляемый функционал:",
22
31
  "hint": "↑/↓ для навигации, пробел для выбора, A - выбрать всё, Enter - подтвердить"
@@ -45,7 +54,8 @@
45
54
  "installingDependencies": "Вызов менеджера пакетов"
46
55
  },
47
56
  "accent": {
48
- "recommended": "(рекомендуется)"
57
+ "recommended": "(рекомендуется)",
58
+ "ifConfigured": "(если настроен)"
49
59
  },
50
60
  "dependencies": {
51
61
  "question": "Установить требуемые зависимости?",
@@ -8,10 +8,10 @@
8
8
  "build:dev": "cross-env NODE_ENV=development rollup -c"
9
9
  },
10
10
  "dependencies": {
11
- "mirta": "0.0.2"
11
+ "mirta": "0.0.3"
12
12
  },
13
13
  "devDependencies": {
14
- "@mirta/rollup": "0.0.2",
14
+ "@mirta/rollup": "0.0.3",
15
15
  "cross-env": "^7.0.3",
16
16
  "rollup": "^4.45.1"
17
17
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@mirta/store": "0.0.2"
3
+ "@mirta/store": "0.0.3"
4
4
  }
5
5
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@mirta/globals": "0.0.2",
4
- "@mirta/tsconfig": "0.0.2",
3
+ "@mirta/globals": "0.0.3",
4
+ "@mirta/tsconfig": "0.0.3",
5
5
  "@types/node": "^24.1.0",
6
6
  "typescript": "^5.8.3"
7
7
  }
@@ -2,12 +2,13 @@
2
2
  "extends": "@mirta/tsconfig",
3
3
  "compilerOptions": {
4
4
  "paths": {
5
- "@wbm/*": ["./src/wb-rules-modules/*"]
5
+ "@wbm/*": [
6
+ "./src/wb-rules-modules/*"
7
+ ]
6
8
  },
7
9
  "types": [
8
10
  "@mirta/globals",
9
- "node",
10
- "vitest/globals"
11
+ "node"
11
12
  ]
12
13
  }
13
14
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": [
4
+ "vitest/globals"
5
+ ]
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-mirta",
3
3
  "description": "🛠️ The recommended way to start a Mirta project.",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "license": "Unlicense",
6
6
  "keywords": [
7
7
  "mirta",