@sprucelabs/spruce-cli 14.28.5 → 14.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/build/__tests__/behavioral/BootingWithBadFiles.test.js +26 -13
- package/build/__tests__/behavioral/BootingWithBadFiles.test.js.map +1 -1
- package/build/__tests__/behavioral/SettingLogTransportsInASkill.test.js +13 -9
- package/build/__tests__/behavioral/SettingLogTransportsInASkill.test.js.map +1 -1
- package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.d.ts +1 -1
- package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.js +24 -14
- package/build/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.js.map +1 -1
- package/build/__tests__/behavioral/TestingDataStores.test.js +15 -11
- package/build/__tests__/behavioral/TestingDataStores.test.js.map +1 -1
- package/build/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.js +3 -1
- package/build/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.js.map +1 -1
- package/build/__tests__/behavioral/events/CreatingAListener.test.d.ts +2 -0
- package/build/__tests__/behavioral/events/CreatingAListener.test.js +157 -81
- package/build/__tests__/behavioral/events/CreatingAListener.test.js.map +1 -1
- package/build/__tests__/behavioral/events/KeepingEventsInSync2.test.js +1 -1
- package/build/__tests__/behavioral/events/KeepingEventsInSync2.test.js.map +1 -1
- package/build/__tests__/behavioral/events/KeepingListenersInSync.test.d.ts +7 -0
- package/build/__tests__/behavioral/events/KeepingListenersInSync.test.js +171 -0
- package/build/__tests__/behavioral/events/KeepingListenersInSync.test.js.map +1 -0
- package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.d.ts +1 -0
- package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.js +53 -21
- package/build/__tests__/behavioral/events/SkillEmitsBootEvents.test.js.map +1 -1
- package/build/__tests__/behavioral/skill/UpgradingASkill2.test.d.ts +1 -1
- package/build/__tests__/behavioral/skill/UpgradingASkill2.test.js +10 -20
- package/build/__tests__/behavioral/skill/UpgradingASkill2.test.js.map +1 -1
- package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.d.ts +5 -0
- package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.js +137 -0
- package/build/__tests__/behavioral/skill/UpgradingWithListeners.test.js.map +1 -0
- package/build/__tests__/behavioral/{CreatingADataStore.test.d.ts → stores/CreatingADataStore.test.d.ts} +2 -1
- package/build/__tests__/behavioral/{CreatingADataStore.test.js → stores/CreatingADataStore.test.js} +87 -57
- package/build/__tests__/behavioral/stores/CreatingADataStore.test.js.map +1 -0
- package/build/__tests__/behavioral/{KeepingDataStoresInSync.test.d.ts → stores/KeepingDataStoresInSync.test.d.ts} +5 -2
- package/build/__tests__/behavioral/{KeepingDataStoresInSync.test.js → stores/KeepingDataStoresInSync.test.js} +138 -49
- package/build/__tests__/behavioral/stores/KeepingDataStoresInSync.test.js.map +1 -0
- package/build/__tests__/behavioral/tests/CreatingATest.test.js +14 -10
- package/build/__tests__/behavioral/tests/CreatingATest.test.js.map +1 -1
- package/build/__tests__/behavioral/views/TestingViewControllers.test.d.ts +1 -0
- package/build/__tests__/behavioral/views/TestingViewControllers.test.js +67 -35
- package/build/__tests__/behavioral/views/TestingViewControllers.test.js.map +1 -1
- package/build/__tests__/implementation/AuthService.test.d.ts +1 -0
- package/build/__tests__/implementation/AuthService.test.js +8 -0
- package/build/__tests__/implementation/AuthService.test.js.map +1 -1
- package/build/__tests__/implementation/EventStore.test.js +3 -1
- package/build/__tests__/implementation/EventStore.test.js.map +1 -1
- package/build/__tests__/implementation/StoreFeature.test.d.ts +4 -0
- package/build/__tests__/implementation/StoreFeature.test.js +132 -0
- package/build/__tests__/implementation/StoreFeature.test.js.map +1 -0
- package/build/cli.d.ts +1 -1
- package/build/cli.js +1 -1
- package/build/cli.js.map +1 -1
- package/build/features/event/EventFeature.d.ts +2 -2
- package/build/features/event/EventFeature.js +53 -13
- package/build/features/event/EventFeature.js.map +1 -1
- package/build/features/event/actions/ListenAction.d.ts +1 -0
- package/build/features/event/actions/ListenAction.js +60 -31
- package/build/features/event/actions/ListenAction.js.map +1 -1
- package/build/features/event/actions/SyncListenersAction.d.ts +15 -0
- package/build/features/event/actions/SyncListenersAction.js +115 -0
- package/build/features/event/actions/SyncListenersAction.js.map +1 -0
- package/build/features/event/builders/ListenerTemplateItemBuilder.d.ts +8 -0
- package/build/features/event/builders/ListenerTemplateItemBuilder.js +65 -0
- package/build/features/event/builders/ListenerTemplateItemBuilder.js.map +1 -0
- package/build/features/event/stores/EventStore.js +2 -2
- package/build/features/event/stores/EventStore.js.map +1 -1
- package/build/features/event/stores/ListenerStore.d.ts +9 -0
- package/build/features/event/stores/ListenerStore.js +122 -0
- package/build/features/event/stores/ListenerStore.js.map +1 -0
- package/build/features/event/writers/EventWriter.d.ts +4 -1
- package/build/features/event/writers/EventWriter.js +42 -8
- package/build/features/event/writers/EventWriter.js.map +1 -1
- package/build/features/node/NodeFeature.js +6 -11
- package/build/features/node/NodeFeature.js.map +1 -1
- package/build/features/skill/SkillFeature.js +1 -1
- package/build/features/skill/SkillFeature.js.map +1 -1
- package/build/features/skill/stores/SkillStore.js +4 -8
- package/build/features/skill/stores/SkillStore.js.map +1 -1
- package/build/features/store/StoreFeature.d.ts +1 -1
- package/build/features/store/StoreFeature.js +6 -6
- package/build/features/store/StoreFeature.js.map +1 -1
- package/build/features/store/actions/SyncAction.js +11 -10
- package/build/features/store/actions/SyncAction.js.map +1 -1
- package/build/features/store/writers/StoreWriter.d.ts +6 -0
- package/build/features/store/writers/StoreWriter.js +78 -8
- package/build/features/store/writers/StoreWriter.js.map +1 -1
- package/build/services/AuthService.d.ts +4 -1
- package/build/services/AuthService.js +15 -4
- package/build/services/AuthService.js.map +1 -1
- package/build/services/LintService.d.ts +4 -1
- package/build/services/LintService.js +123 -94
- package/build/services/LintService.js.map +1 -1
- package/build/services/ServiceFactory.js +3 -3
- package/build/services/ServiceFactory.js.map +1 -1
- package/build/stores/StoreFactory.d.ts +2 -0
- package/build/stores/StoreFactory.js +4 -1
- package/build/stores/StoreFactory.js.map +1 -1
- package/build/tests/AbstractCliTest.js +3 -3
- package/build/tests/AbstractCliTest.js.map +1 -1
- package/build/writers/AbstractWriter.d.ts +0 -3
- package/build/writers/AbstractWriter.js +2 -18
- package/build/writers/AbstractWriter.js.map +1 -1
- package/package.json +30 -28
- package/src/__tests__/behavioral/BootingWithBadFiles.test.ts +8 -3
- package/src/__tests__/behavioral/SettingLogTransportsInASkill.test.ts +2 -0
- package/src/__tests__/behavioral/SyncingEventsOnlyFromDependencies.test.ts +10 -5
- package/src/__tests__/behavioral/TestingDataStores.test.ts +2 -0
- package/src/__tests__/behavioral/eventContract/PullingMercuryEventContract.test.ts +1 -0
- package/src/__tests__/behavioral/events/CreatingAListener.test.ts +28 -9
- package/src/__tests__/behavioral/events/KeepingEventsInSync2.test.ts +1 -1
- package/src/__tests__/behavioral/events/KeepingListenersInSync.test.ts +47 -0
- package/src/__tests__/behavioral/events/SkillEmitsBootEvents.test.ts +6 -0
- package/src/__tests__/behavioral/skill/UpgradingASkill2.test.ts +1 -10
- package/src/__tests__/behavioral/skill/UpgradingWithListeners.test.ts +59 -0
- package/src/__tests__/behavioral/{CreatingADataStore.test.ts → stores/CreatingADataStore.test.ts} +13 -6
- package/src/__tests__/behavioral/{KeepingDataStoresInSync.test.ts → stores/KeepingDataStoresInSync.test.ts} +37 -8
- package/src/__tests__/behavioral/tests/CreatingATest.test.ts +2 -0
- package/src/__tests__/behavioral/views/TestingViewControllers.test.ts +6 -0
- package/src/__tests__/implementation/AuthService.test.ts +6 -0
- package/src/__tests__/implementation/EventStore.test.ts +1 -0
- package/src/__tests__/implementation/StoreFeature.test.ts +40 -0
- package/src/cli.ts +2 -2
- package/src/features/event/EventFeature.ts +21 -4
- package/src/features/event/actions/ListenAction.ts +9 -3
- package/src/features/event/actions/SyncListenersAction.ts +38 -0
- package/src/features/event/builders/ListenerTemplateItemBuilder.ts +27 -0
- package/src/features/event/stores/EventStore.ts +1 -1
- package/src/features/event/stores/ListenerStore.ts +32 -0
- package/src/features/event/writers/EventWriter.ts +19 -0
- package/src/features/node/NodeFeature.ts +0 -3
- package/src/features/skill/SkillFeature.ts +1 -1
- package/src/features/skill/stores/SkillStore.ts +4 -3
- package/src/features/store/StoreFeature.ts +3 -3
- package/src/features/store/actions/SyncAction.ts +2 -1
- package/src/features/store/writers/StoreWriter.ts +30 -0
- package/src/services/AuthService.ts +15 -5
- package/src/services/LintService.ts +19 -2
- package/src/services/ServiceFactory.ts +9 -3
- package/src/stores/StoreFactory.ts +3 -0
- package/src/tests/AbstractCliTest.ts +2 -2
- package/src/writers/AbstractWriter.ts +2 -13
- package/build/__tests__/behavioral/CreatingADataStore.test.js.map +0 -1
- package/build/__tests__/behavioral/KeepingDataStoresInSync.test.js.map +0 -1
|
@@ -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","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ent":["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;;;;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kBAAL,CAAwBX,WAAxB,CADD;AAGA,sCAAOC,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAE0C,0BAApB,yEAAkD,KAAlD;AACA;;;WAED,4BAA2B3C,WAA3B,EAA6E;AAAA;;AAC5E,UAAM4C,KAAK,GAAG5C,WAAW,CAAC6C,WAAZ,EAAd;;AAD4E,2EAE5D,KAAK1E,gBAFuD,yEAEnC,EAFmC;AAAA;;AAAA;AAE5E,+DAA6C;AAAA,cAAlC2E,CAAkC;;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,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.
|
|
21
|
+
"version": "14.29.0",
|
|
22
22
|
"bin": {
|
|
23
23
|
"spruce": "./build/index.js"
|
|
24
24
|
},
|
|
@@ -76,25 +76,27 @@
|
|
|
76
76
|
"@babel/plugin-proposal-decorators": "^7.16.4",
|
|
77
77
|
"@babel/runtime": "^7.16.3",
|
|
78
78
|
"@jest/reporters": "^27.4.2",
|
|
79
|
-
"@sprucelabs/error": "^5.0.
|
|
80
|
-
"@sprucelabs/heartwood-view-controllers": "^51.6.
|
|
81
|
-
"@sprucelabs/jest-json-reporter": "^6.0.
|
|
82
|
-
"@sprucelabs/mercury-client": "^17.4.
|
|
83
|
-
"@sprucelabs/mercury-event-emitter": "^17.4.
|
|
84
|
-
"@sprucelabs/mercury-types": "^26.1.
|
|
85
|
-
"@sprucelabs/schema": "^25.4.
|
|
86
|
-
"@sprucelabs/spruce-core-schemas": "^22.6.
|
|
87
|
-
"@sprucelabs/spruce-event-plugin": "^
|
|
88
|
-
"@sprucelabs/spruce-event-utils": "^17.1.
|
|
89
|
-
"@sprucelabs/spruce-skill-booter": "^
|
|
90
|
-
"@sprucelabs/spruce-skill-utils": "^22.1.
|
|
91
|
-
"@sprucelabs/spruce-templates": "^14.
|
|
79
|
+
"@sprucelabs/error": "^5.0.317",
|
|
80
|
+
"@sprucelabs/heartwood-view-controllers": "^51.6.51",
|
|
81
|
+
"@sprucelabs/jest-json-reporter": "^6.0.265",
|
|
82
|
+
"@sprucelabs/mercury-client": "^17.4.29",
|
|
83
|
+
"@sprucelabs/mercury-event-emitter": "^17.4.29",
|
|
84
|
+
"@sprucelabs/mercury-types": "^26.1.992",
|
|
85
|
+
"@sprucelabs/schema": "^25.4.67",
|
|
86
|
+
"@sprucelabs/spruce-core-schemas": "^22.6.250",
|
|
87
|
+
"@sprucelabs/spruce-event-plugin": "^18.1.0",
|
|
88
|
+
"@sprucelabs/spruce-event-utils": "^17.1.272",
|
|
89
|
+
"@sprucelabs/spruce-skill-booter": "^18.1.0",
|
|
90
|
+
"@sprucelabs/spruce-skill-utils": "^22.1.50",
|
|
91
|
+
"@sprucelabs/spruce-templates": "^14.29.0",
|
|
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",
|
|
95
97
|
"cli-table3": "^0.6.0",
|
|
96
98
|
"commander": "^7.2.0",
|
|
97
|
-
"core-js": "^3.19.
|
|
99
|
+
"core-js": "^3.19.3",
|
|
98
100
|
"emphasize": "^4.2.0",
|
|
99
101
|
"fs-extra": "^10.0.0",
|
|
100
102
|
"gifwrap": "SimenB/gifwrap#patch-1",
|
|
@@ -117,16 +119,16 @@
|
|
|
117
119
|
"uuid": "^8.3.2"
|
|
118
120
|
},
|
|
119
121
|
"devDependencies": {
|
|
120
|
-
"@sprucelabs/data-stores": "^7.
|
|
121
|
-
"@sprucelabs/jest-sheets-reporter": "^1.2.
|
|
122
|
-
"@sprucelabs/mercury-core-events": "^1.6.
|
|
123
|
-
"@sprucelabs/resolve-path-aliases": "^1.0.
|
|
124
|
-
"@sprucelabs/spruce-conversation-plugin": "^
|
|
125
|
-
"@sprucelabs/spruce-deploy-plugin": "^
|
|
126
|
-
"@sprucelabs/spruce-store-plugin": "^
|
|
127
|
-
"@sprucelabs/spruce-test-fixtures": "^
|
|
128
|
-
"@sprucelabs/test": "^7.7.
|
|
129
|
-
"@sprucelabs/test-utils": "^3.0.
|
|
122
|
+
"@sprucelabs/data-stores": "^7.2.0",
|
|
123
|
+
"@sprucelabs/jest-sheets-reporter": "^1.2.268",
|
|
124
|
+
"@sprucelabs/mercury-core-events": "^1.6.215",
|
|
125
|
+
"@sprucelabs/resolve-path-aliases": "^1.0.236",
|
|
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",
|
|
130
|
+
"@sprucelabs/test": "^7.7.248",
|
|
131
|
+
"@sprucelabs/test-utils": "^3.0.301",
|
|
130
132
|
"@types/blessed": "^0.1.19",
|
|
131
133
|
"@types/eslint": "^8.2.1",
|
|
132
134
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -157,10 +159,10 @@
|
|
|
157
159
|
"jest-circus": "^27.4.2",
|
|
158
160
|
"jest-junit": "^13.0.0",
|
|
159
161
|
"jest-reporters": "^0.0.2",
|
|
160
|
-
"prettier": "^2.5.
|
|
162
|
+
"prettier": "^2.5.1",
|
|
161
163
|
"ps-node": "^0.1.6",
|
|
162
164
|
"rimraf": "^3.0.2",
|
|
163
|
-
"ts-jest": "^27.0
|
|
165
|
+
"ts-jest": "^27.1.0",
|
|
164
166
|
"ts-node": "^10.4.0",
|
|
165
167
|
"tsc-watch": "^4.5.0",
|
|
166
168
|
"tsconfig-paths": "^3.12.0",
|
|
@@ -595,5 +597,5 @@
|
|
|
595
597
|
"ora"
|
|
596
598
|
]
|
|
597
599
|
},
|
|
598
|
-
"gitHead": "
|
|
600
|
+
"gitHead": "b3d42f18072662e082727a4ac9b60f3ec707db3d"
|
|
599
601
|
}
|
|
@@ -6,6 +6,7 @@ import testUtil from '../../tests/utilities/test.utility'
|
|
|
6
6
|
export default class BootingWithBadFilesTest extends AbstractCliTest {
|
|
7
7
|
@test()
|
|
8
8
|
protected static async bootingWithAEmptySchemaThrowsErrorWithNameOfBadSchema() {
|
|
9
|
+
await this.FeatureFixture().installCachedFeatures('schemas')
|
|
9
10
|
const bootResults = await this.breakSchemaAndBoot()
|
|
10
11
|
assert.isTruthy(bootResults.errors)
|
|
11
12
|
assert.doesInclude(bootResults.errors[0].message, 'location.schema.ts')
|
|
@@ -13,12 +14,16 @@ export default class BootingWithBadFilesTest extends AbstractCliTest {
|
|
|
13
14
|
|
|
14
15
|
@test()
|
|
15
16
|
protected static async disablesSchemaCheckingWithFlag() {
|
|
16
|
-
|
|
17
|
+
await this.FeatureFixture().installCachedFeatures('schemas')
|
|
18
|
+
diskUtil.writeFile(
|
|
19
|
+
this.resolvePath('.env'),
|
|
20
|
+
'SHOULD_VALIDATE_SCHEMAS_ON_BOOT=false'
|
|
21
|
+
)
|
|
22
|
+
const bootResults = await this.breakSchemaAndBoot()
|
|
23
|
+
assert.isFalsy(bootResults.errors)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
private static async breakSchemaAndBoot() {
|
|
20
|
-
await this.FeatureFixture().installCachedFeatures('schemas')
|
|
21
|
-
|
|
22
27
|
const results = await this.Action('schema', 'sync').execute({})
|
|
23
28
|
|
|
24
29
|
const match = testUtil.assertFileByNameInGeneratedFiles(
|
|
@@ -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
|
|
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
|
|
25
|
+
const files = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
|
|
26
26
|
|
|
27
|
-
assert.isLength(
|
|
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
|
|
48
|
+
const files = fsUtil.readdirSync(this.resolveHashSprucePath('events'))
|
|
47
49
|
|
|
48
|
-
assert.isLength(
|
|
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({
|
|
@@ -52,18 +52,21 @@ export default class CreatingAListenerTest extends AbstractEventTest {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
@test()
|
|
55
|
-
protected static async
|
|
56
|
-
const
|
|
55
|
+
protected static async generatesMapFile() {
|
|
56
|
+
const { results } = await this.installEventsAndCreateListener()
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const match = testUtil.assertFileByNameInGeneratedFiles(
|
|
59
|
+
`listeners.ts`,
|
|
60
|
+
results.files
|
|
61
|
+
)
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
eventName: 'will-boot',
|
|
63
|
-
version,
|
|
64
|
-
})
|
|
63
|
+
await this.Service('typeChecker').check(match)
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
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
|
) {
|
|
@@ -79,7 +79,7 @@ export default class KeepingEventsInSyncTest extends AbstractEventTest {
|
|
|
79
79
|
|
|
80
80
|
await this.Service('build').build()
|
|
81
81
|
|
|
82
|
-
const health = await cli.checkHealth({
|
|
82
|
+
const health = await cli.checkHealth({ shouldRunOnSourceFiles: false })
|
|
83
83
|
|
|
84
84
|
assert.isTruthy(health.skill)
|
|
85
85
|
assert.isFalsy(health.skill.errors)
|
|
@@ -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')
|
|
@@ -84,7 +84,7 @@ export default class UpgradingASkill2Test extends AbstractCliTest {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
@test()
|
|
87
|
-
protected static async
|
|
87
|
+
protected static async callsCleanFixAndBuildDev() {
|
|
88
88
|
await this.FeatureFixture().installCachedFeatures('skills')
|
|
89
89
|
|
|
90
90
|
let wasCleanBuildCalled = false
|
|
@@ -92,7 +92,6 @@ export default class UpgradingASkill2Test extends AbstractCliTest {
|
|
|
92
92
|
return {}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
let wasFixLintCalled = false
|
|
96
95
|
CommandService.setMockResponse('yarn clean.build', {
|
|
97
96
|
code: 0,
|
|
98
97
|
callback: () => {
|
|
@@ -100,13 +99,6 @@ export default class UpgradingASkill2Test extends AbstractCliTest {
|
|
|
100
99
|
},
|
|
101
100
|
})
|
|
102
101
|
|
|
103
|
-
CommandService.setMockResponse('yarn fix.lint', {
|
|
104
|
-
code: 0,
|
|
105
|
-
callback: () => {
|
|
106
|
-
wasFixLintCalled = true
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
|
|
110
102
|
let wasBuildDevCalled = false
|
|
111
103
|
|
|
112
104
|
CommandService.setMockResponse('yarn build.dev', {
|
|
@@ -121,7 +113,6 @@ export default class UpgradingASkill2Test extends AbstractCliTest {
|
|
|
121
113
|
assert.isFalsy(results.errors)
|
|
122
114
|
assert.isTrue(wasCleanBuildCalled)
|
|
123
115
|
assert.isTrue(wasBuildDevCalled)
|
|
124
|
-
assert.isTrue(wasFixLintCalled)
|
|
125
116
|
}
|
|
126
117
|
|
|
127
118
|
@test()
|
|
@@ -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
|
+
}
|
package/src/__tests__/behavioral/{CreatingADataStore.test.ts → stores/CreatingADataStore.test.ts}
RENAMED
|
@@ -2,9 +2,9 @@ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
|
|
|
2
2
|
import { test, assert } from '@sprucelabs/test'
|
|
3
3
|
import { errorAssertUtil } from '@sprucelabs/test-utils'
|
|
4
4
|
import '@sprucelabs/spruce-store-plugin'
|
|
5
|
-
import CommandService from '
|
|
6
|
-
import AbstractSkillTest from '
|
|
7
|
-
import testUtil from '
|
|
5
|
+
import CommandService from '../../../services/CommandService'
|
|
6
|
+
import AbstractSkillTest from '../../../tests/AbstractSkillTest'
|
|
7
|
+
import testUtil from '../../../tests/utilities/test.utility'
|
|
8
8
|
|
|
9
9
|
export default class CreatingDataStoresTest extends AbstractSkillTest {
|
|
10
10
|
protected static skillCacheKey = 'stores'
|
|
@@ -16,7 +16,7 @@ export default class CreatingDataStoresTest extends AbstractSkillTest {
|
|
|
16
16
|
|
|
17
17
|
@test()
|
|
18
18
|
protected static async getsNoStoresBackFromHealthCheck() {
|
|
19
|
-
const health = await this.cli.checkHealth({
|
|
19
|
+
const health = await this.cli.checkHealth({ shouldRunOnSourceFiles: true })
|
|
20
20
|
|
|
21
21
|
assert.isFalsy(health.skill.errors)
|
|
22
22
|
assert.isTruthy(health.store)
|
|
@@ -43,9 +43,16 @@ export default class CreatingDataStoresTest extends AbstractSkillTest {
|
|
|
43
43
|
await this.Service('typeChecker').check(path)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
@test()
|
|
47
|
+
protected static async generatesAMapFile() {
|
|
48
|
+
const file = this.resolveHashSprucePath('stores', 'stores.ts')
|
|
49
|
+
assert.isTrue(diskUtil.doesFileExist(file))
|
|
50
|
+
await this.Service('typeChecker').check(file)
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
@test()
|
|
47
54
|
protected static async getsOneStoresBackFromHealthCheck() {
|
|
48
|
-
const health = await this.cli.checkHealth({
|
|
55
|
+
const health = await this.cli.checkHealth({ shouldRunOnSourceFiles: true })
|
|
49
56
|
assert.isTruthy(health.store)
|
|
50
57
|
assert.isFalsy(health.store.errors)
|
|
51
58
|
assert.isLength(health.store.stores, 1)
|
|
@@ -72,7 +79,7 @@ export default class CreatingDataStoresTest extends AbstractSkillTest {
|
|
|
72
79
|
|
|
73
80
|
@test()
|
|
74
81
|
protected static async getsSecondStoresBackFromHealthCheck() {
|
|
75
|
-
const health = await this.cli.checkHealth({
|
|
82
|
+
const health = await this.cli.checkHealth({ shouldRunOnSourceFiles: true })
|
|
76
83
|
|
|
77
84
|
assert.isTruthy(health.store)
|
|
78
85
|
assert.isFalsy(health.store.errors)
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
|
5
|
-
import
|
|
4
|
+
import { FeatureActionResponse } from '../../../features/features.types'
|
|
5
|
+
import AbstractSkillTest from '../../../tests/AbstractSkillTest'
|
|
6
|
+
import testUtil from '../../../tests/utilities/test.utility'
|
|
6
7
|
|
|
7
8
|
export default class KeepingDataStoresInSyncTest extends AbstractSkillTest {
|
|
8
9
|
protected static skillCacheKey = 'stores'
|
|
@@ -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
|
-
|
|
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',
|