|
1 | 1 | import type { CodeLanguageEnum, NexusGenEnums, NexusGenObjects } from '@packages/graphql/src/gen/nxs.gen' |
2 | 2 | import { CODE_LANGUAGES } from '@packages/types' |
3 | | -import { detect, WIZARD_FRAMEWORKS, WIZARD_BUNDLERS } from '@packages/scaffold-config' |
| 3 | +import { detect, WIZARD_FRAMEWORKS, WIZARD_BUNDLERS, commandsFileBody, supportFileComponent, supportFileE2E } from '@packages/scaffold-config' |
4 | 4 | import assert from 'assert' |
5 | 5 | import dedent from 'dedent' |
6 | 6 | import path from 'path' |
@@ -206,7 +206,18 @@ export class WizardActions { |
206 | 206 | // @ts-ignore |
207 | 207 | await this.ctx.fs.mkdir(supportDir, { recursive: true }) |
208 | 208 |
|
209 | | - const fileContent = fileName === 'commands' ? this.commandsFileBody(language) : this.supportFileBody(fileName, language) |
| 209 | + let fileContent: string | undefined |
| 210 | + |
| 211 | + if (fileName === 'commands') { |
| 212 | + fileContent = commandsFileBody(language) |
| 213 | + } else if (fileName === 'e2e') { |
| 214 | + fileContent = supportFileE2E(language) |
| 215 | + } else if (fileName === 'component') { |
| 216 | + assert(this.ctx.coreData.wizard.chosenFramework) |
| 217 | + fileContent = supportFileComponent(language, this.ctx.coreData.wizard.chosenFramework) |
| 218 | + } |
| 219 | + |
| 220 | + assert(fileContent) |
210 | 221 |
|
211 | 222 | await this.scaffoldFile(supportFile, fileContent, 'Scaffold default support file') |
212 | 223 |
|
@@ -388,79 +399,8 @@ export class WizardActions { |
388 | 399 | private ensureDir (type: 'component' | 'e2e' | 'fixtures') { |
389 | 400 | return this.ctx.fs.ensureDir(path.join(this.projectRoot, 'cypress', type)) |
390 | 401 | } |
391 | | - |
392 | | - private supportFileBody (fileName: 'e2e' | 'component', language: CodeLanguageEnum) { |
393 | | - return dedent` |
394 | | - // *********************************************************** |
395 | | - // This example support/${fileName}.${language} is processed and |
396 | | - // loaded automatically before your test files. |
397 | | - // |
398 | | - // This is a great place to put global configuration and |
399 | | - // behavior that modifies Cypress. |
400 | | - // |
401 | | - // You can change the location of this file or turn off |
402 | | - // automatically serving support files with the |
403 | | - // 'supportFile' configuration option. |
404 | | - // |
405 | | - // You can read more here: |
406 | | - // https://on.cypress.io/configuration |
407 | | - // *********************************************************** |
408 | | - |
409 | | - // Import commands.js using ES2015 syntax: |
410 | | - import './commands' |
411 | | - |
412 | | - // Alternatively you can use CommonJS syntax: |
413 | | - // require('./commands') |
414 | | - ` |
415 | | - } |
416 | | - |
417 | | - private commandsFileBody (language: CodeLanguageEnum) { |
418 | | - return dedent` |
419 | | - ${language === 'ts' ? '/// <reference types="cypress" />' : ''} |
420 | | - // *********************************************** |
421 | | - // This example commands.${language} shows you how to |
422 | | - // create various custom commands and overwrite |
423 | | - // existing commands. |
424 | | - // |
425 | | - // For more comprehensive examples of custom |
426 | | - // commands please read more here: |
427 | | - // https://on.cypress.io/custom-commands |
428 | | - // *********************************************** |
429 | | - // |
430 | | - // |
431 | | - // -- This is a parent command -- |
432 | | - // Cypress.Commands.add('login', (email, password) => { ... }) |
433 | | - // |
434 | | - // |
435 | | - // -- This is a child command -- |
436 | | - // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) |
437 | | - // |
438 | | - // |
439 | | - // -- This is a dual command -- |
440 | | - // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) |
441 | | - // |
442 | | - // |
443 | | - // -- This will overwrite an existing command -- |
444 | | - // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
445 | | - ${language === 'ts' ? COMMAND_TYPES : ''} |
446 | | - ` |
447 | | - } |
448 | 402 | } |
449 | 403 |
|
450 | | -const COMMAND_TYPES = dedent` |
451 | | -// |
452 | | -// declare global { |
453 | | -// namespace Cypress { |
454 | | -// interface Chainable { |
455 | | -// login(email: string, password: string): Chainable<void> |
456 | | -// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> |
457 | | -// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> |
458 | | -// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> |
459 | | -// } |
460 | | -// } |
461 | | -// } |
462 | | -` |
463 | | - |
464 | 404 | const E2E_SCAFFOLD_BODY = dedent` |
465 | 405 | e2e: { |
466 | 406 | setupNodeEvents(on, config) { |
|
0 commit comments