@sprucelabs/spruce-cli 14.28.7 → 14.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/build/__tests__/behavioral/SettingLogTransportsInASkill.test.js +13 -9
  3. package/build/__tests__/behavioral/SettingLogTransportsInASkill.test.js.map +1 -1
  4. package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.d.ts +1 -1
  5. package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.js +24 -14
  6. package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.js.map +1 -1
  7. package/build/__tests__/behavioral/TestingDataStores.test.js +15 -11
  8. package/build/__tests__/behavioral/TestingDataStores.test.js.map +1 -1
  9. package/build/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.js +3 -1
  10. package/build/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.js.map +1 -1
  11. package/build/__tests__/behavioral/events/CreatingAListener.test.d.ts +2 -0
  12. package/build/__tests__/behavioral/events/CreatingAListener.test.js +157 -81
  13. package/build/__tests__/behavioral/events/CreatingAListener.test.js.map +1 -1
  14. package/build/__tests__/behavioral/events/KeepingListenersInSync.test.d.ts +7 -0
  15. package/build/__tests__/behavioral/events/KeepingListenersInSync.test.js +171 -0
  16. package/build/__tests__/behavioral/events/KeepingListenersInSync.test.js.map +1 -0
  17. package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.d.ts +1 -0
  18. package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.js +53 -21
  19. package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.js.map +1 -1
  20. package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.d.ts +5 -0
  21. package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.js +137 -0
  22. package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.js.map +1 -0
  23. package/build/__tests__/behavioral/stores/CreatingADataStore.test.js +4 -1
  24. package/build/__tests__/behavioral/stores/CreatingADataStore.test.js.map +1 -1
  25. package/build/__tests__/behavioral/stores/KeepingDataStoresInSync.test.d.ts +4 -1
  26. package/build/__tests__/behavioral/stores/KeepingDataStoresInSync.test.js +136 -47
  27. package/build/__tests__/behavioral/stores/KeepingDataStoresInSync.test.js.map +1 -1
  28. package/build/__tests__/behavioral/tests/CreatingATest.test.js +14 -10
  29. package/build/__tests__/behavioral/tests/CreatingATest.test.js.map +1 -1
  30. package/build/__tests__/behavioral/views/TestingViewControllers.test.d.ts +1 -0
  31. package/build/__tests__/behavioral/views/TestingViewControllers.test.js +67 -35
  32. package/build/__tests__/behavioral/views/TestingViewControllers.test.js.map +1 -1
  33. package/build/__tests__/implementation/AuthService.test.d.ts +1 -0
  34. package/build/__tests__/implementation/AuthService.test.js +8 -0
  35. package/build/__tests__/implementation/AuthService.test.js.map +1 -1
  36. package/build/__tests__/implementation/EventStore.test.js +3 -1
  37. package/build/__tests__/implementation/EventStore.test.js.map +1 -1
  38. package/build/__tests__/implementation/LintService.test.d.ts +5 -0
  39. package/build/__tests__/implementation/LintService.test.js +130 -0
  40. package/build/__tests__/implementation/LintService.test.js.map +1 -0
  41. package/build/__tests__/implementation/StoreFeature.test.d.ts +4 -0
  42. package/build/__tests__/implementation/StoreFeature.test.js +132 -0
  43. package/build/__tests__/implementation/StoreFeature.test.js.map +1 -0
  44. package/build/errors/SpruceError.js +8 -4
  45. package/build/errors/SpruceError.js.map +1 -1
  46. package/build/features/event/EventFeature.d.ts +2 -2
  47. package/build/features/event/EventFeature.js +53 -13
  48. package/build/features/event/EventFeature.js.map +1 -1
  49. package/build/features/event/actions/ListenAction.d.ts +1 -0
  50. package/build/features/event/actions/ListenAction.js +60 -31
  51. package/build/features/event/actions/ListenAction.js.map +1 -1
  52. package/build/features/event/actions/SyncListenersAction.d.ts +15 -0
  53. package/build/features/event/actions/SyncListenersAction.js +115 -0
  54. package/build/features/event/actions/SyncListenersAction.js.map +1 -0
  55. package/build/features/event/builders/ListenerTemplateItemBuilder.d.ts +8 -0
  56. package/build/features/event/builders/ListenerTemplateItemBuilder.js +65 -0
  57. package/build/features/event/builders/ListenerTemplateItemBuilder.js.map +1 -0
  58. package/build/features/event/stores/EventStore.js +2 -2
  59. package/build/features/event/stores/EventStore.js.map +1 -1
  60. package/build/features/event/stores/ListenerStore.d.ts +9 -0
  61. package/build/features/event/stores/ListenerStore.js +122 -0
  62. package/build/features/event/stores/ListenerStore.js.map +1 -0
  63. package/build/features/event/writers/EventWriter.d.ts +4 -1
  64. package/build/features/event/writers/EventWriter.js +42 -8
  65. package/build/features/event/writers/EventWriter.js.map +1 -1
  66. package/build/features/node/NodeFeature.js +1 -1
  67. package/build/features/node/NodeFeature.js.map +1 -1
  68. package/build/features/skill/SkillFeature.js +1 -1
  69. package/build/features/skill/SkillFeature.js.map +1 -1
  70. package/build/features/skill/stores/SkillStore.js +4 -8
  71. package/build/features/skill/stores/SkillStore.js.map +1 -1
  72. package/build/features/store/StoreFeature.d.ts +1 -1
  73. package/build/features/store/StoreFeature.js +16 -11
  74. package/build/features/store/StoreFeature.js.map +1 -1
  75. package/build/services/AuthService.d.ts +4 -1
  76. package/build/services/AuthService.js +15 -4
  77. package/build/services/AuthService.js.map +1 -1
  78. package/build/services/GameService.js +14 -10
  79. package/build/services/GameService.js.map +1 -1
  80. package/build/services/LintService.d.ts +5 -2
  81. package/build/services/LintService.js +137 -92
  82. package/build/services/LintService.js.map +1 -1
  83. package/build/services/ServiceFactory.js +9 -3
  84. package/build/services/ServiceFactory.js.map +1 -1
  85. package/build/stores/StoreFactory.d.ts +2 -0
  86. package/build/stores/StoreFactory.js +4 -1
  87. package/build/stores/StoreFactory.js.map +1 -1
  88. package/build/tests/AbstractCliTest.js +3 -3
  89. package/build/tests/AbstractCliTest.js.map +1 -1
  90. package/build/writers/AbstractWriter.d.ts +0 -3
  91. package/build/writers/AbstractWriter.js +2 -18
  92. package/build/writers/AbstractWriter.js.map +1 -1
  93. package/package.json +11 -9
  94. package/src/__tests__/behavioral/SettingLogTransportsInASkill.test.ts +2 -0
  95. package/src/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.ts +10 -5
  96. package/src/__tests__/behavioral/TestingDataStores.test.ts +2 -0
  97. package/src/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.ts +1 -0
  98. package/src/__tests__/behavioral/events/CreatingAListener.test.ts +28 -9
  99. package/src/__tests__/behavioral/events/KeepingListenersInSync.test.ts +47 -0
  100. package/src/__tests__/behavioral/events/SkillEmitsBootEvents.test.ts +6 -0
  101. package/src/__tests__/behavioral/skill/UpgradingWithListeners.test.ts +59 -0
  102. package/src/__tests__/behavioral/stores/CreatingADataStore.test.ts +1 -0
  103. package/src/__tests__/behavioral/stores/KeepingDataStoresInSync.test.ts +35 -6
  104. package/src/__tests__/behavioral/tests/CreatingATest.test.ts +2 -0
  105. package/src/__tests__/behavioral/views/TestingViewControllers.test.ts +6 -0
  106. package/src/__tests__/implementation/AuthService.test.ts +6 -0
  107. package/src/__tests__/implementation/EventStore.test.ts +1 -0
  108. package/src/__tests__/implementation/LintService.test.ts +34 -0
  109. package/src/__tests__/implementation/StoreFeature.test.ts +40 -0
  110. package/src/errors/SpruceError.ts +9 -5
  111. package/src/features/event/EventFeature.ts +21 -4
  112. package/src/features/event/actions/ListenAction.ts +9 -3
  113. package/src/features/event/actions/SyncListenersAction.ts +38 -0
  114. package/src/features/event/builders/ListenerTemplateItemBuilder.ts +27 -0
  115. package/src/features/event/stores/EventStore.ts +1 -1
  116. package/src/features/event/stores/ListenerStore.ts +32 -0
  117. package/src/features/event/writers/EventWriter.ts +19 -0
  118. package/src/features/node/NodeFeature.ts +2 -1
  119. package/src/features/skill/SkillFeature.ts +1 -1
  120. package/src/features/skill/stores/SkillStore.ts +4 -3
  121. package/src/features/store/StoreFeature.ts +7 -4
  122. package/src/services/AuthService.ts +15 -5
  123. package/src/services/GameService.ts +1 -0
  124. package/src/services/LintService.ts +34 -5
  125. package/src/services/ServiceFactory.ts +8 -3
  126. package/src/stores/StoreFactory.ts +3 -0
  127. package/src/tests/AbstractCliTest.ts +2 -2
  128. package/src/writers/AbstractWriter.ts +2 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/writers/AbstractWriter.ts"],"names":["AbstractWriter","options","templates","ui","term","upgradeMode","fileDescriptions","linter","settings","file","isLintingEnabled","startLoading","pathUtil","basename","fix","context","destinationDir","filesToWrite","filesToSkip","shouldConfirmBeforeWriting","firstFileWriteMessage","hasShownFirstWriteMessage","directoryTemplate","kind","code","files","results","generated","shouldWrite","indexOf","filename","shouldSkip","writeFileIfChangedMixinResults","join","relativePath","contents","destination","description","cwd","myResults","desc","name","action","diskUtil","isDir","Error","fileDescription","getFileDescription","doesFileExist","write","confirmPromptOnFirstWrite","stopLoading","confirm","writeFile","isFileDifferent","shouldOverwriteIfChanged","cleanedName","cleanFilename","skipped","get","isAlwaysSkipped","shouldAskForOverwrite","renderLine","prompt","type","label","choices","value","FILE_ACTION_OVERWRITE","FILE_ACTION_SKIP","FILE_ACTION_ALWAYS_SKIP","answer","push","set","replace","path","relativeFile","sep","substr","shouldOverwriteWhenChanged","lower","toLowerCase","d","search","undefined","dirOrFile","fallbackFileName","doesDirExist","fs","lstatSync","isDirectory","extname","length","resolvePath"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;IA8B8BA,c;AAY7B,0BAAmBC,OAAnB,EAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+DAPG,EAOH;AAAA,yEANN,IAMM;AAAA;AAAA,wEAHP,KAGO;AAAA;AAC1C,SAAKC,SAAL,GAAiBD,OAAO,CAACC,SAAzB;AACA,SAAKC,EAAL,GAAUF,OAAO,CAACG,IAAlB;AACA,SAAKC,WAAL,GAAmBJ,OAAO,CAACI,WAA3B;AACA,SAAKC,gBAAL,GAAwBL,OAAO,CAACK,gBAAhC;AACA,SAAKC,MAAL,GAAcN,OAA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kC;;AAC5C,cAAIF,KAAK,CAACG,MAAN,CAAaD,CAAC,CAACP,IAAF,CAAOM,WAAP,EAAb,IAAqC,CAAC,CAA1C,EAA6C;AAC5C,mBAAOC,CAAP;AACA;AACD;AAN2E;AAAA;AAAA;AAAA;AAAA;;AAQ5E,aAAOE,SAAP;AACA;;;WAED,iCAAgC;AAC/B,UACC,KAAKjE,0BAAL,IACA,KAAKd,WAAL,KAAqB,eAFtB,EAGE;AACD,eAAO,IAAP;AACA;;AAED,aAAO,KAAP;AACA;;;WAED,qCACCgF,SADD,EAECC,gBAFD,EAGE;AACD,UAAM1C,KAAK,GACVD,2BAAS4C,YAAT,CAAsBF,SAAtB,KACAG,eAAGC,SAAH,CAAaJ,SAAb,EAAwBK,WAAxB,EADA,IAEA9E,iBAAS+E,OAAT,CAAiBN,SAAjB,EAA4BO,MAA5B,KAAuC,CAHxC;AAIA,aAAOhD,KAAK,GAAGD,2BAASkD,WAAT,CAAqBR,SAArB,EAAgCC,gBAAhC,CAAH,GAAuDD,SAAnE;AACA;;;WApND,0BAA+B;AAC9B,WAAK3E,gBAAL,GAAwB,KAAxB;AACA;;;WAED,yBAA8B;AAC7B,WAAKA,gBAAL,GAAwB,IAAxB;AACA;;;;;;iCAlC4BV,c,sBAOK,I","sourcesContent":["import fs from 'fs'\nimport pathUtil from 'path'\nimport { diskUtil, SettingsService } from '@sprucelabs/spruce-skill-utils'\nimport { DirectoryTemplateCode, Templates } from '@sprucelabs/spruce-templates'\nimport {\n\tFILE_ACTION_ALWAYS_SKIP,\n\tFILE_ACTION_OVERWRITE,\n\tFILE_ACTION_SKIP,\n} from '../constants'\nimport LintService from '../services/LintService'\nimport { FileDescription, GeneratedFile, UpgradeMode } from '../types/cli.types'\nimport { GraphicsInterface } from '../types/cli.types'\n\nexport type WriteResults = GeneratedFile[]\n\nexport interface WriterOptions {\n\ttemplates: Templates\n\tterm: GraphicsInterface\n\tupgradeMode?: UpgradeMode\n\tfileDescriptions: FileDescription[]\n\tlinter?: LintService\n\tsettings: SettingsService\n}\n\nexport interface WriteDirectoryTemplateOptions {\n\tdestinationDir: string\n\tcode: DirectoryTemplateCode\n\tfilesToWrite?: string[]\n\tfilesToSkip?: string[]\n\tcontext: any\n\tshouldConfirmBeforeWriting?: boolean\n\tfirstFileWriteMessage?: string\n}\n\nexport default abstract class AbstractWriter {\n\tprotected templates: Templates\n\tprotected ui: GraphicsInterface\n\tprivate linter?: LintService\n\tprivate upgradeMode: UpgradeMode\n\tprivate fileDescriptions: FileDescription[] = []\n\tprivate shouldConfirmBeforeWriting = true\n\tprivate static isLintingEnabled = true\n\tprivate firstFileWriteMessage?: string\n\tprivate hasShownFirstWriteMessage = false\n\tprivate settings: SettingsService<string>\n\n\tpublic constructor(options: WriterOptions) {\n\t\tthis.templates = options.templates\n\t\tthis.ui = options.term\n\t\tthis.upgradeMode = options.upgradeMode\n\t\tthis.fileDescriptions = options.fileDescriptions\n\t\tthis.linter = options.linter\n\t\tthis.settings = options.settings\n\t}\n\n\tprotected async lint(file: string) {\n\t\tif (AbstractWriter.isLintingEnabled) {\n\t\t\tthis.ui.startLoading(`Linting ${pathUtil.basename(file)}...`)\n\t\t\tawait this.linter?.fix(file).catch(() => {})\n\t\t}\n\t}\n\n\tpublic static disableLinting() {\n\t\tthis.isLintingEnabled = false\n\t}\n\n\tpublic static enableLinting() {\n\t\tthis.isLintingEnabled = true\n\t}\n\n\tprotected async writeDirectoryTemplate(\n\t\toptions: WriteDirectoryTemplateOptions\n\t) {\n\t\tconst {\n\t\t\tcontext,\n\t\t\tdestinationDir,\n\t\t\tfilesToWrite,\n\t\t\tfilesToSkip,\n\t\t\tshouldConfirmBeforeWriting = true,\n\t\t\tfirstFileWriteMessage,\n\t\t} = options\n\n\t\tthis.shouldConfirmBeforeWriting = shouldConfirmBeforeWriting\n\t\tthis.firstFileWriteMessage = firstFileWriteMessage\n\t\tthis.hasShownFirstWriteMessage = false\n\n\t\tconst files = await this.templates.directoryTemplate({\n\t\t\tkind: options.code,\n\t\t\tcontext: context ?? {},\n\t\t})\n\n\t\tlet results: WriteResults = []\n\n\t\tfor (const generated of files) {\n\t\t\tconst shouldWrite =\n\t\t\t\t!filesToWrite || filesToWrite.indexOf(generated.filename) > -1\n\t\t\tconst shouldSkip =\n\t\t\t\tfilesToSkip && filesToSkip.indexOf(generated.filename) > -1\n\n\t\t\tif (shouldWrite && !shouldSkip) {\n\t\t\t\tresults = await this.writeFileIfChangedMixinResults(\n\t\t\t\t\tpathUtil.join(destinationDir, generated.relativePath),\n\t\t\t\t\tgenerated.contents,\n\t\t\t\t\t'',\n\t\t\t\t\tresults,\n\t\t\t\t\tdestinationDir\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprotected async writeFileIfChangedMixinResults(\n\t\tdestination: string,\n\t\tcontents: string,\n\t\tdescription: string,\n\t\tresults?: WriteResults,\n\t\tcwd = ''\n\t): Promise<WriteResults> {\n\t\tconst myResults: WriteResults = results ?? []\n\t\tlet desc: string | undefined = description\n\n\t\tconst name = pathUtil.basename(destination)\n\t\tlet action: GeneratedFile['action'] = 'skipped'\n\n\t\tif (diskUtil.isDir(destination)) {\n\t\t\tthrow new Error(`Can't write to a directory ${destination}.`)\n\t\t}\n\n\t\tconst fileDescription = this.getFileDescription(destination)\n\n\t\tif (!diskUtil.doesFileExist(destination)) {\n\t\t\tlet write = true\n\n\t\t\tif (\n\t\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\t\tfileDescription?.confirmPromptOnFirstWrite\n\t\t\t) {\n\t\t\t\tthis.ui.stopLoading()\n\t\t\t\twrite = await this.ui.confirm(fileDescription.confirmPromptOnFirstWrite)\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'generated'\n\t\t\t}\n\t\t} else if (\n\t\t\tthis.isFileDifferent(destination, contents) &&\n\t\t\tthis.shouldOverwriteIfChanged(destination)\n\t\t) {\n\t\t\tconst cleanedName = this.cleanFilename(destination, cwd)\n\t\t\tconst settings = { skipped: [], ...this.settings.get('writer') }\n\t\t\tconst isAlwaysSkipped = settings.skipped.indexOf(cleanedName) > -1\n\t\t\tlet write = !isAlwaysSkipped\n\n\t\t\tif (!isAlwaysSkipped && this.shouldAskForOverwrite()) {\n\t\t\t\tif (!this.hasShownFirstWriteMessage && this.firstFileWriteMessage) {\n\t\t\t\t\tthis.hasShownFirstWriteMessage = true\n\t\t\t\t\tthis.ui.renderLine(this.firstFileWriteMessage)\n\t\t\t\t\tthis.ui.renderLine('')\n\t\t\t\t}\n\n\t\t\t\tconst answer = await this.ui.prompt({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tlabel: `${cleanedName}`,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_OVERWRITE,\n\t\t\t\t\t\t\t\tlabel: 'Overwrite',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_ALWAYS_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Always skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (answer === FILE_ACTION_ALWAYS_SKIP) {\n\t\t\t\t\tsettings.skipped.push(cleanedName)\n\t\t\t\t\tthis.settings.set('writer', settings)\n\t\t\t\t}\n\n\t\t\t\twrite = answer === FILE_ACTION_OVERWRITE\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'updated'\n\t\t\t}\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tdesc = fileDescription?.description\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tthrow new Error(\n\t\t\t\t`No FileDescription provided for ${destination.replace(\n\t\t\t\t\tcwd,\n\t\t\t\t\t''\n\t\t\t\t)}. Check your feature's fileDescriptions property.`\n\t\t\t)\n\t\t}\n\n\t\tmyResults.push({ name, description: desc, path: destination, action })\n\n\t\treturn myResults\n\t}\n\n\tprivate isFileDifferent(destination: string, contents: string) {\n\t\treturn diskUtil.isFileDifferent(destination, contents)\n\t}\n\n\tprivate cleanFilename(destination: string, cwd: string) {\n\t\tlet relativeFile = destination.replace(cwd, '')\n\t\tif (relativeFile[0] === pathUtil.sep) {\n\t\t\trelativeFile = relativeFile.substr(1)\n\t\t}\n\t\treturn relativeFile\n\t}\n\n\tprivate shouldOverwriteIfChanged(destination: string): boolean {\n\t\tif (!this.upgradeMode) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (this.upgradeMode === 'forceEverything') {\n\t\t\treturn true\n\t\t}\n\n\t\tlet description: FileDescription | undefined =\n\t\t\tthis.getFileDescription(destination)\n\n\t\treturn description?.shouldOverwriteWhenChanged ?? false\n\t}\n\n\tprivate getFileDescription(destination: string): FileDescription | undefined {\n\t\tconst lower = destination.toLowerCase()\n\t\tfor (const d of this.fileDescriptions ?? []) {\n\t\t\tif (lower.search(d.path.toLowerCase()) > -1) {\n\t\t\t\treturn d\n\t\t\t}\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\tprivate shouldAskForOverwrite() {\n\t\tif (\n\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\tthis.upgradeMode === 'askForChanged'\n\t\t) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\tprotected resolveFilenameWithFallback(\n\t\tdirOrFile: string,\n\t\tfallbackFileName: string\n\t) {\n\t\tconst isDir =\n\t\t\tdiskUtil.doesDirExist(dirOrFile) &&\n\t\t\tfs.lstatSync(dirOrFile).isDirectory() &&\n\t\t\tpathUtil.extname(dirOrFile).length === 0\n\t\treturn isDir ? diskUtil.resolvePath(dirOrFile, fallbackFileName) : dirOrFile\n\t}\n}\n"],"file":"AbstractWriter.js"}
1
+ {"version":3,"sources":["../../src/writers/AbstractWriter.ts"],"names":["AbstractWriter","options","templates","ui","term","upgradeMode","fileDescriptions","linter","settings","file","startLoading","pathUtil","basename","fix","context","destinationDir","filesToWrite","filesToSkip","shouldConfirmBeforeWriting","firstFileWriteMessage","hasShownFirstWriteMessage","directoryTemplate","kind","code","files","results","generated","shouldWrite","indexOf","filename","shouldSkip","writeFileIfChangedMixinResults","join","relativePath","contents","destination","description","cwd","myResults","desc","name","action","diskUtil","isDir","Error","fileDescription","getFileDescription","doesFileExist","write","confirmPromptOnFirstWrite","stopLoading","confirm","writeFile","isFileDifferent","shouldOverwriteIfChanged","cleanedName","cleanFilename","skipped","get","isAlwaysSkipped","shouldAskForOverwrite","renderLine","prompt","type","label","choices","value","FILE_ACTION_OVERWRITE","FILE_ACTION_SKIP","FILE_ACTION_ALWAYS_SKIP","answer","push","set","replace","path","relativeFile","sep","substr","shouldOverwriteWhenChanged","lower","toLowerCase","d","search","undefined","dirOrFile","fallbackFileName","doesDirExist","fs","lstatSync","isDirectory","extname","length","resolvePath"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;IA8B8BA,c;AAW7B,0BAAmBC,OAAnB,EAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+DANG,EAMH;AAAA,yEALN,IAKM;AAAA;AAAA,wEAHP,KAGO;AAAA;AAC1C,SAAKC,SAAL,GAAiBD,OAAO,CAACC,SAAzB;AACA,SAAKC,EAAL,GAAUF,OAAO,CAACG,IAAlB;AACA,SAAKC,WAAL,GAAmBJ,OAAO,CAACI,WAA3B;AACA,SAAKC,gBAAL,GAAwBL,OAAO,CAACK,gBAAhC;AACA,SAAKC,MAAL,GAAcN,OAAO,CAACM,MAAtB;AACA,SAAKC,QAAL,GAAgBP,OAAO,CAACO,QAAxB;AACA;;;;;gGAED,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ACD;AAN2E;AAAA;AAAA;AAAA;AAAA;;AAQ5E,aAAOE,SAAP;AACA;;;WAED,iCAAgC;AAC/B,UACC,KAAKjE,0BAAL,IACA,KAAKb,WAAL,KAAqB,eAFtB,EAGE;AACD,eAAO,IAAP;AACA;;AAED,aAAO,KAAP;AACA;;;WAED,qCACC+E,SADD,EAECC,gBAFD,EAGE;AACD,UAAM1C,KAAK,GACVD,2BAAS4C,YAAT,CAAsBF,SAAtB,KACAG,eAAGC,SAAH,CAAaJ,SAAb,EAAwBK,WAAxB,EADA,IAEA9E,iBAAS+E,OAAT,CAAiBN,SAAjB,EAA4BO,MAA5B,KAAuC,CAHxC;AAIA,aAAOhD,KAAK,GAAGD,2BAASkD,WAAT,CAAqBR,SAArB,EAAgCC,gBAAhC,CAAH,GAAuDD,SAAnE;AACA","sourcesContent":["import fs from 'fs'\nimport pathUtil from 'path'\nimport { diskUtil, SettingsService } from '@sprucelabs/spruce-skill-utils'\nimport { DirectoryTemplateCode, Templates } from '@sprucelabs/spruce-templates'\nimport {\n\tFILE_ACTION_ALWAYS_SKIP,\n\tFILE_ACTION_OVERWRITE,\n\tFILE_ACTION_SKIP,\n} from '../constants'\nimport LintService from '../services/LintService'\nimport { FileDescription, GeneratedFile, UpgradeMode } from '../types/cli.types'\nimport { GraphicsInterface } from '../types/cli.types'\n\nexport type WriteResults = GeneratedFile[]\n\nexport interface WriterOptions {\n\ttemplates: Templates\n\tterm: GraphicsInterface\n\tupgradeMode?: UpgradeMode\n\tfileDescriptions: FileDescription[]\n\tlinter?: LintService\n\tsettings: SettingsService\n}\n\nexport interface WriteDirectoryTemplateOptions {\n\tdestinationDir: string\n\tcode: DirectoryTemplateCode\n\tfilesToWrite?: string[]\n\tfilesToSkip?: string[]\n\tcontext: any\n\tshouldConfirmBeforeWriting?: boolean\n\tfirstFileWriteMessage?: string\n}\n\nexport default abstract class AbstractWriter {\n\tprotected templates: Templates\n\tprotected ui: GraphicsInterface\n\tprivate linter?: LintService\n\tprivate upgradeMode: UpgradeMode\n\tprivate fileDescriptions: FileDescription[] = []\n\tprivate shouldConfirmBeforeWriting = true\n\tprivate firstFileWriteMessage?: string\n\tprivate hasShownFirstWriteMessage = false\n\tprivate settings: SettingsService<string>\n\n\tpublic constructor(options: WriterOptions) {\n\t\tthis.templates = options.templates\n\t\tthis.ui = options.term\n\t\tthis.upgradeMode = options.upgradeMode\n\t\tthis.fileDescriptions = options.fileDescriptions\n\t\tthis.linter = options.linter\n\t\tthis.settings = options.settings\n\t}\n\n\tprotected async lint(file: string) {\n\t\tthis.ui.startLoading(`Linting ${pathUtil.basename(file)}...`)\n\t\tawait this.linter?.fix(file).catch(() => {})\n\t}\n\n\tprotected async writeDirectoryTemplate(\n\t\toptions: WriteDirectoryTemplateOptions\n\t) {\n\t\tconst {\n\t\t\tcontext,\n\t\t\tdestinationDir,\n\t\t\tfilesToWrite,\n\t\t\tfilesToSkip,\n\t\t\tshouldConfirmBeforeWriting = true,\n\t\t\tfirstFileWriteMessage,\n\t\t} = options\n\n\t\tthis.shouldConfirmBeforeWriting = shouldConfirmBeforeWriting\n\t\tthis.firstFileWriteMessage = firstFileWriteMessage\n\t\tthis.hasShownFirstWriteMessage = false\n\n\t\tconst files = await this.templates.directoryTemplate({\n\t\t\tkind: options.code,\n\t\t\tcontext: context ?? {},\n\t\t})\n\n\t\tlet results: WriteResults = []\n\n\t\tfor (const generated of files) {\n\t\t\tconst shouldWrite =\n\t\t\t\t!filesToWrite || filesToWrite.indexOf(generated.filename) > -1\n\t\t\tconst shouldSkip =\n\t\t\t\tfilesToSkip && filesToSkip.indexOf(generated.filename) > -1\n\n\t\t\tif (shouldWrite && !shouldSkip) {\n\t\t\t\tresults = await this.writeFileIfChangedMixinResults(\n\t\t\t\t\tpathUtil.join(destinationDir, generated.relativePath),\n\t\t\t\t\tgenerated.contents,\n\t\t\t\t\t'',\n\t\t\t\t\tresults,\n\t\t\t\t\tdestinationDir\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprotected async writeFileIfChangedMixinResults(\n\t\tdestination: string,\n\t\tcontents: string,\n\t\tdescription: string,\n\t\tresults?: WriteResults,\n\t\tcwd = ''\n\t): Promise<WriteResults> {\n\t\tconst myResults: WriteResults = results ?? []\n\t\tlet desc: string | undefined = description\n\n\t\tconst name = pathUtil.basename(destination)\n\t\tlet action: GeneratedFile['action'] = 'skipped'\n\n\t\tif (diskUtil.isDir(destination)) {\n\t\t\tthrow new Error(`Can't write to a directory ${destination}.`)\n\t\t}\n\n\t\tconst fileDescription = this.getFileDescription(destination)\n\n\t\tif (!diskUtil.doesFileExist(destination)) {\n\t\t\tlet write = true\n\n\t\t\tif (\n\t\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\t\tfileDescription?.confirmPromptOnFirstWrite\n\t\t\t) {\n\t\t\t\tthis.ui.stopLoading()\n\t\t\t\twrite = await this.ui.confirm(fileDescription.confirmPromptOnFirstWrite)\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'generated'\n\t\t\t}\n\t\t} else if (\n\t\t\tthis.isFileDifferent(destination, contents) &&\n\t\t\tthis.shouldOverwriteIfChanged(destination)\n\t\t) {\n\t\t\tconst cleanedName = this.cleanFilename(destination, cwd)\n\t\t\tconst settings = { skipped: [], ...this.settings.get('writer') }\n\t\t\tconst isAlwaysSkipped = settings.skipped.indexOf(cleanedName) > -1\n\t\t\tlet write = !isAlwaysSkipped\n\n\t\t\tif (!isAlwaysSkipped && this.shouldAskForOverwrite()) {\n\t\t\t\tif (!this.hasShownFirstWriteMessage && this.firstFileWriteMessage) {\n\t\t\t\t\tthis.hasShownFirstWriteMessage = true\n\t\t\t\t\tthis.ui.renderLine(this.firstFileWriteMessage)\n\t\t\t\t\tthis.ui.renderLine('')\n\t\t\t\t}\n\n\t\t\t\tconst answer = await this.ui.prompt({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tlabel: `${cleanedName}`,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_OVERWRITE,\n\t\t\t\t\t\t\t\tlabel: 'Overwrite',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_ALWAYS_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Always skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (answer === FILE_ACTION_ALWAYS_SKIP) {\n\t\t\t\t\tsettings.skipped.push(cleanedName)\n\t\t\t\t\tthis.settings.set('writer', settings)\n\t\t\t\t}\n\n\t\t\t\twrite = answer === FILE_ACTION_OVERWRITE\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'updated'\n\t\t\t}\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tdesc = fileDescription?.description\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tthrow new Error(\n\t\t\t\t`No FileDescription provided for ${destination.replace(\n\t\t\t\t\tcwd,\n\t\t\t\t\t''\n\t\t\t\t)}. Check your feature's fileDescriptions property.`\n\t\t\t)\n\t\t}\n\n\t\tmyResults.push({ name, description: desc, path: destination, action })\n\n\t\treturn myResults\n\t}\n\n\tprivate isFileDifferent(destination: string, contents: string) {\n\t\treturn diskUtil.isFileDifferent(destination, contents)\n\t}\n\n\tprivate cleanFilename(destination: string, cwd: string) {\n\t\tlet relativeFile = destination.replace(cwd, '')\n\t\tif (relativeFile[0] === pathUtil.sep) {\n\t\t\trelativeFile = relativeFile.substr(1)\n\t\t}\n\t\treturn relativeFile\n\t}\n\n\tprivate shouldOverwriteIfChanged(destination: string): boolean {\n\t\tif (!this.upgradeMode) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (this.upgradeMode === 'forceEverything') {\n\t\t\treturn true\n\t\t}\n\n\t\tlet description: FileDescription | undefined =\n\t\t\tthis.getFileDescription(destination)\n\n\t\treturn description?.shouldOverwriteWhenChanged ?? false\n\t}\n\n\tprivate getFileDescription(destination: string): FileDescription | undefined {\n\t\tconst lower = destination.toLowerCase()\n\t\tfor (const d of this.fileDescriptions ?? []) {\n\t\t\tif (lower.search(d.path.toLowerCase()) > -1) {\n\t\t\t\treturn d\n\t\t\t}\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\tprivate shouldAskForOverwrite() {\n\t\tif (\n\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\tthis.upgradeMode === 'askForChanged'\n\t\t) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\tprotected resolveFilenameWithFallback(\n\t\tdirOrFile: string,\n\t\tfallbackFileName: string\n\t) {\n\t\tconst isDir =\n\t\t\tdiskUtil.doesDirExist(dirOrFile) &&\n\t\t\tfs.lstatSync(dirOrFile).isDirectory() &&\n\t\t\tpathUtil.extname(dirOrFile).length === 0\n\t\treturn isDir ? diskUtil.resolvePath(dirOrFile, fallbackFileName) : dirOrFile\n\t}\n}\n"],"file":"AbstractWriter.js"}
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  ]
19
19
  },
20
20
  "license": "MIT",
21
- "version": "14.28.7",
21
+ "version": "14.29.2",
22
22
  "bin": {
23
23
  "spruce": "./build/index.js"
24
24
  },
@@ -84,11 +84,13 @@
84
84
  "@sprucelabs/mercury-types": "^26.1.992",
85
85
  "@sprucelabs/schema": "^25.4.67",
86
86
  "@sprucelabs/spruce-core-schemas": "^22.6.250",
87
- "@sprucelabs/spruce-event-plugin": "^17.0.4",
87
+ "@sprucelabs/spruce-event-plugin": "^18.1.0",
88
88
  "@sprucelabs/spruce-event-utils": "^17.1.272",
89
- "@sprucelabs/spruce-skill-booter": "^17.0.4",
89
+ "@sprucelabs/spruce-skill-booter": "^18.1.0",
90
90
  "@sprucelabs/spruce-skill-utils": "^22.1.50",
91
- "@sprucelabs/spruce-templates": "^14.28.7",
91
+ "@sprucelabs/spruce-templates": "^14.29.2",
92
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
93
+ "@typescript-eslint/parser": "^5.6.0",
92
94
  "cfonts": "^2.10.0",
93
95
  "chalk": "^4.1.2",
94
96
  "chokidar": "^3.5.2",
@@ -121,10 +123,10 @@
121
123
  "@sprucelabs/jest-sheets-reporter": "^1.2.268",
122
124
  "@sprucelabs/mercury-core-events": "^1.6.215",
123
125
  "@sprucelabs/resolve-path-aliases": "^1.0.236",
124
- "@sprucelabs/spruce-conversation-plugin": "^17.0.4",
125
- "@sprucelabs/spruce-deploy-plugin": "^17.0.4",
126
- "@sprucelabs/spruce-store-plugin": "^17.0.4",
127
- "@sprucelabs/spruce-test-fixtures": "^17.0.4",
126
+ "@sprucelabs/spruce-conversation-plugin": "^18.1.0",
127
+ "@sprucelabs/spruce-deploy-plugin": "^18.1.0",
128
+ "@sprucelabs/spruce-store-plugin": "^18.1.0",
129
+ "@sprucelabs/spruce-test-fixtures": "^18.1.0",
128
130
  "@sprucelabs/test": "^7.7.248",
129
131
  "@sprucelabs/test-utils": "^3.0.301",
130
132
  "@types/blessed": "^0.1.19",
@@ -595,5 +597,5 @@
595
597
  "ora"
596
598
  ]
597
599
  },
598
- "gitHead": "7e3efcf5136eb41be381f196473cd3526c59ca9d"
600
+ "gitHead": "0f8f6dd87e9cb555da15d985236cd190a9ab1d51"
599
601
  }
@@ -1,6 +1,7 @@
1
1
  import { diskUtil, namesUtil } from '@sprucelabs/spruce-skill-utils'
2
2
  import { test, assert } from '@sprucelabs/test'
3
3
  import { errorAssertUtil } from '@sprucelabs/test-utils'
4
+ import LintService from '../../services/LintService'
4
5
  import AbstractSkillTest from '../../tests/AbstractSkillTest'
5
6
  import testUtil from '../../tests/utilities/test.utility'
6
7
 
@@ -48,6 +49,7 @@ export default class SettingLogTransportsInASkillTest extends AbstractSkillTest
48
49
 
49
50
  @test()
50
51
  protected static async logsWriteToTransports() {
52
+ LintService.enableLinting()
51
53
  const transportContents = `
52
54
  import { diskUtil, Level, LogTransport } from '@sprucelabs/spruce-skill-utils'
53
55
 
@@ -8,7 +8,7 @@ export default class SyncingEventsOnlyFromDependenciesTest extends AbstractSkill
8
8
  protected static skillCacheKey = 'events'
9
9
 
10
10
  @test()
11
- protected static async doesntSyncAnythingToStart() {
11
+ protected static async doesntSyncAnythingButListenersToStart() {
12
12
  const skills = this.getSkillFixture()
13
13
  await skills.registerCurrentSkill({
14
14
  name: 'events in sync skill',
@@ -22,9 +22,11 @@ export default class SyncingEventsOnlyFromDependenciesTest extends AbstractSkill
22
22
 
23
23
  assert.isFalse(diskUtil.doesDirExist(eventFolder))
24
24
 
25
- const contents = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
25
+ const files = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
26
26
 
27
- assert.isLength(contents, 1)
27
+ assert.isLength(files, 2, 'The wrong number of files were generated.')
28
+ assert.isEqual(files[0], 'events.contract.ts')
29
+ assert.isEqual(files[1], 'listeners.ts')
28
30
  }
29
31
 
30
32
  @test()
@@ -43,9 +45,12 @@ export default class SyncingEventsOnlyFromDependenciesTest extends AbstractSkill
43
45
 
44
46
  assert.isTrue(diskUtil.doesDirExist(eventFolder))
45
47
 
46
- const contents = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
48
+ const files = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
47
49
 
48
- assert.isLength(contents, 2)
50
+ assert.isLength(files, 3, 'The wrong number of files were generated.')
51
+ assert.isEqual(files[0], namesUtil.toCamel(skill.slug))
52
+ assert.isEqual(files[1], 'events.contract.ts')
53
+ assert.isEqual(files[2], 'listeners.ts')
49
54
  }
50
55
 
51
56
  private static async registerGlobalEvent() {
@@ -1,5 +1,6 @@
1
1
  import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
2
  import { test, assert } from '@sprucelabs/test'
3
+ import LintService from '../../services/LintService'
3
4
  import AbstractSkillTest from '../../tests/AbstractSkillTest'
4
5
  import testUtil from '../../tests/utilities/test.utility'
5
6
 
@@ -32,6 +33,7 @@ export default class TestingDataStoresTest extends AbstractSkillTest {
32
33
 
33
34
  @test()
34
35
  protected static async letsYouSelectAbstractStoreTest() {
36
+ LintService.enableLinting()
35
37
  this.cli.getFeature('store').isInstalled = async () => true
36
38
 
37
39
  const promise = this.Action('test', 'create').execute({
@@ -11,6 +11,7 @@ export default class GeneratingMercuryEventContractTest extends AbstractCliTest
11
11
  protected static async beforeEach() {
12
12
  await super.beforeEach()
13
13
  this.cli = await this.Cli()
14
+ diskUtil.writeFile(this.resolvePath('package.json'), '{}')
14
15
  }
15
16
 
16
17
  @test()
@@ -52,18 +52,21 @@ export default class CreatingAListenerTest extends AbstractEventTest {
52
52
  }
53
53
 
54
54
  @test()
55
- protected static async createsValidListener() {
56
- const cli = await this.installEventFeature('events')
55
+ protected static async generatesMapFile() {
56
+ const { results } = await this.installEventsAndCreateListener()
57
57
 
58
- const version = 'v2020_01_01'
58
+ const match = testUtil.assertFileByNameInGeneratedFiles(
59
+ `listeners.ts`,
60
+ results.files
61
+ )
59
62
 
60
- const results = await this.Action('event', 'listen').execute({
61
- namespace: 'skill',
62
- eventName: 'will-boot',
63
- version,
64
- })
63
+ await this.Service('typeChecker').check(match)
64
+ }
65
65
 
66
- assert.isFalsy(results.errors)
66
+ @test()
67
+ protected static async createsValidListener() {
68
+ const { version, results, cli } =
69
+ await this.installEventsAndCreateListener()
67
70
 
68
71
  const match = testUtil.assertFileByNameInGeneratedFiles(
69
72
  `will-boot.${version}.listener.ts`,
@@ -76,6 +79,7 @@ export default class CreatingAListenerTest extends AbstractEventTest {
76
79
 
77
80
  const health = await cli.checkHealth()
78
81
 
82
+ assert.isFalsy(health?.event?.errors)
79
83
  assert.isTruthy(health.skill)
80
84
 
81
85
  assert.isUndefined(health.skill.errors)
@@ -261,6 +265,21 @@ export default class CreatingAListenerTest extends AbstractEventTest {
261
265
  )
262
266
  }
263
267
 
268
+ private static async installEventsAndCreateListener() {
269
+ const cli = await this.installEventFeature('events')
270
+
271
+ const version = 'v2020_01_01'
272
+
273
+ const results = await this.Action('event', 'listen').execute({
274
+ namespace: 'skill',
275
+ eventName: 'will-boot',
276
+ version,
277
+ })
278
+
279
+ assert.isFalsy(results.errors)
280
+ return { version, results, cli }
281
+ }
282
+
264
283
  private static async setupSkillsInstallAtOrgRegisterEventContractAndGenerateListener(
265
284
  eventSignature: EventSignature
266
285
  ) {
@@ -0,0 +1,47 @@
1
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
+ import { test, assert } from '@sprucelabs/test'
3
+ import { FeatureActionResponse } from '../../../features/features.types'
4
+ import AbstractEventTest from '../../../tests/AbstractEventTest'
5
+ import testUtil from '../../../tests/utilities/test.utility'
6
+
7
+ export default class KeepingListenersInSyncTest extends AbstractEventTest {
8
+ @test()
9
+ protected static async hasSyncAction() {
10
+ assert.isFunction(this.Action('event', 'sync.listeners').execute)
11
+ }
12
+
13
+ @test()
14
+ protected static async deletingAListener() {
15
+ await this.FeatureFixture().installCachedFeatures('events')
16
+
17
+ await this.createBootListener('did-boot')
18
+ const results = await this.createBootListener('will-boot')
19
+
20
+ this.deleteLastFile(results)
21
+
22
+ const syncResults = await this.Action('event', 'sync.listeners').execute({})
23
+
24
+ const listenerMap = testUtil.assertFileByNameInGeneratedFiles(
25
+ 'listeners.ts',
26
+ syncResults.files
27
+ )
28
+
29
+ await this.Service('typeChecker').check(listenerMap)
30
+ }
31
+
32
+ private static deleteLastFile(results: FeatureActionResponse) {
33
+ const path = results.files?.pop()?.path
34
+ assert.isString(path)
35
+
36
+ diskUtil.deleteFile(path)
37
+ }
38
+
39
+ private static async createBootListener(name: 'will-boot' | 'did-boot') {
40
+ const results = await this.Action('event', 'listen').execute({
41
+ namespace: 'skill',
42
+ eventName: name,
43
+ })
44
+ assert.isFalsy(results.errors)
45
+ return results
46
+ }
47
+ }
@@ -1,8 +1,14 @@
1
1
  import { test, assert } from '@sprucelabs/test'
2
2
  import { errorAssertUtil } from '@sprucelabs/test-utils'
3
+ import LintService from '../../../services/LintService'
3
4
  import AbstractEventTest from '../../../tests/AbstractEventTest'
4
5
 
5
6
  export default class SkillEmitsBootEventsTest extends AbstractEventTest {
7
+ protected static async beforeEach() {
8
+ await super.beforeEach()
9
+ LintService.enableLinting()
10
+ }
11
+
6
12
  @test()
7
13
  protected static async skillEmitsWillBootEvents() {
8
14
  await this.installEventFeature('events')
@@ -0,0 +1,59 @@
1
+ import { eventResponseUtil } from '@sprucelabs/spruce-event-utils'
2
+ import { test, assert } from '@sprucelabs/test'
3
+ import SpruceError from '../../../errors/SpruceError'
4
+ import { FeatureCode } from '../../../features/features.types'
5
+ import CommandService from '../../../services/CommandService'
6
+ import AbstractCliTest from '../../../tests/AbstractCliTest'
7
+
8
+ export default class UpgradingWithListeners extends AbstractCliTest {
9
+ @test('should sync listeners when installed', 'events', true)
10
+ @test('should not sync listeners when not installed', 'skills', false)
11
+ @test(
12
+ 'should not sync listeners when creating node when not installed',
13
+ 'testsInNodeModule',
14
+ false,
15
+ 'create'
16
+ )
17
+ @test(
18
+ 'should not sync listeners when creating node when installed',
19
+ 'events',
20
+ false,
21
+ 'create'
22
+ )
23
+ protected static async upgradingSyncsListeners(
24
+ featureCode: FeatureCode,
25
+ shouldHit: boolean,
26
+ actionCode = 'upgrade'
27
+ ) {
28
+ await this.FeatureFixture().installCachedFeatures(featureCode)
29
+
30
+ CommandService.setMockResponse(new RegExp(/yarn/), {
31
+ code: 0,
32
+ })
33
+
34
+ let wasHit = false
35
+
36
+ await this.getEmitter().on(
37
+ 'feature.will-execute',
38
+ async ({ featureCode, actionCode }) => {
39
+ if (featureCode === 'event' && actionCode === 'sync.listeners') {
40
+ wasHit = true
41
+ }
42
+ }
43
+ )
44
+
45
+ const results = await this.getEmitter().emit('feature.will-execute', {
46
+ featureCode: 'node',
47
+ actionCode,
48
+ })
49
+
50
+ const { errors } = eventResponseUtil.getAllResponsePayloadsAndErrors(
51
+ results,
52
+ SpruceError
53
+ )
54
+
55
+ assert.isFalsy(errors)
56
+
57
+ assert.isEqual(wasHit, shouldHit)
58
+ }
59
+ }
@@ -47,6 +47,7 @@ export default class CreatingDataStoresTest extends AbstractSkillTest {
47
47
  protected static async generatesAMapFile() {
48
48
  const file = this.resolveHashSprucePath('stores', 'stores.ts')
49
49
  assert.isTrue(diskUtil.doesFileExist(file))
50
+ await this.Service('typeChecker').check(file)
50
51
  }
51
52
 
52
53
  @test()
@@ -1,6 +1,7 @@
1
1
  import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
2
  import { test, assert } from '@sprucelabs/test'
3
3
  import { errorAssertUtil } from '@sprucelabs/test-utils'
4
+ import { FeatureActionResponse } from '../../../features/features.types'
4
5
  import AbstractSkillTest from '../../../tests/AbstractSkillTest'
5
6
  import testUtil from '../../../tests/utilities/test.utility'
6
7
 
@@ -29,10 +30,6 @@ export default class KeepingDataStoresInSyncTest extends AbstractSkillTest {
29
30
  assert.isLength(results.files, 0)
30
31
  }
31
32
 
32
- private static async syncStores() {
33
- return this.Action('store', 'sync').execute({})
34
- }
35
-
36
33
  @test()
37
34
  protected static async badFileReturnsError() {
38
35
  diskUtil.writeFile(this.badStoreDest, 'throw new Error("Cheese!")')
@@ -48,19 +45,51 @@ export default class KeepingDataStoresInSyncTest extends AbstractSkillTest {
48
45
 
49
46
  @test()
50
47
  protected static async generatesValidTypeFile() {
51
- await this.Action('store', 'create').execute({
48
+ const results = await this.Action('store', 'create').execute({
52
49
  nameReadable: 'Bid',
53
50
  nameReadablePlural: 'Bids',
54
51
  namePascal: 'Bid',
55
52
  })
56
53
 
54
+ await this.validateFiles(results)
55
+ }
56
+
57
+ @test()
58
+ protected static async fileIsValidAfterSync() {
57
59
  const results = await this.syncStores()
58
60
 
61
+ await this.validateFiles(results)
62
+ }
63
+
64
+ @test()
65
+ protected static async canAddSecondStore() {
66
+ const results = await this.Action('store', 'create').execute({
67
+ nameReadable: 'Person',
68
+ nameReadablePlural: 'People',
69
+ namePascal: 'Person',
70
+ })
71
+
72
+ await this.validateFiles(results)
73
+ }
74
+
75
+ private static async validateFiles(results: FeatureActionResponse) {
59
76
  const typesFile = testUtil.assertFileByNameInGeneratedFiles(
60
77
  'stores.types.ts',
61
78
  results.files
62
79
  )
63
80
 
64
- await this.Service('typeChecker').check(typesFile)
81
+ const mapFile = testUtil.assertFileByNameInGeneratedFiles(
82
+ 'stores.ts',
83
+ results.files
84
+ )
85
+
86
+ await Promise.all([
87
+ this.Service('typeChecker').check(typesFile),
88
+ this.Service('typeChecker').check(mapFile),
89
+ ])
90
+ }
91
+
92
+ private static async syncStores() {
93
+ return this.Action('store', 'sync').execute({})
65
94
  }
66
95
  }
@@ -1,4 +1,5 @@
1
1
  import { test, assert } from '@sprucelabs/test'
2
+ import LintService from '../../../services/LintService'
2
3
  import AbstractTestTest from '../../../tests/AbstractTestTest'
3
4
  import testUtil from '../../../tests/utilities/test.utility'
4
5
 
@@ -30,6 +31,7 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
30
31
  'AbstractStoreTest (requires install)'
31
32
  )
32
33
  protected static async canCreateBehavioralTest(testName: string) {
34
+ LintService.enableLinting()
33
35
  await this.installTests()
34
36
  const promise = this.Action('test', 'create').execute({
35
37
  type: 'behavioral',
@@ -1,11 +1,17 @@
1
1
  import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
2
  import { test, assert } from '@sprucelabs/test'
3
+ import LintService from '../../../services/LintService'
3
4
  import AbstractSkillTest from '../../../tests/AbstractSkillTest'
4
5
  import testUtil from '../../../tests/utilities/test.utility'
5
6
 
6
7
  export default class TestingViewControllersTest extends AbstractSkillTest {
7
8
  protected static skillCacheKey = 'viewsWithTests'
8
9
 
10
+ protected static async beforeEach() {
11
+ await super.beforeEach()
12
+ LintService.enableLinting()
13
+ }
14
+
9
15
  @test()
10
16
  protected static async showsNotInstalled() {
11
17
  const viewFeature = this.cli.getFeature('view')
@@ -70,11 +70,13 @@ export default class AuthServiceTest extends AbstractCliTest {
70
70
 
71
71
  @test()
72
72
  protected static getCurrentSkillReturnsNull() {
73
+ this.writePackageJson()
73
74
  assert.isNull(this.auth.getCurrentSkill())
74
75
  }
75
76
 
76
77
  @test()
77
78
  protected static canSetCurrentSkill() {
79
+ this.writePackageJson()
78
80
  const skill = {
79
81
  id: '123467aaoeuaoeu',
80
82
  apiKey: 'taco',
@@ -86,4 +88,8 @@ export default class AuthServiceTest extends AbstractCliTest {
86
88
 
87
89
  assert.isEqualDeep(this.auth.getCurrentSkill(), skill)
88
90
  }
91
+
92
+ private static writePackageJson() {
93
+ diskUtil.writeFile(this.resolvePath('package.json'), '{}')
94
+ }
89
95
  }
@@ -29,6 +29,7 @@ export default class EventStoreTest extends AbstractEventTest {
29
29
  public static async beforeEach() {
30
30
  await super.beforeEach()
31
31
  this.createAction = this.Action<CreateAction>('event', 'create')
32
+ diskUtil.writeFile(this.resolvePath('package.json'), '{}')
32
33
  }
33
34
 
34
35
  @test()
@@ -0,0 +1,34 @@
1
+ import { test, assert } from '@sprucelabs/test'
2
+ import CommandService from '../../services/CommandService'
3
+ import LintService from '../../services/LintService'
4
+ import AbstractCliTest from '../../tests/AbstractCliTest'
5
+
6
+ export default class LintServiceTest extends AbstractCliTest {
7
+ @test()
8
+ protected static async throwsWhenLintReturnsMessage() {
9
+ LintService.enableLinting()
10
+
11
+ await this.FeatureFixture().installCachedFeatures('skills')
12
+
13
+ CommandService.setMockResponse(/node/, {
14
+ code: 0,
15
+ stdout: `[{"filePath":"/Users/taylorromero/Development/SpruceLabs/spruce-appointments-skill/src/.spruce/stores/stores.types.ts","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use a negated ignore pattern (like \\"--ignore-pattern '!<relative/path/to/filename>'\\") to override."}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":[]}]\n`,
16
+ })
17
+
18
+ await assert.doesThrowAsync(() => this.Service('lint').fix('./go'))
19
+ }
20
+
21
+ @test()
22
+ protected static async worksWhenNoMessagesReturned() {
23
+ LintService.enableLinting()
24
+
25
+ await this.FeatureFixture().installCachedFeatures('skills')
26
+
27
+ CommandService.setMockResponse(/node/, {
28
+ code: 0,
29
+ stdout: `[{"filePath":"/Users/taylorromero/Development/SpruceLabs/spruce-appointments-skill/src/.spruce/stores/stores.types.ts","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use a negated ignore pattern (like \\"--ignore-pattern '!<relative/path/to/filename>'\\") to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":[]}]\n`,
30
+ })
31
+
32
+ await this.Service('lint').fix('./go')
33
+ }
34
+ }
@@ -0,0 +1,40 @@
1
+ import { test, assert } from '@sprucelabs/test'
2
+ import CommandService from '../../services/CommandService'
3
+ import AbstractCliTest from '../../tests/AbstractCliTest'
4
+
5
+ export default class StoreFeatureTest extends AbstractCliTest {
6
+ @test()
7
+ protected static async syncsOnWillExecute() {
8
+ await this.FeatureFixture().installCachedFeatures('stores')
9
+
10
+ CommandService.setMockResponse(/yarn/, {
11
+ code: 0,
12
+ })
13
+
14
+ let hitCount = 0
15
+ const emitter = this.getEmitter()
16
+ await emitter.on(
17
+ 'feature.will-execute',
18
+ async ({ featureCode, actionCode }) => {
19
+ if (featureCode === 'store' && actionCode === 'sync') {
20
+ hitCount++
21
+ }
22
+ }
23
+ )
24
+
25
+ await emitter.emit('feature.will-execute', {
26
+ featureCode: 'node',
27
+ actionCode: 'upgrade',
28
+ })
29
+
30
+ assert.isEqual(hitCount, 1)
31
+
32
+ await emitter.emit('feature.did-execute', {
33
+ featureCode: 'node',
34
+ actionCode: 'upgrade',
35
+ results: {},
36
+ })
37
+
38
+ assert.isEqual(hitCount, 1)
39
+ }
40
+ }
@@ -68,12 +68,16 @@ export default class SpruceError extends AbstractSpruceError<ErrorOptions> {
68
68
  break
69
69
 
70
70
  case 'LINT_FAILED':
71
- message = `Lint failed on pattern ${options.pattern}.`
71
+ message = options.friendlyMessage
72
72
 
73
- if (options.originalError) {
74
- message += `\n\nOriginal error:${
75
- options.originalError.stack ?? options.originalError.message
76
- }`
73
+ if (!message) {
74
+ message = `Lint failed on pattern ${options.pattern}.`
75
+
76
+ if (options.originalError) {
77
+ message += `\n\nOriginal error:${
78
+ options.originalError.stack ?? options.originalError.message
79
+ }`
80
+ }
77
81
  }
78
82
 
79
83
  break