How to use projectDir method in storybook-root

Best JavaScript code snippet using storybook-root

create-test.ts

Source:create-test.ts Github

copy

Full Screen

1import { execSync } from "child_process";2import * as os from "os";3import * as path from "path";4import { pathToFileURL } from "url";5import * as fse from "fs-extra";6import inquirer from "inquirer";7import stripAnsi from "strip-ansi";8import { run } from "../cli/run";9import { server } from "./msw";10beforeAll(() => server.listen({ onUnhandledRequest: "error" }));11afterAll(() => server.close());12const yarnUserAgent = "yarn/1.22.18 npm/? node/v14.17.0 linux x64";13const pnpmUserAgent = "pnpm/6.32.3 npm/? node/v14.17.0 linux x64";14// keep the console clear15jest.mock("ora", () => {16 return jest.fn(() => ({17 start: jest.fn(() => ({18 stop: jest.fn(),19 clear: jest.fn(),20 })),21 }));22});23// this is so we can mock execSync for "npm install" and the like24jest.mock("child_process", () => {25 let cp = jest.requireActual(26 "child_process"27 ) as typeof import("child_process");28 let installDepsCmdPattern = /^(npm|yarn|pnpm) install$/;29 let configGetCmdPattern = /^(npm|yarn|pnpm) config get/;30 return {31 ...cp,32 execSync: jest.fn(33 (command: string, options: Parameters<typeof cp.execSync>[1]) => {34 // this prevents us from having to run the install process35 // and keeps our console output clean36 if (37 installDepsCmdPattern.test(command) ||38 configGetCmdPattern.test(command)39 ) {40 return "sample stdout";41 }42 return cp.execSync(command, options);43 }44 ),45 };46});47// this is so we can verify the prompts for the users48jest.mock("inquirer", () => {49 let inquirerActual = jest.requireActual("inquirer");50 return {51 ...inquirerActual,52 prompt: jest.fn().mockImplementation(inquirerActual.prompt),53 };54});55const TEMP_DIR = path.join(56 fse.realpathSync(os.tmpdir()),57 `remix-tests-${Math.random().toString(32).slice(2)}`58);59beforeAll(async () => {60 await fse.remove(TEMP_DIR);61 await fse.ensureDir(TEMP_DIR);62});63afterAll(async () => {64 await fse.remove(TEMP_DIR);65});66let output: string;67let originalLog = console.log;68let originalWarn = console.warn;69let originalError = console.error;70beforeEach(async () => {71 output = "";72 function hijackLog(message: unknown = "", ...rest: Array<unknown>) {73 // if you need to debug stuff, then use:74 // console.log('debug:', 'whatever you need to say');75 if (typeof message === "string" && message.startsWith("debug:")) {76 return originalLog(message, ...rest);77 }78 let messageString =79 typeof message === "string" ? message : JSON.stringify(message, null, 2);80 if (rest[0]) {81 throw new Error(82 "Our tests are not set up to handle multiple arguments to console.log."83 );84 }85 output += "\n" + stripAnsi(messageString).replace(TEMP_DIR, "<TEMP_DIR>");86 }87 console.log = hijackLog;88 console.warn = hijackLog;89 console.error = hijackLog;90});91afterEach(() => {92 console.log = originalLog;93 console.warn = originalWarn;94 console.error = originalError;95});96describe("the create command", () => {97 let tempDirs = new Set<string>();98 let originalCwd = process.cwd();99 beforeEach(() => {100 process.chdir(TEMP_DIR);101 jest.clearAllMocks();102 });103 afterEach(async () => {104 process.chdir(originalCwd);105 for (let dir of tempDirs) {106 await fse.remove(dir);107 }108 tempDirs = new Set<string>();109 });110 async function getProjectDir(name: string) {111 let tmpDir = path.join(TEMP_DIR, name);112 tempDirs.add(tmpDir);113 return tmpDir;114 }115 // this also tests sub directories116 it("works for examples in the remix repo", async () => {117 let projectDir = await getProjectDir("example");118 await run([119 "create",120 projectDir,121 "--template",122 "examples/basic",123 "--no-install",124 "--typescript",125 ]);126 expect(output.trim()).toBe(127 getSuccessMessage(path.join("<TEMP_DIR>", "example"))128 );129 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();130 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();131 });132 it("works for templates in the remix org", async () => {133 let projectDir = await getProjectDir("template");134 await run([135 "create",136 projectDir,137 "--template",138 "grunge-stack",139 "--no-install",140 "--typescript",141 ]);142 expect(output.trim()).toBe(143 getOptOutOfInstallMessage() +144 "\n\n" +145 getSuccessMessage(path.join("<TEMP_DIR>", "template"))146 );147 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();148 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();149 });150 it("works for GitHub username/repo combo", async () => {151 let projectDir = await getProjectDir("repo");152 await run([153 "create",154 projectDir,155 "--template",156 "remix-fake-tester-username/remix-fake-tester-repo",157 "--no-install",158 "--typescript",159 ]);160 expect(output.trim()).toBe(161 getOptOutOfInstallMessage() +162 "\n\n" +163 getSuccessMessage(path.join("<TEMP_DIR>", "repo"))164 );165 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();166 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();167 });168 it("fails for private GitHub username/repo combo without a token", async () => {169 let projectDir = await getProjectDir("repo");170 await expect(() =>171 run([172 "create",173 projectDir,174 "--template",175 "private-org/private-repo",176 "--no-install",177 "--typescript",178 ])179 ).rejects.toMatchInlineSnapshot(180 `[Error: 🚨 The template could not be verified. Please double check that the template is a valid GitHub repository and try again.]`181 );182 });183 it("succeeds for private GitHub username/repo combo with a valid token", async () => {184 let projectDir = await getProjectDir("repo");185 await run([186 "create",187 projectDir,188 "--template",189 "private-org/private-repo",190 "--no-install",191 "--typescript",192 "--token",193 "valid-token",194 ]);195 expect(output.trim()).toBe(196 getOptOutOfInstallMessage() +197 "\n\n" +198 getSuccessMessage(path.join("<TEMP_DIR>", "repo"))199 );200 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();201 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();202 });203 it("works for remote tarballs", async () => {204 let projectDir = await getProjectDir("remote-tarball");205 await run([206 "create",207 projectDir,208 "--template",209 "https://example.com/remix-stack.tar.gz",210 "--no-install",211 "--typescript",212 ]);213 expect(output.trim()).toBe(214 getOptOutOfInstallMessage() +215 "\n\n" +216 getSuccessMessage(path.join("<TEMP_DIR>", "remote-tarball"))217 );218 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();219 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();220 });221 it("fails for private github release tarballs", async () => {222 let projectDir = await getProjectDir("private-release-tarball");223 await expect(() =>224 run([225 "create",226 projectDir,227 "--template",228 "https://github.com/private-org/private-repo/releases/download/v0.0.1/stack.tar.gz",229 "--no-install",230 "--typescript",231 ])232 ).rejects.toMatchInlineSnapshot(233 `[Error: 🚨 The template file could not be verified. Please double check the URL and try again.]`234 );235 });236 it("succeeds for private github release tarballs when including token", async () => {237 let projectDir = await getProjectDir("private-release-tarball-with-token");238 await run([239 "create",240 projectDir,241 "--template",242 "https://example.com/remix-stack.tar.gz",243 "--no-install",244 "--typescript",245 "--token",246 "valid-token",247 ]);248 expect(output.trim()).toBe(249 getOptOutOfInstallMessage() +250 "\n\n" +251 getSuccessMessage(252 path.join("<TEMP_DIR>", "private-release-tarball-with-token")253 )254 );255 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();256 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();257 });258 it("works for different branches", async () => {259 let projectDir = await getProjectDir("diff-branch");260 await run([261 "create",262 projectDir,263 "--template",264 "https://github.com/fake-remix-tester/nested-dir/tree/dev/stack",265 "--no-install",266 "--typescript",267 ]);268 expect(output.trim()).toBe(269 getOptOutOfInstallMessage() +270 "\n\n" +271 getSuccessMessage(path.join("<TEMP_DIR>", "diff-branch"))272 );273 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();274 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();275 });276 it("works for a path to a tarball on disk", async () => {277 let projectDir = await getProjectDir("local-tarball");278 await run([279 "create",280 projectDir,281 "--template",282 path.join(__dirname, "fixtures", "arc.tar.gz"),283 "--no-install",284 "--typescript",285 ]);286 expect(output.trim()).toBe(287 getSuccessMessage(path.join("<TEMP_DIR>", "local-tarball"))288 );289 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();290 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();291 });292 it("works for a file URL to a tarball on disk", async () => {293 let projectDir = await getProjectDir("file-url-tarball");294 await run([295 "create",296 projectDir,297 "--template",298 pathToFileURL(path.join(__dirname, "fixtures", "arc.tar.gz")).toString(),299 "--no-install",300 "--typescript",301 ]);302 expect(output.trim()).toBe(303 getSuccessMessage(path.join("<TEMP_DIR>", "file-url-tarball"))304 );305 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();306 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();307 });308 it("converts a template to JavaScript", async () => {309 let projectDir = await getProjectDir("template-to-js");310 await run([311 "create",312 projectDir,313 "--template",314 "blues-stack",315 "--no-install",316 "--no-typescript",317 ]);318 expect(output.trim()).toBe(319 getOptOutOfInstallMessage() +320 "\n\n" +321 getSuccessMessage(path.join("<TEMP_DIR>", "template-to-js"))322 );323 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeFalsy();324 expect(fse.existsSync(path.join(projectDir, "app/root.jsx"))).toBeTruthy();325 expect(fse.existsSync(path.join(projectDir, "tsconfig.json"))).toBeFalsy();326 expect(fse.existsSync(path.join(projectDir, "jsconfig.json"))).toBeTruthy();327 });328 it("works for a file path to a directory on disk", async () => {329 let projectDir = await getProjectDir("local-directory");330 await run([331 "create",332 projectDir,333 "--template",334 path.join(__dirname, "fixtures/stack"),335 "--no-install",336 "--typescript",337 ]);338 expect(output.trim()).toBe(339 getOptOutOfInstallMessage() +340 "\n\n" +341 getSuccessMessage(path.join("<TEMP_DIR>", "local-directory"))342 );343 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();344 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();345 });346 it("works for a file URL to a directory on disk", async () => {347 let projectDir = await getProjectDir("file-url-directory");348 await run([349 "create",350 projectDir,351 "--template",352 pathToFileURL(path.join(__dirname, "fixtures/stack")).toString(),353 "--no-install",354 "--typescript",355 ]);356 expect(output.trim()).toBe(357 getOptOutOfInstallMessage() +358 "\n\n" +359 getSuccessMessage(path.join("<TEMP_DIR>", "file-url-directory"))360 );361 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();362 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();363 });364 it("prioritizes built-in templates when validating input", async () => {365 let projectDir = await getProjectDir("built-in-template");366 // create a local directory in our cwd with the same name as our chosen367 // template and give it a package.json so we can check it against the one in368 // our template369 let dupedDir = path.join(process.cwd(), "express");370 await fse.mkdir(dupedDir);371 await fse.writeFile(372 path.join(dupedDir, "package.json"),373 '{ "name": "dummy" }'374 );375 await run([376 "create",377 projectDir,378 "--template",379 "express",380 "--install",381 "--typescript",382 ]);383 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();384 let pkgJSON = JSON.parse(385 fse.readFileSync(path.join(projectDir, "package.json"), "utf-8")386 );387 expect(pkgJSON.name).not.toBe("dummy");388 });389 it("runs remix.init script when installing dependencies", async () => {390 let projectDir = await getProjectDir("remix-init-auto");391 await run([392 "create",393 projectDir,394 "--template",395 path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),396 "--install",397 "--typescript",398 ]);399 expect(output.trim()).toBe(400 "💿 Running remix.init script\n" +401 getSuccessMessage(path.join("<TEMP_DIR>", "remix-init-auto"))402 );403 expect(output).toContain(`💿 Running remix.init script`);404 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();405 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();406 expect(fse.existsSync(path.join(projectDir, "test.txt"))).toBeTruthy();407 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();408 });409 it("runs remix.init script when using index.ts", async () => {410 let projectDir = await getProjectDir("remix-init-ts");411 await run([412 "create",413 projectDir,414 "--template",415 path.join(__dirname, "fixtures", "stack-init-ts.tar.gz"),416 "--install",417 "--typescript",418 ]);419 expect(output).toContain(420 `Running init script on ${projectDir.replace(TEMP_DIR, "<TEMP_DIR>")}`421 );422 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();423 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();424 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();425 });426 it("runs remix.init script when using `remix init`", async () => {427 let projectDir = await getProjectDir("remix-init-manual");428 await run([429 "create",430 projectDir,431 "--template",432 path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),433 "--no-install",434 "--typescript",435 ]);436 expect(output.trim()).toBe(437 getOptOutOfInstallMessage() +438 "\n\n" +439 getSuccessMessage(path.join("<TEMP_DIR>", "remix-init-manual"))440 );441 output = "";442 process.chdir(projectDir);443 await run(["init"]);444 expect(output).toBe("");445 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();446 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();447 expect(fse.existsSync(path.join(projectDir, "test.txt"))).toBeTruthy();448 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();449 });450 it("It keeps the `remix.init` script when using the `--no-delete` flag", async () => {451 let projectDir = await getProjectDir("remix-init-manual");452 await run([453 "create",454 projectDir,455 "--template",456 path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),457 "--no-install",458 "--typescript",459 ]);460 expect(output.trim()).toBe(461 getOptOutOfInstallMessage() +462 "\n\n" +463 getSuccessMessage(path.join("<TEMP_DIR>", "remix-init-manual"))464 );465 output = "";466 process.chdir(projectDir);467 await run(["init", "--no-delete"]);468 expect(output).toBe("");469 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();470 });471 it("throws an error when invalid remix.init script when automatically ran", async () => {472 let projectDir = await getProjectDir("invalid-remix-init-manual");473 await expect(474 run([475 "create",476 projectDir,477 "--template",478 path.join(__dirname, "fixtures", "failing-remix-init.tar.gz"),479 "--install",480 "--typescript",481 ])482 ).rejects.toThrowError(`🚨 Oops, remix.init failed`);483 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();484 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();485 // we should keep remix.init around if the init script fails486 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();487 });488 it("throws an error when invalid remix.init script when manually ran", async () => {489 let projectDir = await getProjectDir("invalid-remix-init-manual");490 await run([491 "create",492 projectDir,493 "--template",494 path.join(__dirname, "fixtures", "failing-remix-init.tar.gz"),495 "--no-install",496 "--typescript",497 ]);498 expect(output.trim()).toBe(499 getOptOutOfInstallMessage() +500 "\n\n" +501 getSuccessMessage(path.join("<TEMP_DIR>", "invalid-remix-init-manual"))502 );503 process.chdir(projectDir);504 await expect(run(["init"])).rejects.toThrowError(505 `🚨 Oops, remix.init failed`506 );507 expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();508 expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();509 // we should keep remix.init around if the init script fails510 expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();511 });512 it("recognizes when Yarn was used to run the command", async () => {513 let originalUserAgent = process.env.npm_config_user_agent;514 process.env.npm_config_user_agent = yarnUserAgent;515 let projectDir = await getProjectDir("yarn-create");516 await run([517 "create",518 projectDir,519 "--template",520 path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),521 "--install",522 "--typescript",523 ]);524 expect(execSync).toBeCalledWith("yarn install", expect.anything());525 process.env.npm_config_user_agent = originalUserAgent;526 });527 it("recognizes when pnpm was used to run the command", async () => {528 let originalUserAgent = process.env.npm_config_user_agent;529 process.env.npm_config_user_agent = pnpmUserAgent;530 let projectDir = await getProjectDir("pnpm-create");531 await run([532 "create",533 projectDir,534 "--template",535 path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),536 "--install",537 "--typescript",538 ]);539 expect(execSync).toBeCalledWith("pnpm install", expect.anything());540 process.env.npm_config_user_agent = originalUserAgent;541 });542 it("prompts to run the install command for the preferred package manager", async () => {543 let originalUserAgent = process.env.npm_config_user_agent;544 process.env.npm_config_user_agent = pnpmUserAgent;545 let projectDir = await getProjectDir("pnpm-prompt-install");546 let mockPrompt = jest.mocked(inquirer.prompt);547 mockPrompt.mockImplementationOnce(() => {548 return Promise.resolve({549 install: false,550 }) as unknown as ReturnType<typeof inquirer.prompt>;551 });552 await run([553 "create",554 projectDir,555 "--template",556 "grunge-stack",557 "--typescript",558 ]);559 let mockPromptCalls = mockPrompt.mock.calls;560 let lastCallArgs = mockPromptCalls[mockPromptCalls.length - 1][0];561 let lastCallUnknown = lastCallArgs as Array<unknown>;562 expect(lastCallUnknown[lastCallUnknown.length - 1]).toHaveProperty(563 "message",564 "Do you want me to run `pnpm install`?"565 );566 process.env.npm_config_user_agent = originalUserAgent;567 });568 it("suggests to run the init command with the preferred package manager", async () => {569 let originalUserAgent = process.env.npm_config_user_agent;570 process.env.npm_config_user_agent = pnpmUserAgent;571 let projectDir = await getProjectDir("pnpm-suggest-install");572 let mockPrompt = jest.mocked(inquirer.prompt);573 mockPrompt.mockImplementationOnce(() => {574 return Promise.resolve({575 install: false,576 }) as unknown as ReturnType<typeof inquirer.prompt>;577 });578 await run([579 "create",580 projectDir,581 "--template",582 "grunge-stack",583 "--no-install",584 "--typescript",585 ]);586 expect(output).toContain(getOptOutOfInstallMessage("pnpm exec remix init"));587 process.env.npm_config_user_agent = originalUserAgent;588 });589 describe("errors", () => {590 it("identifies when a github repo is not accessible (403)", async () => {591 let projectDir = await getProjectDir("repo");592 await expect(async () => {593 try {594 let res = await run([595 "create",596 projectDir,597 "--template",598 "error-username/403",599 "--no-install",600 "--typescript",601 ]);602 return res;603 } catch (err) {604 throw err;605 }606 }).rejects.toMatchInlineSnapshot(607 `[Error: 🚨 The template could not be verified because you do not have access to the repository. Please double check the access rights of this repo and try again.]`608 );609 });610 it("identifies when a github repo does not exist (404)", async () => {611 let projectDir = await getProjectDir("repo");612 await expect(() =>613 run([614 "create",615 projectDir,616 "--template",617 "error-username/404",618 "--no-install",619 "--typescript",620 ])621 ).rejects.toMatchInlineSnapshot(622 `[Error: 🚨 The template could not be verified. Please double check that the template is a valid GitHub repository and try again.]`623 );624 });625 it("identifies when something unknown goes wrong with the repo request (4xx)", async () => {626 let projectDir = await getProjectDir("repo");627 await expect(() =>628 run([629 "create",630 projectDir,631 "--template",632 "error-username/400",633 "--no-install",634 "--typescript",635 ])636 ).rejects.toMatchInlineSnapshot(637 `[Error: 🚨 The template could not be verified. The server returned a response with a 400 status. Please double check that the template is a valid GitHub repository and try again.]`638 );639 });640 it("identifies when a remote tarball does not exist (404)", async () => {641 let projectDir = await getProjectDir("remote-tarball");642 await expect(() =>643 run([644 "create",645 projectDir,646 "--template",647 "https://example.com/error/404/remix-stack.tar.gz",648 "--no-install",649 "--typescript",650 ])651 ).rejects.toMatchInlineSnapshot(652 `[Error: 🚨 The template file could not be verified. Please double check the URL and try again.]`653 );654 });655 it("identifies when a remote tarball does not exist (4xx)", async () => {656 let projectDir = await getProjectDir("remote-tarball");657 await expect(() =>658 run([659 "create",660 projectDir,661 "--template",662 "https://example.com/error/400/remix-stack.tar.gz",663 "--no-install",664 "--typescript",665 ])666 ).rejects.toMatchInlineSnapshot(667 `[Error: 🚨 The template file could not be verified. The server returned a response with a 400 status. Please double check the URL and try again.]`668 );669 });670 it("allows creating an app in a dir if it's empty", async () => {671 let projectDir = await getProjectDir("other-empty-dir");672 await run([673 "create",674 projectDir,675 "--template",676 "grunge-stack",677 "--no-install",678 "--typescript",679 ]);680 expect(681 fse.existsSync(path.join(projectDir, "package.json"))682 ).toBeTruthy();683 });684 it("doesn't allow creating an app in a dir if it's not empty", async () => {685 let projectDir = await getProjectDir("not-empty-dir");686 fse.mkdirSync(projectDir);687 fse.createFileSync(path.join(projectDir, "some-file.txt"));688 await expect(() =>689 run([690 "create",691 projectDir,692 "--template",693 "grunge-stack",694 "--no-install",695 "--typescript",696 ])697 ).rejects.toMatchInlineSnapshot(698 `[Error: 🚨 The project directory must be empty to create a new project. Please clear the contents of the directory or choose a different path.]`699 );700 });701 it("allows creating an app in the current dir if it's empty", async () => {702 let projectDir = await getProjectDir("empty-dir");703 let cwd = process.cwd();704 fse.mkdirSync(projectDir);705 process.chdir(projectDir);706 await run([707 "create",708 ".",709 "--template",710 "grunge-stack",711 "--no-install",712 "--typescript",713 ]);714 process.chdir(cwd);715 expect(716 fse.existsSync(path.join(projectDir, "package.json"))717 ).toBeTruthy();718 });719 it("doesn't allow creating an app in the current dir if it's not empty", async () => {720 let projectDir = await getProjectDir("not-empty-dir");721 let cwd = process.cwd();722 fse.mkdirSync(projectDir);723 fse.createFileSync(path.join(projectDir, "some-file.txt"));724 process.chdir(projectDir);725 await expect(() =>726 run([727 "create",728 ".",729 "--template",730 "grunge-stack",731 "--no-install",732 "--typescript",733 ])734 ).rejects.toMatchInlineSnapshot(735 `[Error: 🚨 The project directory must be empty to create a new project. Please clear the contents of the directory or choose a different path.]`736 );737 process.chdir(cwd);738 });739 });740});741function getSuccessMessage(projectDirectory: string) {742 return `💿 That's it! \`cd\` into "${projectDirectory}" and check the README for development and deploy instructions!`;743}744const getOptOutOfInstallMessage = (command = "yarn remix init") =>745 "💿 You've opted out of installing dependencies so we won't run the " +746 path.join("remix.init", "index.js") +747 " script for you just yet. Once you've installed dependencies, you can run " +748 `it manually with \`${command}\``;749/*750eslint751 @typescript-eslint/consistent-type-imports: "off",...

Full Screen

Full Screen

AndroidProject.js

Source:AndroidProject.js Github

copy

Full Screen

1/**2 Licensed to the Apache Software Foundation (ASF) under one3 or more contributor license agreements. See the NOTICE file4 distributed with this work for additional information5 regarding copyright ownership. The ASF licenses this file6 to you under the Apache License, Version 2.0 (the7 "License"); you may not use this file except in compliance8 with the License. You may obtain a copy of the License at9 http://www.apache.org/licenses/LICENSE-2.010 Unless required by applicable law or agreed to in writing,11 software distributed under the License is distributed on an12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13 KIND, either express or implied. See the License for the14 specific language governing permissions and limitations15 under the License.16*/17var fs = require('fs');18var path = require('path');19var properties_parser = require('properties-parser');20var AndroidManifest = require('./AndroidManifest');21var AndroidStudio = require('./AndroidStudio');22var pluginHandlers = require('./pluginHandlers');23var projectFileCache = {};24function addToPropertyList (projectProperties, key, value) {25 var i = 1;26 while (projectProperties.get(key + '.' + i)) { i++; }27 projectProperties.set(key + '.' + i, value);28 projectProperties.dirty = true;29}30function removeFromPropertyList (projectProperties, key, value) {31 var i = 1;32 var currentValue;33 while ((currentValue = projectProperties.get(key + '.' + i))) {34 if (currentValue === value) {35 while ((currentValue = projectProperties.get(key + '.' + (i + 1)))) {36 projectProperties.set(key + '.' + i, currentValue);37 i++;38 }39 projectProperties.set(key + '.' + i);40 break;41 }42 i++;43 }44 projectProperties.dirty = true;45}46function getRelativeLibraryPath (parentDir, subDir) {47 var libraryPath = path.relative(parentDir, subDir);48 return (path.sep === '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;49}50function AndroidProject (projectDir) {51 this._propertiesEditors = {};52 this._subProjectDirs = {};53 this._dirty = false;54 this.projectDir = projectDir;55 this.platformWww = path.join(this.projectDir, 'platform_www');56 this.www = path.join(this.projectDir, 'assets/www');57 if (AndroidStudio.isAndroidStudioProject(projectDir) === true) {58 this.www = path.join(this.projectDir, 'app/src/main/assets/www');59 }60}61AndroidProject.getProjectFile = function (projectDir) {62 if (!projectFileCache[projectDir]) {63 projectFileCache[projectDir] = new AndroidProject(projectDir);64 }65 return projectFileCache[projectDir];66};67AndroidProject.purgeCache = function (projectDir) {68 if (projectDir) {69 delete projectFileCache[projectDir];70 } else {71 projectFileCache = {};72 }73};74/**75 * Reads the package name out of the Android Manifest file76 *77 * @param {String} projectDir The absolute path to the directory containing the project78 *79 * @return {String} The name of the package80 */81AndroidProject.prototype.getPackageName = function () {82 var manifestPath = path.join(this.projectDir, 'AndroidManifest.xml');83 if (AndroidStudio.isAndroidStudioProject(this.projectDir) === true) {84 manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');85 }86 return new AndroidManifest(manifestPath).getPackageId();87};88AndroidProject.prototype.getCustomSubprojectRelativeDir = function (plugin_id, src) {89 // All custom subprojects are prefixed with the last portion of the package id.90 // This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.91 var packageName = this.getPackageName();92 var lastDotIndex = packageName.lastIndexOf('.');93 var prefix = packageName.substring(lastDotIndex + 1);94 var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));95 return subRelativeDir;96};97AndroidProject.prototype.addSubProject = function (parentDir, subDir) {98 var parentProjectFile = path.resolve(parentDir, 'project.properties');99 var subProjectFile = path.resolve(subDir, 'project.properties');100 var parentProperties = this._getPropertiesFile(parentProjectFile);101 // TODO: Setting the target needs to happen only for pre-3.7.0 projects102 if (fs.existsSync(subProjectFile)) {103 var subProperties = this._getPropertiesFile(subProjectFile);104 subProperties.set('target', parentProperties.get('target'));105 subProperties.dirty = true;106 this._subProjectDirs[subDir] = true;107 }108 addToPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));109 this._dirty = true;110};111AndroidProject.prototype.removeSubProject = function (parentDir, subDir) {112 var parentProjectFile = path.resolve(parentDir, 'project.properties');113 var parentProperties = this._getPropertiesFile(parentProjectFile);114 removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));115 delete this._subProjectDirs[subDir];116 this._dirty = true;117};118AndroidProject.prototype.addGradleReference = function (parentDir, subDir) {119 var parentProjectFile = path.resolve(parentDir, 'project.properties');120 var parentProperties = this._getPropertiesFile(parentProjectFile);121 addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));122 this._dirty = true;123};124AndroidProject.prototype.removeGradleReference = function (parentDir, subDir) {125 var parentProjectFile = path.resolve(parentDir, 'project.properties');126 var parentProperties = this._getPropertiesFile(parentProjectFile);127 removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));128 this._dirty = true;129};130AndroidProject.prototype.addSystemLibrary = function (parentDir, value) {131 var parentProjectFile = path.resolve(parentDir, 'project.properties');132 var parentProperties = this._getPropertiesFile(parentProjectFile);133 addToPropertyList(parentProperties, 'cordova.system.library', value);134 this._dirty = true;135};136AndroidProject.prototype.removeSystemLibrary = function (parentDir, value) {137 var parentProjectFile = path.resolve(parentDir, 'project.properties');138 var parentProperties = this._getPropertiesFile(parentProjectFile);139 removeFromPropertyList(parentProperties, 'cordova.system.library', value);140 this._dirty = true;141};142AndroidProject.prototype.write = function () {143 if (!this._dirty) {144 return;145 }146 this._dirty = false;147 for (var filename in this._propertiesEditors) {148 var editor = this._propertiesEditors[filename];149 if (editor.dirty) {150 fs.writeFileSync(filename, editor.toString());151 editor.dirty = false;152 }153 }154};155AndroidProject.prototype._getPropertiesFile = function (filename) {156 if (!this._propertiesEditors[filename]) {157 if (fs.existsSync(filename)) {158 this._propertiesEditors[filename] = properties_parser.createEditor(filename);159 } else {160 this._propertiesEditors[filename] = properties_parser.createEditor();161 }162 }163 return this._propertiesEditors[filename];164};165AndroidProject.prototype.getInstaller = function (type) {166 return pluginHandlers.getInstaller(type);167};168AndroidProject.prototype.getUninstaller = function (type) {169 return pluginHandlers.getUninstaller(type);170};171/*172 * This checks if an Android project is clean or has old build artifacts173 */174AndroidProject.prototype.isClean = function () {175 var build_path = path.join(this.projectDir, 'build');176 // If the build directory doesn't exist, it's clean177 return !(fs.existsSync(build_path));178};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2console.log(storybookRoot.projectDir());3const storybookRoot = require('storybook-root');4console.log(storybookRoot.storybookDir());5const storybookRoot = require('storybook-root');6console.log(storybookRoot.storybookDir());7const storybookRoot = require('storybook-root');8console.log(storybookRoot.storybookDir());9const storybookRoot = require('storybook-root');10console.log(storybookRoot.storybookDir());11const storybookRoot = require('storybook-root');12console.log(storybookRoot.storybookDir());13const storybookRoot = require('storybook-root');14console.log(storybookRoot.storybookDir());15const storybookRoot = require('storybook-root');16console.log(storybookRoot.storybookDir());17const storybookRoot = require('storybook-root');18console.log(storybookRoot.storybookDir());19const storybookRoot = require('storybook-root');20console.log(storybookRoot.storybookDir());21const storybookRoot = require('storybook-root');22console.log(storybookRoot.storybookDir());23const storybookRoot = require('storybook-root');24console.log(storybookRoot.storybookDir());25const storybookRoot = require('storybook-root');26console.log(storybookRoot.storybookDir());27const storybookRoot = require('storybook-root');28console.log(storybookRoot.storybookDir());29const storybookRoot = require('storybook-root');30console.log(storybookRoot.storybookDir());

Full Screen

Using AI Code Generation

copy

Full Screen

1const projectDir = require('storybook-root-require').projectDir;2const path = require('path');3module.exports = {4 webpackFinal: async (config, { configType }) => {5 config.resolve.alias['@'] = projectDir('./src');6 config.resolve.alias['~'] = projectDir('./');7 config.resolve.alias['@storybook/vue'] = path.resolve(8 projectDir('./node_modules/@storybook/vue'),9 );10 return config;11 },12};13import { addDecorator, addParameters } from '@storybook/vue';14import { withA11y } from '@storybook/addon-a11y';15import { withKnobs } from '@storybook/addon-knobs';16import { withOptions } from '@storybook/addon-options';17import { withInfo } from 'storybook-addon-vue-info';18import { withContexts } from '@storybook/addon-contexts/vue';19import { contexts } from './contexts';20import { withTests } from '@storybook/addon-jest';21import results from '../.jest-test-results.json';22addDecorator(withA11y);23addDecorator(withKnobs);24addDecorator(withInfo);25addDecorator(withTests({ results }));26addDecorator(withContexts(contexts));27import { contexts } from '@storybook/addon-contexts';28import { themes } from '@storybook/theming';29 {30 {31 props: { theme: themes.normal },32 },33 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = require('storybook-root');2const projectDir = root.projectDir();3const {projectDir} = require('storybook-root');4import {projectDir} from 'storybook-root';5import root from 'storybook-root';6const projectDir = root.projectDir();7projectDir()8projectDir()9storybookDir()10storybookDir()11storybookConfig()12storybookConfig()13storybookStaticDir()

Full Screen

Using AI Code Generation

copy

Full Screen

1import { projectDir } from 'storybook-root';2module.exports.projectDir = () => {3 return __dirname;4};5import { projectDir } from 'storybook-root';6module.exports.projectDir = () => {7 return __dirname;8};9import { projectDir } from 'storybook-root';10module.exports.projectDir = () => {11 return __dirname;12};13import { projectDir } from 'storybook-root';14module.exports.projectDir = () => {15 return __dirname;16};17import { projectDir } from 'storybook-root';18module.exports.projectDir = () => {19 return __dirname;20};21import { projectDir } from 'storybook-root';22module.exports.projectDir = () => {23 return __dirname;24};25import { projectDir } from 'storybook-root';26module.exports.projectDir = () => {27 return __dirname;28};29import { projectDir } from 'storybook-root';30module.exports.projectDir = () => {31 return __dirname;32};33import { projectDir } from 'storybook-root';34module.exports.projectDir = () => {35 return __dirname;36};37import { projectDir } from 'storybook-root';38module.exports.projectDir = () => {39 return __dirname;40};

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = require('storybook-root-require');2console.log(root.projectDir('src'));3const root = require('storybook-root-require');4console.log(root.projectDir('src'));5const root = require('storybook-root-require');6console.log(root.projectDir('src'));7const root = require('storybook-root-require');8console.log(root.projectDir('src'));9const root = require('storybook-root-require');10console.log(root.projectDir('src'));11const root = require('storybook-root-require');12console.log(root.projectDir('src'));13const root = require('storybook-root-require');14console.log(root.projectDir('src'));15const root = require('storybook-root-require');16console.log(root.projectDir('src'));17const root = require('storybook-root-require');18console.log(root.projectDir('src'));19const root = require('storybook-root-require');20console.log(root.projectDir('src'));21const root = require('storybook-root-require');22console.log(root.projectDir('src

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const rootDir = require('storybook-root');3const config = {4 projectDir: rootDir.projectDir(),5};6module.exports = config;7const path = require('path');8const rootDir = require('storybook-root');9const config = {10 storybookDir: rootDir.storybookDir(),11};12module.exports = config;13const path = require('path');14const rootDir = require('storybook-root');15const config = {16 projectDir: rootDir.projectDir(),17 storybookDir: rootDir.storybookDir(),18};19module.exports = config;20MIT © [Mukundan S](

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful