create-mirta 0.3.5 → 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.
Files changed (96) hide show
  1. package/dist/classic.mjs +120 -0
  2. package/dist/index.mjs +800 -690
  3. package/dist/mono.mjs +208 -0
  4. package/dist/resolver.mjs +843 -0
  5. package/locales/en-US.json +109 -0
  6. package/locales/ru-RU.json +109 -0
  7. package/package.json +25 -22
  8. package/templates/classic/starter/content/package.json +11 -0
  9. package/{dist/templates/config/typescript → templates/classic/starter/content}/tsconfig.json +0 -5
  10. package/{dist/templates/eslint/eslint.config.mjs.ejs → templates/classic/starter/features/eslint/eslint.config.mjs.tt} +11 -6
  11. package/{dist/templates/base/_env → templates/classic/starter/features/examples/_.env} +1 -1
  12. package/templates/classic/starter/features/examples/src/wb-rules/01-counter.ts +12 -0
  13. package/templates/classic/starter/features/examples/src/wb-rules-modules/counter.ts +42 -0
  14. package/templates/classic/starter/features/examples-vitest/tests/wb-rules-modules/counter.test.ts +56 -0
  15. package/templates/classic/starter/features/vitest/package.json +10 -0
  16. package/templates/classic/starter/features/vitest-eslint/package.json +5 -0
  17. package/templates/classic/starter/template.json +10 -0
  18. package/{dist/templates/config/store → templates/classic/store/content}/package.json +1 -1
  19. package/templates/classic/store/features/examples/src/wb-rules/01-counter.ts +13 -0
  20. package/templates/classic/store/features/examples/src/wb-rules/02-counter.ts +19 -0
  21. package/templates/classic/store/features/examples/src/wb-rules-modules/counter-store.ts +33 -0
  22. package/templates/classic/store/features/examples/src/wb-rules-modules/counter.ts +44 -0
  23. package/templates/classic/store/features/examples-vitest/tests/wb-rules-modules/counter.test.ts +49 -0
  24. package/templates/classic/store/template.json +14 -0
  25. package/templates/mono/core/content/package.json +6 -0
  26. package/templates/mono/core/content/pnpm-workspace.yaml +3 -0
  27. package/templates/mono/core/content/sites/.gitkeep +0 -0
  28. package/templates/mono/core/content/tsconfig.json +31 -0
  29. package/templates/mono/core/features/eslint/eslint.config.mjs.tt +126 -0
  30. package/templates/mono/core/features/vitest/package.json +10 -0
  31. package/templates/mono/core/template.json +5 -0
  32. package/templates/mono/package/features/package/packages/{{package}}/package.json.tt +25 -0
  33. package/templates/mono/package/features/package/packages/{{package}}/src/.gitkeep +0 -0
  34. package/templates/mono/package/features/package/packages/{{package}}/tsconfig.build.json +10 -0
  35. package/templates/mono/package/features/package/sites/{{package}}-demo/package.json.tt +19 -0
  36. package/templates/mono/package/features/package/sites/{{package}}-demo/src/wb-rules/.gitkeep +0 -0
  37. package/templates/mono/package/features/package/sites/{{package}}-demo/src/wb-rules-modules/.gitkeep +0 -0
  38. package/templates/mono/package/features/package/sites/{{package}}-demo/tsconfig.build.json +10 -0
  39. package/templates/mono/package/features/package-examples/packages/{{package}}/src/index.ts +2 -0
  40. package/templates/mono/package/features/package-examples/packages/{{package}}/src/thermostat.ts +99 -0
  41. package/templates/mono/package/features/package-examples/packages/{{package}}/src/types.ts +25 -0
  42. package/templates/mono/package/features/package-examples/sites/{{package}}-demo/src/wb-rules/01-thermo.ts.tt +11 -0
  43. package/templates/mono/package/features/package-examples-vitest/packages/{{package}}/tests/mirta-thermostat.test.ts +72 -0
  44. package/templates/mono/package/features/package-github/packages/{{package}}/package.json.tt +11 -0
  45. package/templates/mono/package/template.json +16 -0
  46. package/templates/mono/sites/content/mirta.config.json +37 -0
  47. package/templates/mono/sites/content/sites/home/package.json +17 -0
  48. package/templates/mono/sites/content/sites/home/src/wb-rules/.gitkeep +0 -0
  49. package/templates/mono/sites/content/sites/home/src/wb-rules-modules/.gitkeep +0 -0
  50. package/templates/mono/sites/content/sites/home-staging/package.json +17 -0
  51. package/templates/mono/sites/content/sites/home-staging/src/wb-rules/.gitkeep +0 -0
  52. package/templates/mono/sites/content/sites/home-staging/src/wb-rules-modules/.gitkeep +0 -0
  53. package/templates/mono/sites/template.json +9 -0
  54. package/{dist/templates/base/_editorconfig → templates/shared/base/content/_.editorconfig} +1 -1
  55. package/{dist/templates/base/_gitignore → templates/shared/base/content/_.gitignore} +1 -3
  56. package/templates/shared/base/content/_.node-version +1 -0
  57. package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/settings.json +12 -1
  58. package/templates/shared/base/content/package.json +22 -0
  59. package/templates/shared/base/features/connection/_.env.local.tt +1 -0
  60. package/templates/shared/base/features/connection/mirta.config.json +6 -0
  61. package/templates/shared/base/features/eslint/package.json +9 -0
  62. package/templates/shared/base/features/examples/mirta.config.json.tt +51 -0
  63. package/templates/shared/base/features/github/_.github/workflows/build.yml.tt +56 -0
  64. package/templates/shared/base/features/github-vitest/_.github/workflows/test.yml +30 -0
  65. package/templates/shared/base/template.json +16 -0
  66. package/dist/locales/en-US.json +0 -85
  67. package/dist/locales/ru-RU.json +0 -86
  68. package/dist/templates/base/package.json +0 -27
  69. package/dist/templates/base/rollup.config.mjs +0 -15
  70. package/dist/templates/config/typescript/package.json +0 -8
  71. package/dist/templates/config/vitest/package.json +0 -10
  72. package/dist/templates/config/vitest/tests/setup/dotenv.ts +0 -5
  73. package/dist/templates/config/vitest/tests/setup/mirta.ts +0 -41
  74. package/dist/templates/config/vitest/tests/tsconfig.json +0 -9
  75. package/dist/templates/config/vitest/vitest.config.ts +0 -37
  76. package/dist/templates/example/base/src/wb-rules/00-dotenv.ts +0 -52
  77. package/dist/templates/example/base/src/wb-rules/01-count.ts +0 -6
  78. package/dist/templates/example/base/src/wb-rules-modules/counter.ts +0 -14
  79. package/dist/templates/example/store/src/wb-rules/01-count.ts +0 -10
  80. package/dist/templates/example/store/src/wb-rules-modules/counter-store.ts +0 -7
  81. package/dist/templates/example/store/src/wb-rules-modules/counter.ts +0 -20
  82. package/dist/templates/example/vitest/base/tests/wb-rules-modules/counter.test.ts +0 -10
  83. package/dist/templates/example/vitest/store/tests/wb-rules-modules/counter-store.test.ts +0 -13
  84. /package/{dist/assets → assets}/logo.art +0 -0
  85. /package/{dist/templates/base → templates/classic/starter/content}/src/wb-rules/.gitkeep +0 -0
  86. /package/{dist/templates/base → templates/classic/starter/content}/src/wb-rules-modules/.gitkeep +0 -0
  87. /package/{dist/templates/base → templates/classic/starter/content}/types/env.d.ts +0 -0
  88. /package/{dist/templates/config → templates/classic/starter/features}/vitest/tests/wb-rules-modules/.gitkeep +0 -0
  89. /package/{dist/templates/config → templates/classic/starter/features}/vitest/tsconfig.json +0 -0
  90. /package/{dist/templates/base/_gitattributes → templates/shared/base/content/_.gitattributes} +0 -0
  91. /package/{dist/templates/base/_npmrc → templates/shared/base/content/_.npmrc} +0 -0
  92. /package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/extensions.json +0 -0
  93. /package/{dist/templates/base/.vscode → templates/shared/base/content/_.vscode}/tasks.json +0 -0
  94. /package/{dist/templates/config/eslint/.vscode → templates/shared/base/features/eslint/_.vscode}/extensions.json +0 -0
  95. /package/{dist/templates/config/eslint/.vscode → templates/shared/base/features/eslint/_.vscode}/settings.json +0 -0
  96. /package/{dist/templates/config/vitest/.vscode → templates/shared/base/features/vitest/_.vscode}/extensions.json +0 -0
@@ -0,0 +1,109 @@
1
+ {
2
+ "title": "Your framework for smart home automations",
3
+
4
+ "yes": "Yes",
5
+ "no": "No",
6
+
7
+ "args.errorHeader": "Invalid CLI {count, plural, one{argument} other{arguments}}",
8
+ "args.unknownOption": "{option} → unknown option",
9
+ "args.unknownOptionSuggest": "{option} → did you mean {suggestion}?",
10
+ "args.missingValue": "{option} → missing value",
11
+
12
+ "label.debug": "Debug",
13
+ "label.info": "Info",
14
+ "label.warning": "Warning",
15
+ "label.error": "Error",
16
+ "label.success": "Success",
17
+ "label.canceled": "Canceled",
18
+
19
+ "hint.recommended": "Recommended",
20
+ "hint.blocked": "Not supported by template",
21
+ "hint.select": "Use arrow keys. Enter to submit",
22
+
23
+ "captions.intro": "Project Settings",
24
+ "captions.deploy": "Deploy Settings",
25
+
26
+ "projectType.prompt": "Project Type",
27
+ "projectType.classic": "Classic — for Wiren Board controller",
28
+ "projectType.mono": "Mono — for related projects and NPM",
29
+
30
+ "projectFolder.prompt": "Project folder",
31
+
32
+ "packageName.prompt": "Package name",
33
+ "packageName.tooLong": "Exceeds {maxLength} characters",
34
+ "packageName.invalidFormat": "Invalid format",
35
+
36
+ "template.select": "Select template",
37
+ "template.notFound": "Template '{name}' not found",
38
+
39
+ "templates.starter.name": "Starter — Base Project",
40
+ "templates.starter.description": "A solid foundation",
41
+
42
+ "templates.store.name": "Store — Shared State",
43
+ "templates.store.description": "Access data from any script",
44
+
45
+ "templates.package.name": "Package — wb-rules modules for NPM",
46
+ "templates.package.description": "Code distribution",
47
+
48
+ "templates.sites.name": "Sites — connected projects",
49
+ "templates.sites.description": "Home and cottage, office",
50
+
51
+ "features.select": "Select features",
52
+ "features.instructions": "Navigate: ↑ / ↓\nSelect: ← / → / Space\nSelect all: A\nComplete answer: Enter",
53
+
54
+ "features.examples.name": "Examples — Quick Start",
55
+ "features.examples.description": "Typical use of the template and features",
56
+
57
+ "features.connection.name": "SSH — File Transfer",
58
+ "features.connection.description": "Configure connection to the controller",
59
+
60
+ "features.eslint.name": "ESLint — Static Analysis",
61
+ "features.eslint.description": "Enforce code style and catch errors",
62
+
63
+ "features.vitest.name": "Vitest — Unit Testing",
64
+ "features.vitest.description": "Test and debug without the controller",
65
+
66
+ "features.package.name": "Package — NPM module",
67
+ "features.package.description": "Publish your code to NPM",
68
+
69
+ "features.github.name": "GitHub — Repository & CI",
70
+ "features.github.description": "Set metadata and CI/CD workflows",
71
+
72
+ "feature.skipped": "Feature {feature} skipped — not supported by template",
73
+
74
+ "connection.caption": "Controller Connection Settings",
75
+
76
+ "ssh.username": "SSH Username",
77
+ "ssh.hostname": "SSH Hostname",
78
+ "ssh.port": "SSH Port",
79
+ "ssh.rutoken": "Use Rutoken ECP?",
80
+
81
+ "github.caption": "GitHub Settings",
82
+
83
+ "github.owner.prompt": "Repository owner",
84
+ "github.repository.prompt": "Repository name",
85
+ "github.branch.prompt": "Repository main branch",
86
+
87
+ "overwrite.notEmpty": "Location {path} is not empty",
88
+ "overwrite.prompt": "Remove existing files before continuing?",
89
+
90
+ "package.caption": "Package Settings",
91
+
92
+ "dependencies.prompt": "Install project dependencies?",
93
+ "dependencies.answer.yesUsing": "Yes, using {manager}",
94
+ "dependencies.answer.no": "No, I will handle that myself",
95
+
96
+ "step.canceled": "Operation canceled",
97
+ "step.removingFiles": "Removing files...",
98
+ "step.scaffolding": "Scaffolding project in {folder}",
99
+ "step.scaffolded": "The project has been scaffolded",
100
+ "step.installingDependencies": "Calling the package manager",
101
+
102
+ "validation.required": "Must be provided",
103
+ "validation.invalidFormat": "Invalid format",
104
+
105
+ "project.outsideRoot": "Cannot create project outside current directory",
106
+ "project.denyOverwrite": "Target directory is not empty",
107
+
108
+ "load.noTemplates": "No templates found for project type '{type}'"
109
+ }
@@ -0,0 +1,109 @@
1
+ {
2
+ "title": "Ваш фреймворк для современных автоматизаций",
3
+
4
+ "yes": "Да",
5
+ "no": "Нет",
6
+
7
+ "args.errorHeader": "{count, plural, one{Недопустимый аргумент} other{Недопустимые аргументы}} CLI",
8
+ "args.unknownOption": "{option} → неизвестный параметр",
9
+ "args.unknownOptionSuggest": "{option} → возможно, {suggestion}?",
10
+ "args.missingValue": "{option} → отсутствует значение",
11
+
12
+ "label.debug": "Отладка",
13
+ "label.info": "Инфо",
14
+ "label.warning": "Предупреждение",
15
+ "label.error": "Ошибка",
16
+ "label.success": "Успешно",
17
+ "label.canceled": "Отмена",
18
+
19
+ "hint.recommended": "Рекомендуется",
20
+ "hint.blocked": "Не поддерживается шаблоном",
21
+ "hint.select": "Используйте стрелки. Enter — подтвердить",
22
+
23
+ "captions.intro": "Настройки проекта",
24
+ "captions.deploy": "Настройки развёртывания",
25
+
26
+ "projectType.prompt": "Тип проекта",
27
+ "projectType.classic": "Классический — для контроллера Wiren Board",
28
+ "projectType.mono": "Моно — для связанных проектов и NPM",
29
+
30
+ "projectFolder.prompt": "Папка проекта",
31
+
32
+ "packageName.prompt": "Имя пакета",
33
+ "packageName.tooLong": "Превышает {maxLength} символов",
34
+ "packageName.invalidFormat": "Неверный формат",
35
+
36
+ "template.select": "Выберите шаблон",
37
+ "template.notFound": "Шаблон '{name}' не найден",
38
+
39
+ "templates.starter.name": "Стартер — начальный проект",
40
+ "templates.starter.description": "Сильная основа",
41
+
42
+ "templates.store.name": "Store — управление состоянием",
43
+ "templates.store.description": "Доступ к данным из любого скрипта",
44
+
45
+ "templates.package.name": "Пакет — модули wb-rules для NPM",
46
+ "templates.package.description": "Распространение кода",
47
+
48
+ "templates.sites.name": "Sites — связанные проекты",
49
+ "templates.sites.description": "Дом и дача, работа",
50
+
51
+ "features.select": "Выберите расширенные возможности",
52
+ "features.instructions": "Навигация: ↑ / ↓\nВыбрать: ← / → / Пробел\nВыбрать всё: A\nПодтвердить: Enter",
53
+
54
+ "features.examples.name": "Примеры — быстрый старт",
55
+ "features.examples.description": "Типовое использование шаблона и опций",
56
+
57
+ "features.connection.name": "SSH — передача файлов",
58
+ "features.connection.description": "Настроить подключение к контроллеру",
59
+
60
+ "features.eslint.name": "ESLint — статический анализ",
61
+ "features.eslint.description": "Контроль стиля и ошибок",
62
+
63
+ "features.vitest.name": "Vitest — модульные тесты",
64
+ "features.vitest.description": "Тесты и отладка без контроллера",
65
+
66
+ "features.package.name": "Пакет — модуль для NPM",
67
+ "features.package.description": "Распространение кода",
68
+
69
+ "features.github.name": "GitHub — репозиторий и CI",
70
+ "features.github.description": "Задать метаданные репозитория и настроить CI/CD",
71
+
72
+ "feature.skipped": "Функция {feature} пропущена — не поддерживается шаблоном",
73
+
74
+ "connection.caption": "Настройки подключения к контроллеру",
75
+
76
+ "ssh.username": "Пользователь SSH",
77
+ "ssh.hostname": "Хост SSH",
78
+ "ssh.port": "Порт SSH",
79
+ "ssh.rutoken": "Использовать Рутокен ЭЦП?",
80
+
81
+ "github.caption": "Параметры репозитория",
82
+
83
+ "github.owner.prompt": "Владелец репозитория (owner)",
84
+ "github.repository.prompt": "Имя репозитория",
85
+ "github.branch.prompt": "Основная ветка репозитория",
86
+
87
+ "package.caption": "Настройки пакета",
88
+
89
+ "overwrite.notEmpty": "Расположение {path} уже содержит файлы",
90
+ "overwrite.prompt": "Удалить существующие файлы перед продолжением?",
91
+
92
+ "dependencies.prompt": "Установить зависимости проекта?",
93
+ "dependencies.answer.yesUsing": "Да, с помощью {manager}",
94
+ "dependencies.answer.no": "Нет, я сделаю это самостоятельно",
95
+
96
+ "step.canceled": "Операция прервана",
97
+ "step.removingFiles": "Удаление файлов...",
98
+ "step.scaffolding": "Создание проекта в {folder}",
99
+ "step.scaffolded": "Проект создан",
100
+ "step.installingDependencies": "Вызов менеджера пакетов",
101
+
102
+ "validation.required": "Требуется указать значение",
103
+ "validation.invalidFormat": "Неверный формат",
104
+
105
+ "project.outsideRoot": "Невозможно создать проект вне текущей директории",
106
+ "project.denyOverwrite": "Целевая директория не пуста",
107
+
108
+ "load.noTemplates": "Шаблоны для типа проекта '{type}' не найдены"
109
+ }
package/package.json CHANGED
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "name": "create-mirta",
3
- "description": "🛠️ The recommended way to start a Mirta project.",
4
- "version": "0.3.5",
3
+ "description": "🛠️ The recommended way to start a Mirta project",
4
+ "version": "0.4.3",
5
5
  "license": "Unlicense",
6
6
  "keywords": [
7
7
  "mirta",
8
8
  "wb-rules"
9
9
  ],
10
- "engines": {
11
- "node": ">=20.6.0"
12
- },
13
10
  "type": "module",
11
+ "imports": {
12
+ "#*": "./src/*.js",
13
+ "#i18n": "./src/i18n/index.js",
14
+ "#jsonc": "./src/jsonc/index.js",
15
+ "#errors": "./src/errors/index.js",
16
+ "#runners": "./src/runners/index.js",
17
+ "#locales/*": "./locales/*.json"
18
+ },
14
19
  "files": [
15
20
  "dist",
21
+ "assets",
22
+ "locales",
23
+ "templates",
16
24
  "LICENSE",
17
25
  "README.md"
18
26
  ],
@@ -29,28 +37,23 @@
29
37
  "url": "https://github.com/wb-mirta/core/issues"
30
38
  },
31
39
  "dependencies": {
32
- "@clack/prompts": "^0.11.0",
40
+ "prompts": "^2.4.2",
33
41
  "chalk": "^5.6.2",
34
- "ejs": "^3.1.10",
35
- "fs-extra": "^11.3.2",
36
42
  "gradient-string": "^3.0.0",
37
- "is-unicode-supported": "^2.1.0",
38
- "lodash.merge": "^4.6.2"
43
+ "jsonc-parser": "^3.3.1",
44
+ "@mirta/i18n": "0.4.3",
45
+ "@mirta/staged-args": "0.4.3",
46
+ "@mirta/basics": "0.4.3"
39
47
  },
40
48
  "devDependencies": {
41
- "@eslint/js": "^9.38.0",
42
- "@stylistic/eslint-plugin": "^5.5.0",
43
- "@types/cross-spawn": "^6.0.6",
44
- "@types/ejs": "^3.1.5",
45
- "@types/fs-extra": "^11.0.4",
46
- "@types/lodash.merge": "^4.6.9",
47
- "eslint": "^9.38.0",
48
- "@vitest/eslint-plugin": "^1.3.23",
49
- "globals": "^16.4.0",
50
- "typescript-eslint": "^8.46.2"
49
+ "@types/prompts": "^2.4.9"
50
+ },
51
+ "engines": {
52
+ "node": ">=24.12.0"
51
53
  },
52
54
  "scripts": {
53
- "clean": "rimraf dist",
54
- "build:mono": "pnpm clean && rollup -c node:@mirta/rollup/config --config-package --config-skip-exports"
55
+ "build:mono": "rollup -c node:@mirta/rollup/config-package --config-skip-exports",
56
+ "i18n:shape-gen": "node ../../scripts/i18n/shape-gen.mjs",
57
+ "create": "node dist/index.mjs"
55
58
  }
56
59
  }
@@ -0,0 +1,11 @@
1
+ {
2
+ "imports": {
3
+ "#wb/*": "./src/wb-rules/*.js",
4
+ "#wbm/*": "./src/wb-rules-modules/*.js"
5
+ },
6
+ "scripts": {
7
+ "build": "cross-env NODE_ENV=production rollup -c node:@mirta/rollup/config",
8
+ "build:dev": "rollup -c node:@mirta/rollup/config",
9
+ "wb:deploy": "mirta deploy"
10
+ }
11
+ }
@@ -2,11 +2,6 @@
2
2
  "extends": "@mirta/tsconfig",
3
3
  "compilerOptions": {
4
4
  "rootDir": ".",
5
- "paths": {
6
- "@wbm/*": [
7
- "./src/wb-rules-modules/*"
8
- ]
9
- },
10
5
  "types": [
11
6
  "@mirta/globals",
12
7
  "node"
@@ -3,9 +3,9 @@ import globals from 'globals'
3
3
  import globalsMirta from '@mirta/globals/eslint'
4
4
  import tseslint from 'typescript-eslint'
5
5
  import stylistic from '@stylistic/eslint-plugin'
6
- <%_ if (addVitest) { _%>
6
+ {{#if features.vitest}}
7
7
  import vitest from '@vitest/eslint-plugin'
8
- <%_ } _%>
8
+ {{/if features.vitest}}
9
9
  import { defineConfig, globalIgnores } from 'eslint/config'
10
10
 
11
11
  export default defineConfig([
@@ -24,11 +24,11 @@ export default defineConfig([
24
24
  },
25
25
  },
26
26
  // TypeScript Defaults
27
- tseslint.configs.strictTypeChecked.map(config => ({
27
+ ...tseslint.configs.strictTypeChecked.map(config => ({
28
28
  ...config,
29
29
  files: ['**/*.ts'],
30
30
  })),
31
- tseslint.configs.stylisticTypeChecked.map(config => ({
31
+ ...tseslint.configs.stylisticTypeChecked.map(config => ({
32
32
  ...config,
33
33
  files: ['**/*.ts'],
34
34
  })),
@@ -59,6 +59,11 @@ export default defineConfig([
59
59
  'ignoreRestSiblings': true,
60
60
  },
61
61
  ],
62
+ '@typescript-eslint/prefer-nullish-coalescing': ['error', {
63
+ 'ignorePrimitives': {
64
+ 'string': true,
65
+ },
66
+ }],
62
67
  },
63
68
  languageOptions: {
64
69
  parserOptions: {
@@ -91,7 +96,7 @@ export default defineConfig([
91
96
  }],
92
97
  },
93
98
  },
94
- <%_ if (addVitest) { _%>
99
+ {{#if features.vitest}}
95
100
  // Vitest Defaults
96
101
  {
97
102
  files: ['tests/**'],
@@ -107,7 +112,7 @@ export default defineConfig([
107
112
  },
108
113
  },
109
114
  },
110
- <%_ } _%>
115
+ {{/if features.vitest}}
111
116
  globalIgnores([
112
117
  'node_modules/',
113
118
  'dist/',
@@ -1,4 +1,4 @@
1
1
  APP_FRAMEWORK='Mirta'
2
2
 
3
3
  # Example environment variable with expansion
4
- APP_NAME='${APP_FRAMEWORK} Project'
4
+ APP_NAME=`${APP_FRAMEWORK} Project`
@@ -0,0 +1,12 @@
1
+ import { useCounter } from '#wbm/counter'
2
+
3
+ log('Script: {}', __filename)
4
+
5
+ // Использует счетчик из модуля counter
6
+ const counter = useCounter()
7
+
8
+ // Увеличивает значение счетчика на 1
9
+ counter.increment()
10
+
11
+ // Выводит в лог текущее значение счетчика
12
+ log('Counter Value: {}', counter.count)
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Простой счётчик с возможностью инкремента и чтения текущего значения
3
+ *
4
+ **/
5
+ export interface Counter {
6
+
7
+ /** Позволяет прочесть значение счётчика. */
8
+ get count(): number
9
+
10
+ /** Увеличивает значение счётчика на единицу. */
11
+ increment(): void
12
+
13
+ }
14
+
15
+ /**
16
+ * Функция-построитель простого счётчика
17
+ *
18
+ * @returns Экземпляр счётчика
19
+ *
20
+ **/
21
+ export function useCounter(): Counter {
22
+
23
+ // Значение счётчика - его индивидуальное состояние
24
+ let count = 0
25
+
26
+ return {
27
+
28
+ get count() {
29
+
30
+ return count
31
+
32
+ },
33
+
34
+ increment() {
35
+
36
+ count += 1
37
+
38
+ }
39
+
40
+ }
41
+
42
+ }
@@ -0,0 +1,56 @@
1
+ import { useCounter } from '#wbm/counter'
2
+
3
+ describe('Counter', () => {
4
+
5
+ let counter: ReturnType<typeof useCounter>
6
+
7
+ beforeEach(() => {
8
+
9
+ counter = useCounter()
10
+
11
+ })
12
+
13
+ it('should start with count equal to 0', () => {
14
+
15
+ expect(counter.count).toBe(0)
16
+
17
+ })
18
+
19
+ it('should increment count by 1 when increment is called', () => {
20
+
21
+ counter.increment()
22
+ expect(counter.count).toBe(1)
23
+
24
+ counter.increment()
25
+ expect(counter.count).toBe(2)
26
+
27
+ })
28
+
29
+ it('should not allow direct modification of count', () => {
30
+
31
+ const initial = counter.count
32
+
33
+ // @ts-expect-error – подавляем ошибку этапа компиляции
34
+ counter.count = 100
35
+
36
+ // Значение не должно измениться
37
+ expect(counter.count).toBe(initial)
38
+
39
+ })
40
+
41
+ it('should have independent state for each instance', () => {
42
+
43
+ const counter1 = useCounter()
44
+ const counter2 = useCounter()
45
+
46
+ counter1.increment()
47
+ counter1.increment()
48
+
49
+ counter2.increment()
50
+
51
+ expect(counter1.count).toBe(2)
52
+ expect(counter2.count).toBe(1)
53
+
54
+ })
55
+
56
+ })
@@ -0,0 +1,10 @@
1
+ {
2
+ "scripts": {
3
+ "test": "vitest run --config @mirta/testing/config"
4
+ },
5
+ "devDependencies": {
6
+ "@mirta/testing": "0.4.3",
7
+ "vitest": "^4.0.8",
8
+ "vitest-mock-extended": "^3.1.0"
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "devDependencies": {
3
+ "@vitest/eslint-plugin": "^1.6.4"
4
+ }
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "base",
3
+ "features": {
4
+ "compound": [
5
+ "examples-vitest",
6
+ "vitest-eslint"
7
+ ]
8
+ },
9
+ "order": 1010
10
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@mirta/store": "0.3.5"
3
+ "@mirta/store": "0.4.3"
4
4
  }
5
5
  }
@@ -0,0 +1,13 @@
1
+ import { useCounter } from '#wbm/counter'
2
+
3
+ log('Script: {}', __filename)
4
+
5
+ // Использует счетчик из модуля counter
6
+ const counter = useCounter()
7
+
8
+ // Увеличивает значение счетчика на 2
9
+ counter.increment()
10
+ counter.increment()
11
+
12
+ // Выводит в лог текущее значение счетчика
13
+ log('Counter Value: {}', counter.count)
@@ -0,0 +1,19 @@
1
+ import { useCounter } from '#wbm/counter'
2
+ import { useCounterStore } from '#wbm/counter-store'
3
+
4
+ log('Script: {}', __filename)
5
+
6
+ // Использует счетчик из модуля counter
7
+ const counter = useCounter()
8
+
9
+ // Увеличивает значение счетчика на 2
10
+ counter.increment()
11
+ counter.increment()
12
+
13
+ // Выводит в лог текущее значение счетчика
14
+ log('Counter Value: {}', counter.count)
15
+
16
+ const store = useCounterStore()
17
+
18
+ // Выводит в лог значение напрямую из store
19
+ log('Value from store: {}, double from getter: {}', store.count, store.double)
@@ -0,0 +1,33 @@
1
+ import { defineStore } from '@mirta/store'
2
+
3
+ export const useCounterStore = defineStore('counter', {
4
+
5
+ state: () => ({
6
+
7
+ count: 0,
8
+
9
+ }),
10
+
11
+ getters: {
12
+
13
+ double: state => state.count * 2,
14
+
15
+ },
16
+
17
+ actions: {
18
+
19
+ increment() {
20
+
21
+ this.count++
22
+
23
+ },
24
+
25
+ setCount(value: number) {
26
+
27
+ this.count = value
28
+
29
+ },
30
+
31
+ },
32
+
33
+ })
@@ -0,0 +1,44 @@
1
+ import { useCounterStore } from '#wbm/counter-store'
2
+
3
+ /**
4
+ * Простой счётчик с возможностью инкремента и чтения текущего значения
5
+ *
6
+ **/
7
+ export interface Counter {
8
+
9
+ /** Позволяет прочесть значение счётчика. */
10
+ get count(): number
11
+
12
+ /** Увеличивает значение счётчика на единицу. */
13
+ increment(): void
14
+
15
+ }
16
+
17
+ /**
18
+ * Функция-построитель простого счётчика
19
+ *
20
+ * @returns Экземпляр счётчика
21
+ *
22
+ **/
23
+ export function useCounter(): Counter {
24
+
25
+ // Значение счётчика - глобальное состояние
26
+ const store = useCounterStore()
27
+
28
+ return {
29
+
30
+ get count() {
31
+
32
+ return store.count
33
+
34
+ },
35
+
36
+ increment() {
37
+
38
+ store.increment()
39
+
40
+ },
41
+
42
+ }
43
+
44
+ }