dana-cli 0.0.0-stage → 0.0.26
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/.github/dependabot.yml +43 -0
- package/.github/labeler.yml +30 -0
- package/.github/workflows/bump.yml +51 -0
- package/.github/workflows/ci-cd.yml +110 -0
- package/.github/workflows/dependabot-automerge-call.yml +13 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +4 -0
- package/CODEOWNERS +5 -0
- package/README.md +50 -2
- package/bin/bump.js +48 -0
- package/eslint.config.mjs +12 -0
- package/images/vodScreen1.png +0 -0
- package/package.json +53 -5
- package/sonar-project.properties +20 -0
- package/tools/cli/README.md +51 -0
- package/tools/cli/__mocks__/fs/promises.cjs +4 -0
- package/tools/cli/bin/dana.js +3 -0
- package/tools/cli/dana_completion.sh +156 -0
- package/tools/cli/eslint.config.mjs +14 -0
- package/tools/cli/package.json +67 -0
- package/tools/cli/rollup.config.mjs +26 -0
- package/tools/cli/src/commands/addComponent/addMenu/add-menu.ts +65 -0
- package/tools/cli/src/commands/addComponent/addMenu/addMenuDefinition.ts +21 -0
- package/tools/cli/src/commands/addComponent/addRail/add-rail.ts +59 -0
- package/tools/cli/src/commands/addComponent/addRail/addRailDefinition.ts +34 -0
- package/tools/cli/src/commands/addComponent/addScreen/add-screen.ts +42 -0
- package/tools/cli/src/commands/addComponent/addScreen/addScreenDefinition.ts +17 -0
- package/tools/cli/src/commands/addComponent/addScrollView/add-scrollView.ts +48 -0
- package/tools/cli/src/commands/addComponent/addScrollView/addScrollViewDefinition.ts +16 -0
- package/tools/cli/src/commands/addComponent/config/ComponentConfig.ts +169 -0
- package/tools/cli/src/commands/addComponent/config/componentTypes.ts +38 -0
- package/tools/cli/src/commands/addComponent/const/componentConst.ts +20 -0
- package/tools/cli/src/commands/addComponent/const/defaultConfig.ts +28 -0
- package/tools/cli/src/commands/addComponent/const/navigationConst.ts +36 -0
- package/tools/cli/src/commands/addComponent/createComponent.ts +45 -0
- package/tools/cli/src/commands/addComponent/helper/ComponentHelper.ts +98 -0
- package/tools/cli/src/commands/addDevice/add-device.ts +106 -0
- package/tools/cli/src/commands/addDevice/addDeviceDefinition.ts +13 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/androidtvConfig.ts +142 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/configTypes.ts +44 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/deviceConfig.ts +38 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/titanosConfig.ts +17 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/tizenConfig.ts +64 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/tvosConfig.ts +50 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/vidaaConfig.ts +17 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/webosConfig.ts +64 -0
- package/tools/cli/src/commands/addDevice/helper/addDeviceHelper.ts +121 -0
- package/tools/cli/src/commands/addDianaSkills/add-dianaSkills.ts +55 -0
- package/tools/cli/src/commands/addDianaSkills/addDianaSkillsDefinition.ts +13 -0
- package/tools/cli/src/commands/addDianaSkills/dianaDependencies.ts +15 -0
- package/tools/cli/src/commands/addModule/add-module.ts +46 -0
- package/tools/cli/src/commands/addModule/addModuleDefinition.ts +17 -0
- package/tools/cli/src/commands/addModule/moduleConst.ts +18 -0
- package/tools/cli/src/commands/authentication/AuthenticationManager.ts +255 -0
- package/tools/cli/src/commands/authentication/authDefinition.ts +51 -0
- package/tools/cli/src/commands/authentication/authHook.ts +50 -0
- package/tools/cli/src/commands/authentication/authentConst.ts +6 -0
- package/tools/cli/src/commands/authentication/commands/get-packages-token.ts +40 -0
- package/tools/cli/src/commands/authentication/commands/login.ts +63 -0
- package/tools/cli/src/commands/authentication/commands/logout.ts +26 -0
- package/tools/cli/src/commands/authentication/commands/status.ts +47 -0
- package/tools/cli/src/commands/authentication/helper/CodeArtifactHelper.ts +66 -0
- package/tools/cli/src/commands/authentication/helper/CommandHelper.ts +9 -0
- package/tools/cli/src/commands/authentication/helper/CredentialsHelper.ts +176 -0
- package/tools/cli/src/commands/authentication/helper/SPM.ts +95 -0
- package/tools/cli/src/commands/authentication/tokenHook.ts +30 -0
- package/tools/cli/src/commands/commandHelp/customHelp.ts +31 -0
- package/tools/cli/src/commands/completion/completion.ts +53 -0
- package/tools/cli/src/commands/completion/completionDefinition.ts +16 -0
- package/tools/cli/src/commands/createApp/const/createAppTasks.ts +133 -0
- package/tools/cli/src/commands/createApp/const/setupConst.ts +16 -0
- package/tools/cli/src/commands/createApp/const/templateConst.ts +10 -0
- package/tools/cli/src/commands/createApp/createApp.ts +60 -0
- package/tools/cli/src/commands/createApp/createAppDefinition.ts +26 -0
- package/tools/cli/src/commands/createApp/helpers/CreateAppHelper.ts +167 -0
- package/tools/cli/src/commands/createApp/helpers/SetupChecker.ts +98 -0
- package/tools/cli/src/commands/hooks/checkDanaProjectHook.ts +30 -0
- package/tools/cli/src/commands/zip/zip.ts +26 -0
- package/tools/cli/src/commands/zip/zipDefinition.ts +13 -0
- package/tools/cli/src/common/commonConst.ts +1 -0
- package/tools/cli/src/common/const/deviceConst.ts +110 -0
- package/tools/cli/src/common/const/exitCodeConst.ts +12 -0
- package/tools/cli/src/common/helpers/CreateArchiveHelper.ts +55 -0
- package/tools/cli/src/common/helpers/CreateFileHelper.ts +199 -0
- package/tools/cli/src/common/helpers/InputValidator.ts +58 -0
- package/tools/cli/src/common/helpers/InstallHelper.ts +202 -0
- package/tools/cli/src/common/helpers/UpdateFileHelper.ts +239 -0
- package/tools/cli/src/common/helpers/UserInputGetter.ts +145 -0
- package/tools/cli/src/common/helpers/handlebarsHelper.ts +31 -0
- package/tools/cli/src/common/helpers/stringHelper.ts +25 -0
- package/tools/cli/src/common/translation/en.json +87 -0
- package/tools/cli/src/common/translation/translation.ts +6 -0
- package/tools/cli/src/common/types/helperTypes.ts +79 -0
- package/tools/cli/src/index.ts +16 -0
- package/tools/cli/src/program.ts +59 -0
- package/tools/cli/tests/commands/addComponent/addMenu/add-menu.test.ts +96 -0
- package/tools/cli/tests/commands/addComponent/addRail/add-rail.test.ts +57 -0
- package/tools/cli/tests/commands/addComponent/addScreen/add-screen.test.ts +55 -0
- package/tools/cli/tests/commands/addComponent/addScrollView/add-scrollView.test.ts +89 -0
- package/tools/cli/tests/commands/addComponent/config/ComponentConfig.test.ts +261 -0
- package/tools/cli/tests/commands/addComponent/createComponent.test.ts +87 -0
- package/tools/cli/tests/commands/addComponent/helper/ComponentHelper.test.ts +110 -0
- package/tools/cli/tests/commands/addDevice/add-device.test.ts +117 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/androidtvConfig.test.ts +184 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/deviceConfig.test.ts +30 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/titanosConfig.test.ts +20 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/tizenConfig.test.ts +63 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/tvosConfig.test.ts +47 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/vidaaConfig.test.ts +20 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/webosConfig.test.ts +74 -0
- package/tools/cli/tests/commands/addDevice/helper/addDeviceHelper.test.ts +144 -0
- package/tools/cli/tests/commands/addDianaSkills/add-dianaSkills.test.ts +72 -0
- package/tools/cli/tests/commands/addModule/add-module.test.ts +108 -0
- package/tools/cli/tests/commands/authentication/AuthenticationManager.test.ts +756 -0
- package/tools/cli/tests/commands/authentication/commands/authDefinition.test.ts +53 -0
- package/tools/cli/tests/commands/authentication/commands/authHook.test.ts +94 -0
- package/tools/cli/tests/commands/authentication/commands/get-packages-token.test.ts +69 -0
- package/tools/cli/tests/commands/authentication/commands/login.test.ts +170 -0
- package/tools/cli/tests/commands/authentication/commands/logout.test.ts +77 -0
- package/tools/cli/tests/commands/authentication/commands/status.test.ts +73 -0
- package/tools/cli/tests/commands/authentication/helper/CredentialsHelper.test.ts +352 -0
- package/tools/cli/tests/commands/authentication/helper/SPM.test.ts +229 -0
- package/tools/cli/tests/commands/cliHelp/customHelp.test.ts +24 -0
- package/tools/cli/tests/commands/completion/completion.test.ts +76 -0
- package/tools/cli/tests/commands/createApp/const/createAppTasks.test.ts +70 -0
- package/tools/cli/tests/commands/createApp/createApp.test.ts +116 -0
- package/tools/cli/tests/commands/createApp/helpers/CreateAppHelper.test.ts +197 -0
- package/tools/cli/tests/commands/createApp/helpers/SetupChecker.test.ts +152 -0
- package/tools/cli/tests/commands/createApp/helpers/fixtures/myApp/scripts/app/ui/screens/SplashScreen.js +70 -0
- package/tools/cli/tests/commands/hooks/checkDanaProjectHook.test.ts +55 -0
- package/tools/cli/tests/commands/zip/zip.test.ts +51 -0
- package/tools/cli/tests/common/helpers/CreateArchiveHelper.test.ts +69 -0
- package/tools/cli/tests/common/helpers/CreateFileHelper.test.ts +359 -0
- package/tools/cli/tests/common/helpers/InputValidator.test.ts +93 -0
- package/tools/cli/tests/common/helpers/InstallHelper.test.ts +262 -0
- package/tools/cli/tests/common/helpers/UpdateFileHelper.test.ts +288 -0
- package/tools/cli/tests/common/helpers/UserInputGetter.test.ts +182 -0
- package/tools/cli/tests/common/helpers/handlebarsHelper.test.ts +87 -0
- package/tools/cli/tests/common/helpers/stringHelper.test.ts +35 -0
- package/tools/cli/tests/program.test.ts +215 -0
- package/tools/cli/tsconfig.json +19 -0
- package/tools/cli/tsconfig.test.json +4 -0
- package/tools/cli/vitest.config.ts +4 -0
- package/tools/templates/app-template/.dana/.gitkeep +0 -0
- package/tools/templates/app-template/Gruntfile.js +31 -0
- package/tools/templates/app-template/README.md +17 -0
- package/tools/templates/app-template/app.config.json +56 -0
- package/tools/templates/app-template/editorconfigTemplate.hbs +18 -0
- package/tools/templates/app-template/eslintrc.jsonTemplate.hbs +5 -0
- package/tools/templates/app-template/gitignoreTemplate.hbs +27 -0
- package/tools/templates/app-template/i18n/LocaleStringEnUS.json +7 -0
- package/tools/templates/app-template/i18n/README.md +32 -0
- package/tools/templates/app-template/images/dana.png +0 -0
- package/tools/templates/app-template/images/dana_logo.png +0 -0
- package/tools/templates/app-template/images/dana_logo_light.png +0 -0
- package/tools/templates/app-template/images/loading.png +0 -0
- package/tools/templates/app-template/nvmrcTemplate.hbs +1 -0
- package/tools/templates/app-template/package.json +33 -0
- package/tools/templates/app-template/profiles/app.config.browser-css.json +16 -0
- package/tools/templates/app-template/profiles/app.config.browser-lightning.json +16 -0
- package/tools/templates/app-template/scripts/app/README.md +6 -0
- package/tools/templates/app-template/scripts/app/TemplateAppRoutes.js.hbs +18 -0
- package/tools/templates/app-template/scripts/app/app.js.hbs +17 -0
- package/tools/templates/app-template/scripts/app/theme/AppTheme.js +57 -0
- package/tools/templates/app-template/scripts/app/ui/screens/AppScreen.js +106 -0
- package/tools/templates/app-template/scripts/app/ui/screens/SplashScreen.js +70 -0
- package/tools/templates/app-template/scripts/app/ui/views/LoaderView.js +31 -0
- package/tools/templates/app-template/styles/fonts/Roboto-Bold.ttf +0 -0
- package/tools/templates/app-template/styles/fonts/Roboto-Regular.ttf +0 -0
- package/tools/templates/app-template/tests/README.md +70 -0
- package/tools/templates/app-template/tests/automation/features/splash.feature +5 -0
- package/tools/templates/app-template/tests/automation/init.js +20 -0
- package/tools/templates/app-template/tests/automation/steps-definitions/dictionary.js +31 -0
- package/tools/templates/app-template/tests/automation/steps-definitions/helpers.js +9 -0
- package/tools/templates/app-template/tests/unit/README.md +7 -0
- package/tools/templates/app-template/tests/unit/app/TemplateAppRoutes.js.hbs +24 -0
- package/tools/templates/assets/fonts/fa-solid-900.ttf +0 -0
- package/tools/templates/components/ButtonItemView.js.hbs +69 -0
- package/tools/templates/components/ButtonView.js.hbs +65 -0
- package/tools/templates/components/ScrollItemView.js.hbs +53 -0
- package/tools/templates/components/ScrollView.js.hbs +43 -0
- package/tools/templates/components/TileView.js.hbs +55 -0
- package/tools/templates/components/screen.js.hbs +74 -0
- package/tools/templates/components/settings.js.hbs +74 -0
- package/tools/templates/components/vod.js.hbs +104 -0
- package/tools/templates/components/wtvMenuListView.js.hbs +38 -0
- package/tools/templates/components/wtvRailListView.js.hbs +44 -0
- package/tools/templates/index.ts +3 -0
- package/tools/templates/mocks/menuMock.json +29 -0
- package/tools/templates/mocks/railMock.json +101 -0
- package/tools/templates/mocks/scrollViewMock.json +165 -0
- package/tools/templates/modules/fip/images/12.png +0 -0
- package/tools/templates/modules/fip/images/audioD.png +0 -0
- package/tools/templates/modules/fip/package.json +5 -0
- package/tools/templates/modules/fip/scripts/FipModule.js +19 -0
- package/tools/templates/modules/fip/scripts/FipRoutes.js +19 -0
- package/tools/templates/modules/fip/scripts/services/mock/fipMock.json +12 -0
- package/tools/templates/modules/fip/scripts/ui/screens/FipScreen.js +169 -0
- package/tools/templates/modules/fip/scripts/ui/views/FipContentInfoView.js +77 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoDetailImageView.js +35 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoDetailTextView.js +39 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoListView.js +57 -0
- package/tools/templates/modules/fip/scripts/ui/views/PlayButtonView.js +63 -0
- package/tools/templates/modules/home/package.json +5 -0
- package/tools/templates/modules/home/scripts/HomeModule.js +19 -0
- package/tools/templates/modules/home/scripts/HomeRoutes.js +19 -0
- package/tools/templates/modules/home/scripts/services/mock/highlightMock.json +40 -0
- package/tools/templates/modules/home/scripts/services/mock/homeScrollViewMock.json +170 -0
- package/tools/templates/modules/home/scripts/ui/screens/HomeScreen.js +258 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/DotsListItemView.js +37 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/DotsListView.js +22 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightContentDescriptionView.js +99 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightPlayButtonView.js +63 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightRailItemView.js +186 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeMockTileView.js +67 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeRailScrollView.js +53 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeScrollView.js +22 -0
- package/tools/templates/modules/menu/images/profile.png +0 -0
- package/tools/templates/modules/menu/package.json +5 -0
- package/tools/templates/modules/menu/scripts/MenuModule.js +18 -0
- package/tools/templates/modules/menu/scripts/MenuRoutes.js +14 -0
- package/tools/templates/modules/menu/scripts/services/menuMock.json +24 -0
- package/tools/templates/modules/menu/scripts/ui/const/MenuIcons.js +16 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuButtonView.js +101 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuListView.js +60 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuView.js +87 -0
- package/tools/templates/modules/menu/scripts/ui/views/ProfileImageView.js +30 -0
- package/tools/templates/modules/player/package.json +5 -0
- package/tools/templates/modules/player/scripts/PlayerModule.js +19 -0
- package/tools/templates/modules/player/scripts/PlayerRoutes.js +19 -0
- package/tools/templates/modules/player/scripts/ui/const/PlayerIcons.js +19 -0
- package/tools/templates/modules/player/scripts/ui/screens/PlayerScreen.js +361 -0
- package/tools/templates/modules/player/scripts/ui/views/PlayerControlButtonView.js +69 -0
- package/tools/templates/modules/player/scripts/ui/views/PlayerControlsView.js +173 -0
- package/tools/templates/modules/player/scripts/ui/views/ProgressBarView.js +53 -0
- package/tools/templates/modules/search/package.json +5 -0
- package/tools/templates/modules/search/scripts/SearchModule.js +18 -0
- package/tools/templates/modules/search/scripts/SearchRoutes.js +16 -0
- package/tools/templates/modules/search/scripts/ui/const/EnglishKeyboardData.js +31 -0
- package/tools/templates/modules/search/scripts/ui/const/SearchIcons.js +14 -0
- package/tools/templates/modules/search/scripts/ui/const/SearchKeyboardLayout.js +19 -0
- package/tools/templates/modules/search/scripts/ui/primitives/SearchTextPrimitive.js +36 -0
- package/tools/templates/modules/search/scripts/ui/screens/SearchScreen.js +234 -0
- package/tools/templates/modules/search/scripts/ui/services/MockSearchService.js +39 -0
- package/tools/templates/modules/search/scripts/ui/services/SearchVirtualKeyboardService.js +33 -0
- package/tools/templates/modules/search/scripts/ui/services/mock/searchMock.json +172 -0
- package/tools/templates/modules/search/scripts/ui/views/SearchView.js +62 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardRowItemView.js +92 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardRowListView.js +33 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardView.js +63 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchScrollRailView.js +53 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchScrollView.js +22 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchTileView.js +68 -0
- package/tools/templates/modules/search/styles/styles/fonts/fa-solid-900.ttf +0 -0
- package/tools/templates/modules/settings/package.json +5 -0
- package/tools/templates/modules/settings/scripts/SettingsModule.js +19 -0
- package/tools/templates/modules/settings/scripts/SettingsRoutes.js +19 -0
- package/tools/templates/modules/settings/scripts/ui/screens/SettingsScreen.js +200 -0
- package/tools/templates/modules/settings/scripts/ui/views/SettingsListItemView.js +85 -0
- package/tools/templates/modules/settings/scripts/ui/views/SettingsListView.js +56 -0
- package/tools/templates/modules/vod/package.json +5 -0
- package/tools/templates/modules/vod/scripts/VodModule.js +19 -0
- package/tools/templates/modules/vod/scripts/VodRoutes.js +19 -0
- package/tools/templates/modules/vod/scripts/services/mock/scrollViewMock.json +172 -0
- package/tools/templates/modules/vod/scripts/ui/screens/VodScreen.js +204 -0
- package/tools/templates/modules/vod/scripts/ui/views/MockTileView.js +69 -0
- package/tools/templates/modules/vod/scripts/ui/views/RailScrollItemView.js +53 -0
- package/tools/templates/modules/vod/scripts/ui/views/VodScrollView.js +22 -0
- package/tools/templates/package.json +14 -0
- package/tools/templates/profiles/app.config.androidtv.json +17 -0
- package/tools/templates/profiles/app.config.titanos.json +24 -0
- package/tools/templates/profiles/app.config.tizen.json +52 -0
- package/tools/templates/profiles/app.config.tvos.json +18 -0
- package/tools/templates/profiles/app.config.vidaa.json +24 -0
- package/tools/templates/profiles/app.config.webos.json +21 -0
- package/tools/templates/tutorial/modules/fip/package.json +4 -0
- package/tools/templates/tutorial/modules/fip/scripts/FipModule.js +18 -0
- package/tools/templates/tutorial/modules/fip/scripts/FipRoutes.js +19 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/screens/FipContentScreen.js +146 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/ElevatorView.js +66 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/FipContentInfoView.js +90 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/PlayButtonView.js +58 -0
- package/tools/templates/tutorial/vendors/customBE/package.json +5 -0
- package/tools/templates/tutorial/vendors/customBE/scripts/datas/contents.json +749 -0
- package/tools/templates/tutorial/vendors/customBE/scripts/services/CustomBEVodService.js +70 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +19 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, it, expect, vi, MockedFunction, beforeEach } from "vitest";
|
|
2
|
+
import { createAppTasks } from "@/commands/createApp/const/createAppTasks.js";
|
|
3
|
+
import { AppType } from "@/commands/createApp/const/templateConst.js";
|
|
4
|
+
import { Data } from "@/common/types/helperTypes.js";
|
|
5
|
+
import { ModuleType } from "@/commands/addModule/moduleConst.js";
|
|
6
|
+
import { readdir } from "node:fs/promises";
|
|
7
|
+
import InstallHelper from "@/common/helpers/InstallHelper.js";
|
|
8
|
+
|
|
9
|
+
vi.mock("@/common/helpers/CreateFileHelper.js");
|
|
10
|
+
vi.mock("@/common/helpers/UpdateFileHelper.js");
|
|
11
|
+
vi.mock("@/common/helpers/InstallHelper.js");
|
|
12
|
+
vi.mock("@/commands/addComponent/helper/ComponentHelper.js");
|
|
13
|
+
vi.mock("node:fs/promises", () => ({
|
|
14
|
+
readdir: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock("node:path");
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.mocked(InstallHelper.getDependenciesList).mockResolvedValue(["dep1"]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
vi.resetAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const mockData: Data = {
|
|
27
|
+
devices: false,
|
|
28
|
+
name: "test",
|
|
29
|
+
skills: true,
|
|
30
|
+
} as unknown as Data;
|
|
31
|
+
|
|
32
|
+
describe("createAppTasks", () => {
|
|
33
|
+
it("returns bare app tasks for BARE type", async () => {
|
|
34
|
+
const tasks = await createAppTasks(mockData, AppType.BARE);
|
|
35
|
+
expect(tasks).toHaveLength(12);
|
|
36
|
+
expect(tasks[0].title).toBe("Copy template");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("adds tutorial tasks for TUTORIAL type", async () => {
|
|
40
|
+
const tasks = await createAppTasks(mockData, AppType.TUTORIAL);
|
|
41
|
+
expect(tasks).toHaveLength(13);
|
|
42
|
+
expect(tasks[11].title).toBe("Copy for tutorial");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("adds templated tasks for TEMPLATED type with update appTheme condition", async () => {
|
|
46
|
+
(vi.mocked(readdir) as unknown as MockedFunction<() => Promise<string[]>>).mockResolvedValue([
|
|
47
|
+
ModuleType.MENU,
|
|
48
|
+
ModuleType.SETTINGS,
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const tasks = await createAppTasks(mockData, AppType.TEMPLATED);
|
|
52
|
+
expect(tasks).toHaveLength(16);
|
|
53
|
+
expect(tasks[7].title).toBe("Copy skills for ai agents");
|
|
54
|
+
expect(tasks[7].condition).toBe(true);
|
|
55
|
+
expect(tasks[11].title).toBe("Copy modules for templated");
|
|
56
|
+
expect(tasks[13].title).toBe("Update appTheme");
|
|
57
|
+
expect(tasks[13].condition).toBe(true);
|
|
58
|
+
expect(tasks[15].title).toBe("Initialize git");
|
|
59
|
+
});
|
|
60
|
+
it("adds templated tasks for TEMPLATED type with NO update appTheme condition", async () => {
|
|
61
|
+
(vi.mocked(readdir) as unknown as MockedFunction<() => Promise<string[]>>).mockResolvedValue([ModuleType.FIP]);
|
|
62
|
+
|
|
63
|
+
const tasks = await createAppTasks(mockData, AppType.TEMPLATED);
|
|
64
|
+
expect(tasks).toHaveLength(16);
|
|
65
|
+
expect(tasks[11].title).toBe("Copy modules for templated");
|
|
66
|
+
expect(tasks[13].title).toBe("Update appTheme");
|
|
67
|
+
expect(tasks[13].condition).toBe(false);
|
|
68
|
+
expect(tasks[15].title).toBe("Initialize git");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { afterAll, afterEach, describe } from "vitest";
|
|
2
|
+
import createApp, { ProgramOptions } from "@/commands/createApp/createApp.js";
|
|
3
|
+
import { AppType } from "@/commands/createApp/const/templateConst.js";
|
|
4
|
+
import SetupChecker from "@/commands/createApp/helpers/SetupChecker.js";
|
|
5
|
+
import * as prompts from "@clack/prompts";
|
|
6
|
+
import { rm } from "node:fs/promises";
|
|
7
|
+
import { createAppTasks } from "@/commands/createApp/const/createAppTasks.js";
|
|
8
|
+
import CreateAppHelper from "@/commands/createApp/helpers/CreateAppHelper.js";
|
|
9
|
+
import InstallHelper from "@/common/helpers/InstallHelper.js";
|
|
10
|
+
import { APP_CREATION_ERROR } from "@/common/const/exitCodeConst.js";
|
|
11
|
+
|
|
12
|
+
vi.mock("@/commands/createApp/helpers/SetupChecker.js", () => ({
|
|
13
|
+
default: { checkSetup: vi.fn() },
|
|
14
|
+
}));
|
|
15
|
+
vi.mock("node:fs/promises", () => ({
|
|
16
|
+
rm: vi.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
vi.mock("@clack/prompts", () => ({
|
|
20
|
+
intro: vi.fn(),
|
|
21
|
+
group: vi.fn(),
|
|
22
|
+
spinner: vi.fn(() => ({
|
|
23
|
+
start: vi.fn(),
|
|
24
|
+
stop: vi.fn(),
|
|
25
|
+
})),
|
|
26
|
+
outro: vi.fn(),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
vi.mock("../../common/helpers/UserInputGetter.js", () => ({
|
|
30
|
+
default: {
|
|
31
|
+
getPrompts: vi.fn(() => ({})),
|
|
32
|
+
getDevicesConfig: vi.fn(() => ({})),
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
vi.mock("../authentication/helper/CredentialsHelper.js", () => ({
|
|
37
|
+
CredentialsHelper: { get: vi.fn(() => ({ org: "test-org" })) },
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
vi.mock("@/commands/createApp/helpers/CreateAppHelper.js", () => ({
|
|
41
|
+
default: {
|
|
42
|
+
installation: vi.fn(),
|
|
43
|
+
printNpmCommandForUser: vi.fn(),
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
vi.mock("@/commands/createApp/const/createAppTasks.js");
|
|
47
|
+
vi.mock("@/commands/createApp/helpers/CreateAppHelper.js");
|
|
48
|
+
vi.mock("@/common/helpers/InstallHelper.js");
|
|
49
|
+
|
|
50
|
+
describe("createApp", () => {
|
|
51
|
+
const data = {
|
|
52
|
+
selectedDevices: [],
|
|
53
|
+
type: AppType.BARE,
|
|
54
|
+
directory: "projectName",
|
|
55
|
+
skills: true,
|
|
56
|
+
} as unknown as ProgramOptions;
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
vi.mocked(prompts.group).mockResolvedValue(data);
|
|
59
|
+
vi.mocked(createAppTasks).mockResolvedValue([]);
|
|
60
|
+
vi.mocked(InstallHelper.getDependenciesList).mockResolvedValue(["dep1", "dep2"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
vi.clearAllMocks();
|
|
65
|
+
});
|
|
66
|
+
afterAll(() => {
|
|
67
|
+
vi.resetAllMocks();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should create a new app", async () => {
|
|
71
|
+
const optionsList = [
|
|
72
|
+
{
|
|
73
|
+
options: { type: AppType.BARE, devices: false, skills: true },
|
|
74
|
+
expectedSkills: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
options: { type: AppType.TUTORIAL, devices: false, skills: true },
|
|
78
|
+
expectedSkills: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
options: { type: AppType.TEMPLATED, devices: false, skills: false },
|
|
82
|
+
expectedSkills: false,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
const commonExpectedOptions = {
|
|
86
|
+
awsProfile: "public",
|
|
87
|
+
directory: "projectName",
|
|
88
|
+
selectedDevices: [],
|
|
89
|
+
allowBeta: false,
|
|
90
|
+
config: {},
|
|
91
|
+
type: "bare",
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
for (const { options, expectedSkills } of optionsList) {
|
|
95
|
+
await createApp("projectName", options);
|
|
96
|
+
expect(SetupChecker.checkSetup).toHaveBeenCalled();
|
|
97
|
+
expect(createAppTasks).toHaveBeenCalledWith(
|
|
98
|
+
{ ...commonExpectedOptions, skills: expectedSkills },
|
|
99
|
+
options.type,
|
|
100
|
+
);
|
|
101
|
+
expect(vi.mocked(CreateAppHelper.installation).mock.calls[0][0]).toEqual([]);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
it("should manage error", async () => {
|
|
105
|
+
vi.mocked(CreateAppHelper.installation).mockRejectedValue(new Error("Installation failed"));
|
|
106
|
+
vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
|
|
107
|
+
const options = { devices: false, type: AppType.BARE, skills: true };
|
|
108
|
+
|
|
109
|
+
await createApp("projectName", options);
|
|
110
|
+
expect(SetupChecker.checkSetup).toHaveBeenCalled();
|
|
111
|
+
expect(createAppTasks).toHaveBeenCalledWith(data, AppType.BARE);
|
|
112
|
+
expect(vi.mocked(CreateAppHelper.installation).mock.calls[0][0]).toEqual([]);
|
|
113
|
+
expect(rm).toHaveBeenCalledWith("./projectName", { recursive: true, force: true });
|
|
114
|
+
expect(process.exit).toHaveBeenCalledWith(APP_CREATION_ERROR);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import CreateAppHelper, { Spinner } from "@/commands/createApp/helpers/CreateAppHelper.js";
|
|
2
|
+
import * as prompts from "@clack/prompts";
|
|
3
|
+
import * as deviceConst from "@/common/const/deviceConst.js";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import WebosConfig from "@/commands/addDevice/deviceConfig/webosConfig.js";
|
|
6
|
+
import AndroidtvConfig from "@/commands/addDevice/deviceConfig/androidtvConfig.js";
|
|
7
|
+
import TizenConfig from "@/commands/addDevice/deviceConfig/tizenConfig.js";
|
|
8
|
+
import DeviceConfig from "@/commands/addDevice/deviceConfig/deviceConfig.js";
|
|
9
|
+
import TvosConfig from "@/commands/addDevice/deviceConfig/tvosConfig.js";
|
|
10
|
+
import { Data } from "@/common/types/helperTypes.js";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { fs, vol } from "memfs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
vi.mock("@clack/prompts");
|
|
16
|
+
vi.mock("node:fs/promises", async () => {
|
|
17
|
+
const memfs = await import("memfs");
|
|
18
|
+
return {
|
|
19
|
+
readFile: vi.fn(),
|
|
20
|
+
writeFile: memfs.fs.promises.writeFile,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
vi.mock("@babel/traverse", async () => {
|
|
24
|
+
return await vi.importActual("@babel/traverse");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
vi.mock("@babel/generator", async () => {
|
|
28
|
+
return await vi.importActual("@babel/generator");
|
|
29
|
+
});
|
|
30
|
+
vi.mock("@clack/prompts");
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.resetAllMocks();
|
|
34
|
+
vol.reset();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("askHtmlRenderers", () => {
|
|
38
|
+
const expectedOptions = [
|
|
39
|
+
{ label: "css", value: "css" },
|
|
40
|
+
{ label: "wasm", value: "wasm" },
|
|
41
|
+
{ label: "lightning", value: "lightning" },
|
|
42
|
+
];
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
vi.spyOn(deviceConst, "RENDERERS", "get").mockReturnValue(["css", "wasm", "lightning"]);
|
|
45
|
+
vi.mocked(prompts.multiselect).mockResolvedValue(["css", "wasm"]);
|
|
46
|
+
});
|
|
47
|
+
it("should prompt selected device", async () => {
|
|
48
|
+
await CreateAppHelper.askHtmlRenderers("tizen");
|
|
49
|
+
|
|
50
|
+
expect(vi.mocked(prompts.multiselect).mock.calls[0][0].message).toMatch("tizen");
|
|
51
|
+
});
|
|
52
|
+
it("should present a list of renderers", async () => {
|
|
53
|
+
await CreateAppHelper.askHtmlRenderers("tizen");
|
|
54
|
+
|
|
55
|
+
expect(vi.mocked(prompts.multiselect).mock.calls[0][0].options).toEqual(expectedOptions);
|
|
56
|
+
});
|
|
57
|
+
it("should return the selections", async () => {
|
|
58
|
+
const result = await CreateAppHelper.askHtmlRenderers("tizen");
|
|
59
|
+
|
|
60
|
+
expect(result).toEqual(["css", "wasm"]);
|
|
61
|
+
});
|
|
62
|
+
it("should handle cancellation", async () => {
|
|
63
|
+
vi.spyOn(CreateAppHelper, "handleCancellation").mockImplementationOnce(() => {
|
|
64
|
+
throw new Error("Project cancelled.");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return expect(CreateAppHelper.askHtmlRenderers("tizen")).rejects.toThrow("Project cancelled.");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("getDeviceConfig", () => {
|
|
72
|
+
it("should return the device config", () => {
|
|
73
|
+
const inputs = ["webos", "androidtv", "tizen", "tvos", "something"];
|
|
74
|
+
const expectedConfig = [WebosConfig, AndroidtvConfig, TizenConfig, TvosConfig, DeviceConfig];
|
|
75
|
+
inputs.forEach((input, index: number) => {
|
|
76
|
+
const result = CreateAppHelper.getDeviceConfig(input);
|
|
77
|
+
expect(result).toEqual(expectedConfig[index]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("installation", () => {
|
|
83
|
+
let spinner: Spinner;
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
spinner = {
|
|
86
|
+
start: vi.fn(),
|
|
87
|
+
stop: vi.fn(),
|
|
88
|
+
message: vi.fn(),
|
|
89
|
+
} as unknown as Spinner;
|
|
90
|
+
});
|
|
91
|
+
it(`should fail when a task fails`, async () => {
|
|
92
|
+
const tasks = [
|
|
93
|
+
{ title: "task1", task: vi.fn() },
|
|
94
|
+
{ title: "task2", task: vi.fn(), condition: false },
|
|
95
|
+
{ title: "task3", task: vi.fn().mockRejectedValue(new Error("task3 failed")) },
|
|
96
|
+
{ title: "task4", task: vi.fn() },
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
return expect(CreateAppHelper.installation(tasks)).rejects.toThrow("task3 failed");
|
|
100
|
+
});
|
|
101
|
+
it(`should execute all tasks if condition is true`, async () => {
|
|
102
|
+
const taskSpy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
103
|
+
|
|
104
|
+
const tasks = [
|
|
105
|
+
{ title: "task1", task: taskSpy },
|
|
106
|
+
{ title: "task2", task: taskSpy, condition: false },
|
|
107
|
+
{ title: "task3", task: taskSpy, condition: true },
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
await CreateAppHelper.installation(tasks, spinner);
|
|
111
|
+
|
|
112
|
+
expect(taskSpy).toHaveBeenCalledTimes(2);
|
|
113
|
+
expect(spinner.message).toHaveBeenCalledTimes(2);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("printNpmCommandForUser", () => {
|
|
118
|
+
it(`should print every command`, () => {
|
|
119
|
+
const data = {
|
|
120
|
+
directory: "./directory",
|
|
121
|
+
selectedDevices: ["tvos", "tizen"],
|
|
122
|
+
config: { tvos: {}, tizen: { renderers: ["css", "lightning"] } },
|
|
123
|
+
} as unknown as Data;
|
|
124
|
+
|
|
125
|
+
const expectedOptions = [
|
|
126
|
+
{ device: " browser", command: "start" },
|
|
127
|
+
{ device: " tvos", command: "start:tvos" },
|
|
128
|
+
{ device: " tizen", command: "start:tizen_css" },
|
|
129
|
+
{ device: " tizen", command: "start:tizen_lightning" },
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
const expectedCommandLine = `cd ./directory && npm run `;
|
|
133
|
+
CreateAppHelper.printNpmCommandForUser(data);
|
|
134
|
+
|
|
135
|
+
expect(vi.mocked(prompts.log.message)).toHaveBeenCalledTimes(4);
|
|
136
|
+
expect(vi.mocked(prompts.log.info)).toHaveBeenCalledTimes(3);
|
|
137
|
+
expectedOptions.forEach((option, index) => {
|
|
138
|
+
expect(vi.mocked(prompts.log.message).mock.calls[index][0]).toMatch(expectedCommandLine + option.command);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("setFirstRoute", () => {
|
|
144
|
+
const templatePath = path.resolve(
|
|
145
|
+
__dirname,
|
|
146
|
+
"../../../../../templates/app-template/scripts/app/ui/screens/SplashScreen.js",
|
|
147
|
+
); //real path from templates directory
|
|
148
|
+
const testDir = "/test-app";
|
|
149
|
+
const testSplashPath = path.resolve(testDir, "scripts", "app", "ui", "screens", "SplashScreen.js"); //path to memfs
|
|
150
|
+
|
|
151
|
+
beforeEach(async () => {
|
|
152
|
+
const actualFs = await vi.importActual<typeof import("node:fs/promises")>("node:fs/promises");
|
|
153
|
+
|
|
154
|
+
vi.mocked(readFile).mockImplementation(async (filePath) => {
|
|
155
|
+
// Redirect reads from test directory to template
|
|
156
|
+
if ((filePath as string).includes("test-app")) {
|
|
157
|
+
return actualFs.readFile(templatePath, "utf-8");
|
|
158
|
+
}
|
|
159
|
+
// Mock missing splashScreen
|
|
160
|
+
if ((filePath as string).includes("invalid")) {
|
|
161
|
+
throw new Error("ENOENT: no such file");
|
|
162
|
+
}
|
|
163
|
+
return actualFs.readFile(filePath, "utf-8");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
vol.fromJSON({
|
|
167
|
+
[testSplashPath]: "",
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
it("should replace console.warn with this.route('home')", async () => {
|
|
171
|
+
await CreateAppHelper.setFirstRoute({ directory: testDir }); //read real splashScreen
|
|
172
|
+
|
|
173
|
+
const modifiedContent = await fs.promises.readFile(testSplashPath, "utf-8"); //read memfs result
|
|
174
|
+
|
|
175
|
+
expect(modifiedContent).toContain('this.route("home")');
|
|
176
|
+
expect(modifiedContent).not.toContain('console.warn("FIXME: route to home !")');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("should preserve file structure and formatting", async () => {
|
|
180
|
+
await CreateAppHelper.setFirstRoute({ directory: testDir });
|
|
181
|
+
|
|
182
|
+
const modifiedContent = await fs.promises.readFile(testSplashPath, "utf-8");
|
|
183
|
+
|
|
184
|
+
expect(modifiedContent).toContain("beforeShow: function");
|
|
185
|
+
expect(modifiedContent).toContain("this.timerManager.setTimeout");
|
|
186
|
+
expect(modifiedContent).toContain("export default $AppScreen.declare");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should resolve on success", async () => {
|
|
190
|
+
const result = await CreateAppHelper.setFirstRoute({ directory: testDir });
|
|
191
|
+
expect(result).toBe("first route set");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should handle missing file gracefully", async () => {
|
|
195
|
+
return expect(CreateAppHelper.setFirstRoute({ directory: "/invalid" })).rejects.toThrow("ENOENT");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
|
|
3
|
+
* All Rights Reserved
|
|
4
|
+
*
|
|
5
|
+
* All information contained herein is proprietary and confidential.
|
|
6
|
+
* Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
|
|
7
|
+
* prior written permission is obtained from Wiztivi.
|
|
8
|
+
* No warranty, explicit or implicit, provided.
|
|
9
|
+
* This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import SetupChecker from "@/commands/createApp/helpers/SetupChecker.js";
|
|
14
|
+
import { vi, afterEach, describe, expect, test } from "vitest";
|
|
15
|
+
import { exec, ChildProcess } from "node:child_process";
|
|
16
|
+
import * as prompts from "@clack/prompts";
|
|
17
|
+
import translation from "@/common/translation/translation.js";
|
|
18
|
+
import { SETUP_ERROR } from "@/common/const/exitCodeConst.js";
|
|
19
|
+
|
|
20
|
+
vi.mock("@clack/prompts");
|
|
21
|
+
vi.mock("node:child_process");
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.resetAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("validateNodeVersion", () => {
|
|
28
|
+
test("should resolve if version meets nvmrc requirement", async () => {
|
|
29
|
+
vi.stubGlobal("process", { ...process, version: "v24.17.0" });
|
|
30
|
+
expect(await SetupChecker.validateNodeVersion()).toMatch(/Node version ok/);
|
|
31
|
+
});
|
|
32
|
+
test("should reject if version is below nvmrc requirement", async () => {
|
|
33
|
+
vi.stubGlobal("process", { ...process, version: "v14.17.0" });
|
|
34
|
+
return expect(SetupChecker.validateNodeVersion()).rejects.toThrow();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("executeCheck", () => {
|
|
39
|
+
test("should execute all tasks while in success", async () => {
|
|
40
|
+
const task1Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
41
|
+
const task2Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
42
|
+
const task3Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
43
|
+
const taskListSuccess = [
|
|
44
|
+
{ title: "Task 1", task: task1Spy },
|
|
45
|
+
{ title: "Task 2", task: task2Spy },
|
|
46
|
+
{ title: "Task 3", task: task3Spy },
|
|
47
|
+
];
|
|
48
|
+
await SetupChecker.executeCheck(taskListSuccess);
|
|
49
|
+
|
|
50
|
+
expect(task1Spy).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(task2Spy).toHaveBeenCalledTimes(1);
|
|
52
|
+
expect(task3Spy).toHaveBeenCalledTimes(1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("should stop if one Task reject", () => {
|
|
56
|
+
const task1Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
57
|
+
const task2Spy = vi.fn().mockImplementation(() => {
|
|
58
|
+
throw new Error("Task 2 failed");
|
|
59
|
+
});
|
|
60
|
+
const task3Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
61
|
+
const taskListError = [
|
|
62
|
+
{ title: "Task 1", task: task1Spy },
|
|
63
|
+
{ title: "Task 2", task: task2Spy },
|
|
64
|
+
{ title: "Task 3", task: task3Spy },
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
return expect(SetupChecker.executeCheck(taskListError)).rejects.toThrow("Task 2 failed");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("should execute task1 but not task3 when task2 fails", async () => {
|
|
71
|
+
const task1Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
72
|
+
const task2Spy = vi.fn().mockImplementation(() => {
|
|
73
|
+
throw new Error("Task 2 failed");
|
|
74
|
+
});
|
|
75
|
+
const task3Spy = vi.fn().mockImplementation(() => Promise.resolve());
|
|
76
|
+
const taskListError = [
|
|
77
|
+
{ title: "Task 1", task: task1Spy },
|
|
78
|
+
{ title: "Task 2", task: task2Spy },
|
|
79
|
+
{ title: "Task 3", task: task3Spy },
|
|
80
|
+
];
|
|
81
|
+
try {
|
|
82
|
+
await SetupChecker.executeCheck(taskListError);
|
|
83
|
+
} catch {
|
|
84
|
+
// Expected to fail
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
expect(task1Spy).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(task3Spy).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("validateAwsInstallation", () => {
|
|
93
|
+
test("should exec 'aws --version'", async () => {
|
|
94
|
+
vi.mocked(exec).mockImplementation((cmd, options, callback) => {
|
|
95
|
+
if (callback) callback(null, "aws ok", "");
|
|
96
|
+
return null as unknown as ChildProcess;
|
|
97
|
+
});
|
|
98
|
+
await SetupChecker.validateAwsInstallation();
|
|
99
|
+
|
|
100
|
+
expect(vi.mocked(exec)).toHaveBeenCalledTimes(1);
|
|
101
|
+
expect(vi.mocked(exec).mock.calls[0][0]).toBe("aws --version");
|
|
102
|
+
});
|
|
103
|
+
test("should reject if there is an error", async () => {
|
|
104
|
+
vi.mocked(exec).mockImplementation((_cmd, _options, callback) => {
|
|
105
|
+
if (callback) callback(Error("Error occurred"), "", "");
|
|
106
|
+
return null as unknown as ChildProcess;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return expect(SetupChecker.validateAwsInstallation()).rejects.toThrow(translation["aws.cli.error"]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("validateGitInstallation", () => {
|
|
114
|
+
test("should exec 'git --version'", async () => {
|
|
115
|
+
vi.mocked(exec).mockImplementation((cmd, options, callback) => {
|
|
116
|
+
if (callback) callback(null, "git ok", "");
|
|
117
|
+
return null as unknown as ChildProcess;
|
|
118
|
+
});
|
|
119
|
+
await SetupChecker.validateGitInstallation();
|
|
120
|
+
|
|
121
|
+
expect(vi.mocked(exec)).toHaveBeenCalledTimes(1);
|
|
122
|
+
expect(vi.mocked(exec).mock.calls[0][0]).toBe("git --version");
|
|
123
|
+
});
|
|
124
|
+
test("should reject if there is an error", async () => {
|
|
125
|
+
vi.mocked(exec).mockImplementation((_cmd, _options, callback) => {
|
|
126
|
+
if (callback) callback(new Error("Git error"), "", "");
|
|
127
|
+
return null as unknown as ChildProcess;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return expect(SetupChecker.validateGitInstallation()).rejects.toThrow(translation["git.error"]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("checkSetup", () => {
|
|
135
|
+
test("should log success", async () => {
|
|
136
|
+
vi.mocked(prompts.log.success);
|
|
137
|
+
vi.spyOn(SetupChecker, "executeCheck").mockImplementation(() => Promise.resolve());
|
|
138
|
+
await SetupChecker.checkSetup();
|
|
139
|
+
expect(vi.mocked(SetupChecker.executeCheck)).toHaveBeenCalled();
|
|
140
|
+
expect(prompts.log.success).toHaveBeenCalled();
|
|
141
|
+
});
|
|
142
|
+
test("should log error", async () => {
|
|
143
|
+
vi.mocked(prompts.outro);
|
|
144
|
+
vi.spyOn(SetupChecker, "executeCheck").mockImplementation(() => Promise.reject(new Error("failed")));
|
|
145
|
+
vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
|
|
146
|
+
await SetupChecker.checkSetup();
|
|
147
|
+
|
|
148
|
+
expect(vi.mocked(SetupChecker.executeCheck)).toHaveBeenCalled();
|
|
149
|
+
expect(prompts.outro).toHaveBeenCalled();
|
|
150
|
+
expect(process.exit).toHaveBeenCalledWith(SETUP_ERROR);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import $AppScreen from "@AppScreen";
|
|
2
|
+
import $LoaderView from "@LoaderView";
|
|
3
|
+
import $TimerManager from "@TimerManager";
|
|
4
|
+
import $RectanglePrimitive from "@RectanglePrimitive";
|
|
5
|
+
import $Theme from "@Theme";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The first screen that is shown, use to show a boot splash
|
|
9
|
+
*
|
|
10
|
+
* @name SplashScreen
|
|
11
|
+
* @class
|
|
12
|
+
* @extends AppScreen
|
|
13
|
+
*
|
|
14
|
+
* @property {TimerManager} timerManager - Instance of TimerManager
|
|
15
|
+
* @property {number} splashDuration - Duration in ms to display splash screen
|
|
16
|
+
*
|
|
17
|
+
* @screen
|
|
18
|
+
*/
|
|
19
|
+
export default $AppScreen.declare("SplashScreen", {
|
|
20
|
+
statics: {
|
|
21
|
+
HIDE_SPLASH_SCREEN_TIMER_ID: "SplashScreen:Hide",
|
|
22
|
+
},
|
|
23
|
+
properties: {
|
|
24
|
+
timerManager: { class: $TimerManager },
|
|
25
|
+
splashDuration: 2000,
|
|
26
|
+
},
|
|
27
|
+
children: /** @lends SplashScreen.prototype */ {
|
|
28
|
+
background: { class: $RectanglePrimitive },
|
|
29
|
+
loader: { class: $LoaderView },
|
|
30
|
+
},
|
|
31
|
+
methods: /** @lends SplashScreen.prototype */ {
|
|
32
|
+
/**
|
|
33
|
+
* Called before the screen is shown
|
|
34
|
+
* The flow is interrupted until the promise has been resolved/rejected
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} [context] The context shared by the screens during display
|
|
37
|
+
*/
|
|
38
|
+
beforeShow: function (context) {
|
|
39
|
+
this.timerManager.setTimeout(
|
|
40
|
+
() => {
|
|
41
|
+
this.route("home");
|
|
42
|
+
},
|
|
43
|
+
this.splashDuration,
|
|
44
|
+
this.statics.HIDE_SPLASH_SCREEN_TIMER_ID,
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Called before the screen is hidden
|
|
50
|
+
* The flow is interrupted until the promise has been resolved/rejected
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} [context] The context shared by the screens during display
|
|
53
|
+
*/
|
|
54
|
+
beforeHide: function (context) {
|
|
55
|
+
this.timerManager.stop(this.statics.HIDE_SPLASH_SCREEN_TIMER_ID);
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
style: {
|
|
60
|
+
background: {
|
|
61
|
+
width: $Theme.FULL_SCREEN_WIDTH,
|
|
62
|
+
height: $Theme.FULL_SCREEN_HEIGHT,
|
|
63
|
+
fillColor: $Theme.COLOR_BACKGROUND,
|
|
64
|
+
},
|
|
65
|
+
loader: {
|
|
66
|
+
x: ({ parent }) => (parent.width - parent.loader.width) / 2,
|
|
67
|
+
y: ({ parent }) => (parent.height - parent.loader.height) / 2,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
|
|
3
|
+
* All Rights Reserved
|
|
4
|
+
*
|
|
5
|
+
* All information contained herein is proprietary and confidential.
|
|
6
|
+
* Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
|
|
7
|
+
* prior written permission is obtained from Wiztivi.
|
|
8
|
+
* No warranty, explicit or implicit, provided.
|
|
9
|
+
* This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
import { checkDanaProjectHook } from "@/commands/hooks/checkDanaProjectHook.js";
|
|
15
|
+
import { Mock, vi } from "vitest";
|
|
16
|
+
import * as prompts from "@clack/prompts";
|
|
17
|
+
import translation from "@/common/translation/translation.js";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { findUp } from "find-up";
|
|
20
|
+
|
|
21
|
+
vi.mock("@clack/prompts");
|
|
22
|
+
vi.mock("find-up");
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.resetAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("checkDanaProjectHook", () => {
|
|
29
|
+
let exitSpy: Mock<(code?: number | string | null) => never>;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
33
|
+
return undefined as never;
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it("should not exit if the current directory is a Dana project", async () => {
|
|
37
|
+
vi.mocked(findUp).mockResolvedValue(join("testRoot", ".dana"));
|
|
38
|
+
|
|
39
|
+
const subCommand = new Command("testCommand");
|
|
40
|
+
await checkDanaProjectHook({} as Command, subCommand);
|
|
41
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
it("should not exit if command belongs to allowed command", async () => {
|
|
44
|
+
const subCommand = new Command("create-app");
|
|
45
|
+
await checkDanaProjectHook({} as Command, subCommand);
|
|
46
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
it("should exit if command is not allowed and current dir is not a dana project", async () => {
|
|
49
|
+
vi.mocked(findUp).mockResolvedValue("");
|
|
50
|
+
const subCommand = new Command("testCommand");
|
|
51
|
+
await checkDanaProjectHook({} as Command, subCommand);
|
|
52
|
+
expect(exitSpy).toHaveBeenCalledWith(10);
|
|
53
|
+
expect(vi.mocked(prompts.log.error)).toHaveBeenCalledWith(translation["command.hook.dana_project"]);
|
|
54
|
+
});
|
|
55
|
+
});
|