@sprucelabs/spruce-cli 28.2.3 → 29.0.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.
Files changed (226) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/.spruce/errors/errors.types.d.ts +23 -2
  3. package/build/.spruce/errors/options.types.d.ts +4 -1
  4. package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.d.ts +3 -0
  5. package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.js +20 -0
  6. package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.js.map +1 -0
  7. package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.d.ts +7 -2
  8. package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.js +36 -13
  9. package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.js.map +1 -1
  10. package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.d.ts +5 -0
  11. package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.js +32 -0
  12. package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.js.map +1 -0
  13. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.d.ts +5 -0
  14. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js +21 -13
  15. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js.map +1 -1
  16. package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.d.ts +1 -1
  17. package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.js +7 -7
  18. package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.js.map +1 -1
  19. package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.d.ts +39 -0
  20. package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.js +289 -0
  21. package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.js.map +1 -0
  22. package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.d.ts +7 -0
  23. package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.js +46 -0
  24. package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.js.map +1 -0
  25. package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.d.ts +5 -0
  26. package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.js +31 -0
  27. package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.js.map +1 -0
  28. package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js +1 -1
  29. package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js.map +1 -1
  30. package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js +10 -1
  31. package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js.map +1 -1
  32. package/build/__tests__/implementation/SkillStore.test.d.ts +5 -0
  33. package/build/__tests__/implementation/SkillStore.test.js +37 -0
  34. package/build/__tests__/implementation/SkillStore.test.js.map +1 -1
  35. package/build/__tests__/support/EventFaker.d.ts +4 -0
  36. package/build/__tests__/support/EventFaker.js +16 -0
  37. package/build/__tests__/support/EventFaker.js.map +1 -1
  38. package/build/cli/Cli.js +12 -9
  39. package/build/cli/Cli.js.map +1 -1
  40. package/build/errors/SpruceError.js +3 -0
  41. package/build/errors/SpruceError.js.map +1 -1
  42. package/build/errors/directoryNotGoModule.builder.d.ts +12 -0
  43. package/build/errors/directoryNotGoModule.builder.js +15 -0
  44. package/build/errors/directoryNotGoModule.builder.js.map +1 -0
  45. package/build/features/AbstractAction.d.ts +1 -0
  46. package/build/features/AbstractAction.js +5 -1
  47. package/build/features/AbstractAction.js.map +1 -1
  48. package/build/features/AbstractFeature.d.ts +8 -1
  49. package/build/features/AbstractFeature.js +12 -1
  50. package/build/features/AbstractFeature.js.map +1 -1
  51. package/build/features/ActionFactory.js +1 -2
  52. package/build/features/ActionFactory.js.map +1 -1
  53. package/build/features/ActionQuestionAsker.js +0 -1
  54. package/build/features/ActionQuestionAsker.js.map +1 -1
  55. package/build/features/FeatureInstaller.d.ts +1 -0
  56. package/build/features/FeatureInstaller.js +21 -7
  57. package/build/features/FeatureInstaller.js.map +1 -1
  58. package/build/features/FeatureInstallerFactory.d.ts +1 -0
  59. package/build/features/FeatureInstallerFactory.js +7 -0
  60. package/build/features/FeatureInstallerFactory.js.map +1 -1
  61. package/build/features/OverrideActionDecorator.js +1 -1
  62. package/build/features/OverrideActionDecorator.js.map +1 -1
  63. package/build/features/VersionResolver.js +1 -1
  64. package/build/features/VersionResolver.js.map +1 -1
  65. package/build/features/agent/AgentFeature.d.ts +1 -1
  66. package/build/features/agent/AgentFeature.js +1 -1
  67. package/build/features/agent/AgentFeature.js.map +1 -1
  68. package/build/features/conversation/ConversationFeature.d.ts +1 -1
  69. package/build/features/conversation/ConversationFeature.js +1 -1
  70. package/build/features/conversation/ConversationFeature.js.map +1 -1
  71. package/build/features/dependencies/DependencyFeature.d.ts +0 -1
  72. package/build/features/dependencies/DependencyFeature.js +0 -1
  73. package/build/features/dependencies/DependencyFeature.js.map +1 -1
  74. package/build/features/deploy/DeployFeature.d.ts +1 -1
  75. package/build/features/deploy/DeployFeature.js +1 -1
  76. package/build/features/deploy/DeployFeature.js.map +1 -1
  77. package/build/features/error/ErrorFeature.d.ts +1 -1
  78. package/build/features/error/ErrorFeature.js +1 -1
  79. package/build/features/error/ErrorFeature.js.map +1 -1
  80. package/build/features/event/EventFeature.d.ts +1 -1
  81. package/build/features/event/EventFeature.js +1 -1
  82. package/build/features/event/EventFeature.js.map +1 -1
  83. package/build/features/eventContract/EventContractFeature.d.ts +1 -3
  84. package/build/features/eventContract/EventContractFeature.js +0 -2
  85. package/build/features/eventContract/EventContractFeature.js.map +1 -1
  86. package/build/features/node/NodeFeature.d.ts +1 -1
  87. package/build/features/node/NodeFeature.js +1 -1
  88. package/build/features/node/NodeFeature.js.map +1 -1
  89. package/build/features/onboard/OnboardFeature.d.ts +1 -3
  90. package/build/features/onboard/OnboardFeature.js +0 -2
  91. package/build/features/onboard/OnboardFeature.js.map +1 -1
  92. package/build/features/organization/OrganizationFeature.d.ts +0 -1
  93. package/build/features/organization/OrganizationFeature.js +0 -1
  94. package/build/features/organization/OrganizationFeature.js.map +1 -1
  95. package/build/features/permission/PermissionFeature.d.ts +2 -3
  96. package/build/features/permission/PermissionFeature.js +1 -2
  97. package/build/features/permission/PermissionFeature.js.map +1 -1
  98. package/build/features/person/PersonFeature.d.ts +1 -3
  99. package/build/features/person/PersonFeature.js +0 -2
  100. package/build/features/person/PersonFeature.js.map +1 -1
  101. package/build/features/polish/PolishFeature.d.ts +1 -1
  102. package/build/features/polish/PolishFeature.js +1 -1
  103. package/build/features/polish/PolishFeature.js.map +1 -1
  104. package/build/features/sandbox/SandboxFeature.d.ts +0 -1
  105. package/build/features/sandbox/SandboxFeature.js +0 -1
  106. package/build/features/sandbox/SandboxFeature.js.map +1 -1
  107. package/build/features/schema/SchemaFeature.d.ts +2 -3
  108. package/build/features/schema/SchemaFeature.js +6 -1
  109. package/build/features/schema/SchemaFeature.js.map +1 -1
  110. package/build/features/schema/actions/SyncAction.d.ts +5 -2
  111. package/build/features/schema/actions/SyncAction.js +50 -16
  112. package/build/features/schema/actions/SyncAction.js.map +1 -1
  113. package/build/features/schema/utilities/schemaDisk.utility.d.ts +7 -0
  114. package/build/features/schema/utilities/schemaDisk.utility.js +22 -4
  115. package/build/features/schema/utilities/schemaDisk.utility.js.map +1 -1
  116. package/build/features/schema/utilities/schemaGenerator.utility.d.ts +1 -0
  117. package/build/features/schema/utilities/schemaGenerator.utility.js +18 -10
  118. package/build/features/schema/utilities/schemaGenerator.utility.js.map +1 -1
  119. package/build/features/schema/writers/SchemaWriter.d.ts +9 -9
  120. package/build/features/schema/writers/SchemaWriter.js +38 -17
  121. package/build/features/schema/writers/SchemaWriter.js.map +1 -1
  122. package/build/features/skill/SkillFeature.d.ts +1 -1
  123. package/build/features/skill/SkillFeature.js +1 -1
  124. package/build/features/skill/SkillFeature.js.map +1 -1
  125. package/build/features/skill/stores/SkillStore.d.ts +4 -0
  126. package/build/features/skill/stores/SkillStore.js +37 -3
  127. package/build/features/skill/stores/SkillStore.js.map +1 -1
  128. package/build/features/store/StoreFeature.d.ts +1 -1
  129. package/build/features/store/StoreFeature.js +1 -1
  130. package/build/features/store/StoreFeature.js.map +1 -1
  131. package/build/features/test/TestFeature.d.ts +1 -1
  132. package/build/features/test/TestFeature.js +1 -1
  133. package/build/features/test/TestFeature.js.map +1 -1
  134. package/build/features/test/TestReporter.js +1 -1
  135. package/build/features/test/TestReporter.js.map +1 -1
  136. package/build/features/view/ViewFeature.d.ts +1 -1
  137. package/build/features/view/ViewFeature.js +1 -1
  138. package/build/features/view/ViewFeature.js.map +1 -1
  139. package/build/migration/EsLint9Migrator.d.ts +1 -0
  140. package/build/packageManager/NodePackageManager.d.ts +14 -0
  141. package/build/packageManager/NodePackageManager.js +88 -0
  142. package/build/packageManager/NodePackageManager.js.map +1 -0
  143. package/build/packageManager/packageManager.types.d.ts +16 -0
  144. package/build/packageManager/packageManager.types.js +3 -0
  145. package/build/packageManager/packageManager.types.js.map +1 -0
  146. package/build/services/GoPackageManager.d.ts +10 -0
  147. package/build/services/GoPackageManager.js +39 -0
  148. package/build/services/GoPackageManager.js.map +1 -0
  149. package/build/services/PkgService.d.ts +3 -7
  150. package/build/services/PkgService.js +13 -68
  151. package/build/services/PkgService.js.map +1 -1
  152. package/build/templateItemBuilders/SchemaTemplateItemBuilder.js.map +1 -1
  153. package/build/tests/AbstractCliTest.d.ts +5 -1
  154. package/build/tests/AbstractCliTest.js +15 -3
  155. package/build/tests/AbstractCliTest.js.map +1 -1
  156. package/build/tests/fixtures/FeatureFixture.js +4 -1
  157. package/build/tests/fixtures/FeatureFixture.js.map +1 -1
  158. package/build/tests/fixtures/GoFixture.d.ts +12 -0
  159. package/build/tests/fixtures/GoFixture.js +39 -0
  160. package/build/tests/fixtures/GoFixture.js.map +1 -0
  161. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.d.ts +1 -0
  162. package/build/widgets/terminalKit/TkTextWidget.js +1 -1
  163. package/build/widgets/terminalKit/TkTextWidget.js.map +1 -1
  164. package/build/writers/AbstractWriter.js +7 -6
  165. package/build/writers/AbstractWriter.js.map +1 -1
  166. package/package.json +29 -29
  167. package/src/.spruce/errors/errors.types.ts +32 -2
  168. package/src/.spruce/errors/options.types.ts +4 -1
  169. package/src/.spruce/errors/spruceCli/directoryNotGoModule.schema.ts +23 -0
  170. package/src/__tests__/behavioral/OverridingCommandsInPackageJson.test.ts +60 -13
  171. package/src/__tests__/behavioral/features/InstallFeaturesInGo.test.ts +17 -0
  172. package/src/__tests__/behavioral/organization/CreatingAnOrg.test.ts +29 -22
  173. package/src/__tests__/behavioral/schemas/KeepingSchemasInSync.test.ts +6 -9
  174. package/src/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.ts +376 -0
  175. package/src/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.ts +46 -0
  176. package/src/__tests__/behavioral/schemas/SyncingSchemasInGo.test.ts +23 -0
  177. package/src/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.ts +1 -1
  178. package/src/__tests__/behavioral/upgrading/UpdatingDependencies2.test.ts +15 -2
  179. package/src/__tests__/implementation/SkillStore.test.ts +44 -1
  180. package/src/__tests__/support/EventFaker.ts +29 -0
  181. package/src/cli/Cli.ts +20 -12
  182. package/src/errors/SpruceError.ts +4 -0
  183. package/src/errors/directoryNotGoModule.builder.ts +13 -0
  184. package/src/features/AbstractAction.ts +6 -4
  185. package/src/features/AbstractFeature.ts +20 -1
  186. package/src/features/ActionFactory.ts +2 -2
  187. package/src/features/ActionQuestionAsker.ts +0 -1
  188. package/src/features/FeatureInstaller.ts +30 -6
  189. package/src/features/FeatureInstallerFactory.ts +9 -0
  190. package/src/features/OverrideActionDecorator.ts +1 -1
  191. package/src/features/VersionResolver.ts +2 -1
  192. package/src/features/agent/AgentFeature.ts +1 -1
  193. package/src/features/conversation/ConversationFeature.ts +1 -1
  194. package/src/features/dependencies/DependencyFeature.ts +0 -1
  195. package/src/features/deploy/DeployFeature.ts +1 -1
  196. package/src/features/error/ErrorFeature.ts +1 -1
  197. package/src/features/event/EventFeature.ts +1 -1
  198. package/src/features/eventContract/EventContractFeature.ts +1 -3
  199. package/src/features/node/NodeFeature.ts +1 -1
  200. package/src/features/onboard/OnboardFeature.ts +1 -7
  201. package/src/features/organization/OrganizationFeature.ts +0 -1
  202. package/src/features/permission/PermissionFeature.ts +1 -3
  203. package/src/features/person/PersonFeature.ts +1 -4
  204. package/src/features/polish/PolishFeature.ts +1 -1
  205. package/src/features/sandbox/SandboxFeature.ts +0 -1
  206. package/src/features/schema/SchemaFeature.ts +8 -2
  207. package/src/features/schema/actions/SyncAction.ts +68 -26
  208. package/src/features/schema/utilities/schemaDisk.utility.ts +43 -11
  209. package/src/features/schema/utilities/schemaGenerator.utility.ts +33 -13
  210. package/src/features/schema/writers/SchemaWriter.ts +71 -25
  211. package/src/features/skill/SkillFeature.ts +1 -1
  212. package/src/features/skill/stores/SkillStore.ts +47 -5
  213. package/src/features/store/StoreFeature.ts +1 -1
  214. package/src/features/test/TestFeature.ts +1 -1
  215. package/src/features/test/TestReporter.ts +1 -1
  216. package/src/features/view/ViewFeature.ts +1 -1
  217. package/src/packageManager/NodePackageManager.ts +115 -0
  218. package/src/packageManager/packageManager.types.ts +21 -0
  219. package/src/services/GoPackageManager.ts +45 -0
  220. package/src/services/PkgService.ts +17 -92
  221. package/src/templateItemBuilders/SchemaTemplateItemBuilder.ts +6 -6
  222. package/src/tests/AbstractCliTest.ts +19 -5
  223. package/src/tests/fixtures/FeatureFixture.ts +3 -1
  224. package/src/tests/fixtures/GoFixture.ts +39 -0
  225. package/src/widgets/terminalKit/TkTextWidget.ts +1 -1
  226. package/src/writers/AbstractWriter.ts +15 -6
@@ -14,9 +14,6 @@ import { FeatureActionResponse } from '../../features.types'
14
14
  import schemaDiskUtil from '../utilities/schemaDisk.utility'
15
15
  import ValueTypeBuilder from '../ValueTypeBuilder'
16
16
 
17
- type OptionsSchema =
18
- SpruceSchemas.SpruceCli.v2020_07_22.SyncSchemasOptionsSchema
19
- type Options = SpruceSchemas.SpruceCli.v2020_07_22.SyncSchemasOptions
20
17
  export default class SyncAction extends AbstractAction<OptionsSchema> {
21
18
  public optionsSchema = syncSchemasActionSchema
22
19
  public commandAliases = ['sync.schemas']
@@ -24,12 +21,10 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
24
21
 
25
22
  private readonly schemaWriter = this.Writer('schema')
26
23
  private readonly schemaStore = this.Store('schema')
24
+ private readonly skillStore = this.Store('skill')
27
25
 
28
26
  public async execute(options: Options): Promise<FeatureActionResponse> {
29
27
  const normalizedOptions = this.validateAndNormalizeOptions(options)
30
- const isInCoreSchemasModule =
31
- this.Service('pkg').get('name') ===
32
- '@sprucelabs/spruce-core-schemas'
33
28
 
34
29
  let {
35
30
  schemaTypesDestinationDirOrFile,
@@ -39,7 +34,7 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
39
34
  shouldEnableVersioning,
40
35
  globalSchemaNamespace,
41
36
  shouldFetchRemoteSchemas,
42
- shouldGenerateCoreSchemaTypes = isInCoreSchemasModule,
37
+ shouldGenerateCoreSchemaTypes,
43
38
  shouldFetchLocalSchemas,
44
39
  generateFieldTypes,
45
40
  generateStandaloneTypesFile,
@@ -54,8 +49,7 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
54
49
 
55
50
  this.ui.startLoading('Loading details about your skill... 🧐')
56
51
 
57
- let localNamespace =
58
- await this.Store('skill').loadCurrentSkillsNamespace()
52
+ let localNamespace = await this.skillStore.loadCurrentSkillsNamespace()
59
53
  let shouldImportCoreSchemas = true
60
54
 
61
55
  if (shouldGenerateCoreSchemaTypes) {
@@ -79,6 +73,7 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
79
73
  generateStandaloneTypesFile,
80
74
  schemaTypesDestinationDirOrFile,
81
75
  fieldTypesDestinationDir,
76
+ language: this.getProjectLanguage(),
82
77
  })
83
78
 
84
79
  this.ui.startLoading('Generating field types...')
@@ -125,7 +120,6 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
125
120
 
126
121
  if (deleteOrphanedSchemas) {
127
122
  this.ui.startLoading('Identifying orphaned schemas...')
128
-
129
123
  await schemaDiskUtil.deleteOrphanedSchemas(
130
124
  resolvedSchemaTypesDestinationDirOrFile,
131
125
  schemaTemplateItems
@@ -140,20 +134,30 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
140
134
  let valueTypes: ValueTypes | undefined
141
135
 
142
136
  try {
143
- valueTypes = await this.generateValueTypes({
144
- resolvedDestination: resolvedFieldTypesDestination,
145
- fieldTemplateItems,
146
- schemaTemplateItems,
147
- globalSchemaNamespace: globalSchemaNamespace ?? undefined,
148
- })
137
+ valueTypes = this.isInGoProject()
138
+ ? undefined
139
+ : await this.generateValueTypes({
140
+ resolvedDestination: resolvedFieldTypesDestination,
141
+ fieldTemplateItems,
142
+ schemaTemplateItems,
143
+ globalSchemaNamespace:
144
+ globalSchemaNamespace ?? undefined,
145
+ })
149
146
  } catch (err: any) {
150
147
  schemaErrors.push(err)
151
148
  }
152
149
 
153
- if (valueTypes) {
150
+ if (valueTypes || this.isInGoProject()) {
154
151
  try {
155
152
  this.ui.startLoading('Determining what changed... ⚡️')
156
153
 
154
+ let goModuleNameAndPath: string | undefined = undefined
155
+ if (this.isInGoProject()) {
156
+ goModuleNameAndPath = this.skillStore.getGoModuleName({
157
+ shouldIncludePathFromCwd: true,
158
+ })
159
+ }
160
+
157
161
  typeResults = await this.schemaWriter.writeSchemasAndTypes(
158
162
  resolvedSchemaTypesDestination,
159
163
  {
@@ -162,11 +166,13 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
162
166
  schemaTemplateItems,
163
167
  shouldImportCoreSchemas,
164
168
  valueTypes,
169
+ goModuleNameAndPath,
170
+ language: this.getProjectLanguage(),
165
171
  globalSchemaNamespace:
166
172
  globalSchemaNamespace ?? undefined,
167
- typesTemplate: generateStandaloneTypesFile
168
- ? 'schema/core.schemas.types.ts.hbs'
169
- : undefined,
173
+ typesTemplate: this.resolveTypesTemplate(
174
+ generateStandaloneTypesFile
175
+ ),
170
176
  }
171
177
  )
172
178
  } catch (err: any) {
@@ -176,7 +182,10 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
176
182
  }
177
183
 
178
184
  const p = resolvedSchemaTypesDestination
179
- diskUtil.deleteEmptyDirs(diskUtil.isDir(p) ? p : pathUtil.dirname(p))
185
+ const dir = diskUtil.isDir(p) ? p : pathUtil.dirname(p)
186
+ if (diskUtil.doesDirExist(dir)) {
187
+ diskUtil.deleteEmptyDirs(dir)
188
+ }
180
189
 
181
190
  this.ui.stopLoading()
182
191
 
@@ -192,6 +201,18 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
192
201
  })
193
202
  }
194
203
 
204
+ private resolveTypesTemplate(
205
+ generateStandaloneTypesFile: boolean
206
+ ): string | undefined {
207
+ if (this.isInGoProject()) {
208
+ return 'schema/schemas.go.hbs'
209
+ }
210
+
211
+ return generateStandaloneTypesFile
212
+ ? 'schema/core.schemas.types.ts.hbs'
213
+ : undefined
214
+ }
215
+
195
216
  private async optionallyInstallRemoteModules(
196
217
  schemaTemplateItems: SchemaTemplateItem[],
197
218
  forceInstall?: boolean
@@ -202,6 +223,10 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
202
223
  .filter((i) => !!i)
203
224
  ) as string[]
204
225
 
226
+ if (this.isInGoProject()) {
227
+ return
228
+ }
229
+
205
230
  const notInstalled: string[] = []
206
231
 
207
232
  const pkg = this.Service('pkg')
@@ -287,11 +312,12 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
287
312
  },
288
313
  })
289
314
 
290
- const hashSpruceDestination =
291
- resolvedSchemaTypesDestinationDirOrFile.replace(
292
- diskUtil.resolveHashSprucePath(this.cwd),
293
- '#spruce'
294
- )
315
+ const hashSpruceDestination = this.isInGoProject()
316
+ ? this.cwd
317
+ : resolvedSchemaTypesDestinationDirOrFile.replace(
318
+ diskUtil.resolveHashSprucePath(this.cwd),
319
+ '#spruce'
320
+ )
295
321
 
296
322
  let total = 0
297
323
  let totalNamespaces = 0
@@ -317,11 +343,23 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
317
343
  return { schemaTemplateItems, schemaErrors }
318
344
  }
319
345
 
346
+ private isInGoProject() {
347
+ return this.getProjectLanguage() === 'go'
348
+ }
349
+
320
350
  private async generateFieldTemplateItems(options: {
321
351
  addonsLookupDir: string
322
352
  shouldGenerateFieldTypes: boolean
323
353
  resolvedFieldTypesDestination: string
324
354
  }) {
355
+ if (this.isInGoProject()) {
356
+ return {
357
+ generateFieldFiles: [],
358
+ fieldTemplateItems: [],
359
+ fieldErrors: [],
360
+ }
361
+ }
362
+
325
363
  const {
326
364
  addonsLookupDir,
327
365
  shouldGenerateFieldTypes: generateFieldTypes,
@@ -358,3 +396,7 @@ export default class SyncAction extends AbstractAction<OptionsSchema> {
358
396
  return builder.generateValueTypes(options)
359
397
  }
360
398
  }
399
+
400
+ type OptionsSchema =
401
+ SpruceSchemas.SpruceCli.v2020_07_22.SyncSchemasOptionsSchema
402
+ type Options = SpruceSchemas.SpruceCli.v2020_07_22.SyncSchemasOptions
@@ -1,6 +1,10 @@
1
1
  import pathUtil from 'path'
2
2
  import { Schema, SchemaError, SchemaTemplateItem } from '@sprucelabs/schema'
3
- import { diskUtil, namesUtil } from '@sprucelabs/spruce-skill-utils'
3
+ import {
4
+ diskUtil,
5
+ namesUtil,
6
+ ProjectLanguage,
7
+ } from '@sprucelabs/spruce-skill-utils'
4
8
  import schemaGeneratorUtil from './schemaGenerator.utility'
5
9
 
6
10
  const schemaDiskUtil = {
@@ -8,25 +12,29 @@ const schemaDiskUtil = {
8
12
  destination: string
9
13
  schema: Schema
10
14
  shouldIncludeFileExtension?: boolean
15
+ language?: ProjectLanguage
11
16
  }) {
12
- const {
13
- destination,
14
- schema,
15
- shouldIncludeFileExtension: includeFileExtension,
16
- } = options
17
+ const { destination, schema, shouldIncludeFileExtension, language } =
18
+ options
17
19
 
18
20
  if (!schema.namespace) {
19
21
  throw new SchemaError({
20
22
  code: 'MISSING_PARAMETERS',
21
23
  parameters: ['namespace'],
24
+ friendlyMessage: `Schema with id "${schema.id}" is missing a namespace so it can not be written to disk.`,
22
25
  })
23
26
  }
24
27
 
28
+ const name =
29
+ language == 'go'
30
+ ? `${namesUtil.toSnake(schema.id)}.go`
31
+ : `${schema.id}.schema${shouldIncludeFileExtension === false ? '' : '.ts'}`
32
+
25
33
  return pathUtil.join(
26
34
  destination,
27
35
  namesUtil.toCamel(schema.namespace),
28
36
  schema.version ?? '',
29
- `${schema.id}.schema${includeFileExtension === false ? '' : '.ts'}`
37
+ name
30
38
  )
31
39
  },
32
40
 
@@ -35,23 +43,32 @@ const schemaDiskUtil = {
35
43
  generateStandaloneTypesFile: boolean
36
44
  schemaTypesDestinationDirOrFile: string
37
45
  fieldTypesDestinationDir: string
46
+ language: ProjectLanguage
38
47
  }) {
39
- const {
48
+ let {
40
49
  cwd,
41
50
  generateStandaloneTypesFile,
42
51
  schemaTypesDestinationDirOrFile,
43
52
  fieldTypesDestinationDir,
53
+ language,
44
54
  } = options
45
55
 
56
+ if (
57
+ language === 'go' &&
58
+ !generateStandaloneTypesFile &&
59
+ schemaTypesDestinationDirOrFile === '#spruce/schemas'
60
+ ) {
61
+ schemaTypesDestinationDirOrFile = 'schemas/schemas.go'
62
+ }
63
+
46
64
  const resolvedSchemaTypesDestination = diskUtil.resolvePath(
47
65
  cwd,
48
66
  generateStandaloneTypesFile &&
49
67
  diskUtil.isDirPath(schemaTypesDestinationDirOrFile)
50
- ? diskUtil.resolvePath(
68
+ ? this.resolveStandaloneSchemaTypesFilePath({
51
69
  cwd,
52
70
  schemaTypesDestinationDirOrFile,
53
- 'core.schemas.types.ts'
54
- )
71
+ })
55
72
  : schemaTypesDestinationDirOrFile
56
73
  )
57
74
 
@@ -73,6 +90,21 @@ const schemaDiskUtil = {
73
90
  }
74
91
  },
75
92
 
93
+ resolveStandaloneSchemaTypesFilePath(options: {
94
+ cwd: string
95
+ schemaTypesDestinationDirOrFile: string
96
+ }) {
97
+ const { cwd, schemaTypesDestinationDirOrFile } = options
98
+
99
+ return diskUtil.resolvePath(
100
+ cwd,
101
+ schemaTypesDestinationDirOrFile,
102
+ diskUtil.detectProjectLanguage(cwd) === 'go'
103
+ ? '../../schemas/core_schemas.go'
104
+ : 'core.schemas.types.ts'
105
+ )
106
+ },
107
+
76
108
  async deleteOrphanedSchemas(
77
109
  resolvedDestination: string,
78
110
  schemaTemplateItems: SchemaTemplateItem[]
@@ -7,26 +7,27 @@ const schemaGeneratorUtil = {
7
7
  lookupDir: string,
8
8
  schemas: { id: string; namespace?: string; version?: string }[]
9
9
  ): Promise<string[]> {
10
- const matches = await globby(
11
- pathUtil.join(lookupDir, '/**/*.schema.[t|j]s')
12
- )
10
+ const matches = await globby([
11
+ pathUtil.join(lookupDir, '/**/*.schema.[t|j]s'),
12
+ pathUtil.join(lookupDir, '/*/v*/*.go'),
13
+ ])
14
+
13
15
  const filtered = matches.filter((match) => {
14
16
  let found = false
15
17
 
16
18
  for (const schema of schemas) {
17
19
  const { id, namespace, version } = schema
18
- let regexString = `${pathUtil.sep}${id}.schema.[t|j]s`
19
20
 
20
- if (version) {
21
- regexString = pathUtil.sep + version + regexString
22
- }
21
+ const expectedPath = match.endsWith('.go')
22
+ ? this.buildPath(
23
+ namesUtil.toSnake(id),
24
+ '.go',
25
+ namespace,
26
+ version
27
+ )
28
+ : this.buildPath(id, '.schema.', namespace, version)
23
29
 
24
- if (namespace) {
25
- regexString = namesUtil.toCamel(namespace) + regexString
26
- }
27
-
28
- const idx = match.search(new RegExp(regexString))
29
- if (idx > -1) {
30
+ if (match.includes(expectedPath)) {
30
31
  found = true
31
32
  break
32
33
  }
@@ -36,6 +37,25 @@ const schemaGeneratorUtil = {
36
37
  })
37
38
  return filtered
38
39
  },
40
+
41
+ buildPath(
42
+ schemaId: string,
43
+ suffix: string,
44
+ namespace?: string,
45
+ version?: string
46
+ ): string {
47
+ let path = pathUtil.sep + schemaId + suffix
48
+
49
+ if (version) {
50
+ path = pathUtil.sep + version + path
51
+ }
52
+
53
+ if (namespace) {
54
+ path = namesUtil.toCamel(namespace) + path
55
+ }
56
+
57
+ return path
58
+ },
39
59
  }
40
60
 
41
61
  export default schemaGeneratorUtil
@@ -1,7 +1,7 @@
1
1
  import path from 'path'
2
2
  import pathUtil from 'path'
3
3
  import { FieldTemplateItem, SchemaTemplateItem } from '@sprucelabs/schema'
4
- import { versionUtil } from '@sprucelabs/spruce-skill-utils'
4
+ import { ProjectLanguage, versionUtil } from '@sprucelabs/spruce-skill-utils'
5
5
  import { diskUtil } from '@sprucelabs/spruce-skill-utils'
6
6
  import {
7
7
  LATEST_HANDLEBARS,
@@ -110,13 +110,17 @@ export default class SchemaWriter extends AbstractWriter {
110
110
 
111
111
  public async writeSchemasAndTypes(
112
112
  destinationDirOrFilename: string,
113
- options: GenerateSchemaTypesOptions
113
+ options: Omit<GenerateSchemaTypesOptions, 'valueTypes'> & {
114
+ valueTypes?: ValueTypes
115
+ goModuleNameAndPath?: string
116
+ }
114
117
  ): Promise<WriteResults> {
115
118
  const {
116
119
  fieldTemplateItems,
117
120
  schemaTemplateItems,
118
121
  valueTypes,
119
122
  typesTemplate,
123
+ language,
120
124
  } = options
121
125
 
122
126
  this.isLintEnabled = false
@@ -132,7 +136,8 @@ export default class SchemaWriter extends AbstractWriter {
132
136
  const localItems = schemaTemplateItems.filter((i) => !i.importFrom)
133
137
 
134
138
  if (localItems.length > 0) {
135
- const schemaTypesContents = this.templates.schemasTypes({
139
+ let schemaTypesContents = this.templates.schemasTypes({
140
+ language: language === 'go' ? 'go' : 'typescript',
136
141
  schemaTemplateItems: localItems,
137
142
  fieldTemplateItems,
138
143
  valueTypes,
@@ -140,6 +145,17 @@ export default class SchemaWriter extends AbstractWriter {
140
145
  typesTemplate,
141
146
  })
142
147
 
148
+ if (language === 'go') {
149
+ const referencesSchemaType =
150
+ schemaTypesContents.split('SpruceSchema.')
151
+ if (referencesSchemaType.length === 1) {
152
+ schemaTypesContents = schemaTypesContents.replace(
153
+ 'import SpruceSchema "github.com/sprucelabsai-community/spruce-schema/v32/pkg/fields"',
154
+ ''
155
+ )
156
+ }
157
+ }
158
+
143
159
  results = await this.writeFileIfChangedMixinResults(
144
160
  resolvedTypesDestination,
145
161
  schemaTypesContents,
@@ -154,7 +170,7 @@ export default class SchemaWriter extends AbstractWriter {
154
170
  const allSchemaResults = await this.writeAllSchemas(
155
171
  pathUtil.dirname(resolvedTypesDestination),
156
172
  {
157
- ...options,
173
+ ...(options as GenerateSchemaTypesOptions),
158
174
  typesFile: resolvedTypesDestination,
159
175
  }
160
176
  )
@@ -172,52 +188,61 @@ export default class SchemaWriter extends AbstractWriter {
172
188
  destinationDir: string,
173
189
  options: GenerateSchemaTypesOptions & { typesFile?: string }
174
190
  ): Promise<WriteResults> {
191
+ const { language } = options
175
192
  const results: WriteResults = []
176
193
 
177
194
  for (const item of options.schemaTemplateItems) {
178
- const schemaResults = await this.writeSchema(destinationDir, {
179
- ...options,
180
- ...item,
181
- })
182
- results.push(...schemaResults)
195
+ if (language === 'ts' || (language === 'go' && !item.importFrom)) {
196
+ const schemaResults = await this.writeSchema(destinationDir, {
197
+ ...options,
198
+ ...item,
199
+ })
200
+ results.push(...schemaResults)
201
+ }
183
202
  }
184
203
 
185
204
  return results
186
205
  }
187
206
 
188
- public async writeSchema(
207
+ private async writeSchema(
189
208
  destinationDir: string,
190
209
  options: {
191
210
  schemaTemplateItems: SchemaTemplateItem[]
192
211
  fieldTemplateItems: FieldTemplateItem[]
193
212
  valueTypes: ValueTypes
194
213
  typesFile?: string
214
+ language?: ProjectLanguage
195
215
  registerBuiltSchemas?: boolean
216
+ goModuleNameAndPath?: string
196
217
  shouldImportCoreSchemas: boolean
197
218
  } & SchemaTemplateItem
198
219
  ) {
199
- const {
220
+ let {
200
221
  schemaTemplateItems,
201
222
  fieldTemplateItems,
202
223
  valueTypes,
203
224
  registerBuiltSchemas = true,
225
+ language,
226
+ schema,
227
+ typesFile,
204
228
  ...item
205
229
  } = options
206
230
 
207
231
  const resolvedDestination = schemaDiskUtil.resolvePath({
208
232
  destination: destinationDir,
209
- schema: options.schema,
233
+ schema,
234
+ language,
210
235
  })
211
236
 
212
- let typesFile = options.typesFile
213
- ? diskUtil.resolveRelativePath(
214
- pathUtil.dirname(resolvedDestination),
215
- options.typesFile
216
- )
217
- : undefined
237
+ typesFile = this.resolveTypesFile(typesFile, resolvedDestination)
218
238
 
219
- if (typesFile) {
220
- typesFile = typesFile.replace(pathUtil.extname(typesFile), '')
239
+ let templateFile =
240
+ item.importFrom && options.shouldImportCoreSchemas
241
+ ? `schema/imported.schema.ts.hbs`
242
+ : undefined
243
+
244
+ if (language === 'go') {
245
+ templateFile = 'schema/schema.go.hbs'
221
246
  }
222
247
 
223
248
  const schemaContents = this.templates.schema({
@@ -227,23 +252,42 @@ export default class SchemaWriter extends AbstractWriter {
227
252
  fieldTemplateItems,
228
253
  valueTypes,
229
254
  typesFile,
230
- schemaFile:
231
- item.importFrom && options.shouldImportCoreSchemas
232
- ? `schema/imported.schema.ts.hbs`
233
- : undefined,
255
+ schema,
256
+ language: language === 'go' ? 'go' : 'typescript',
257
+ schemaFile: templateFile,
234
258
  })
235
259
 
236
260
  return this.writeFileIfChangedMixinResults(
237
261
  resolvedDestination,
238
262
  schemaContents,
239
263
  `${
240
- item.schema.description ? `${item.schema.description} ` : ''
264
+ schema.description ? `${schema.description} ` : ''
241
265
  }This is the schema generated by ${
242
266
  item.id
243
267
  }.builder.ts. AUTOGENERATED. DO NOT EDIT.`
244
268
  )
245
269
  }
246
270
 
271
+ private resolveTypesFile(
272
+ typesFile: string | undefined,
273
+ resolvedDestination: string
274
+ ) {
275
+ let resolvedType = typesFile
276
+ ? diskUtil.resolveRelativePath(
277
+ pathUtil.dirname(resolvedDestination),
278
+ typesFile
279
+ )
280
+ : undefined
281
+
282
+ if (resolvedType) {
283
+ resolvedType = resolvedType.replace(
284
+ pathUtil.extname(resolvedType),
285
+ ''
286
+ )
287
+ }
288
+ return resolvedType
289
+ }
290
+
247
291
  public async writeValueTypes(
248
292
  destinationDir: string,
249
293
  options: {
@@ -297,4 +341,6 @@ export interface GenerateSchemaTypesOptions {
297
341
  typesTemplate?: string
298
342
  registerBuiltSchemas?: boolean
299
343
  shouldImportCoreSchemas: boolean
344
+ language?: ProjectLanguage
345
+ goModuleNameAndPath?: string
300
346
  }
@@ -19,7 +19,7 @@ export default class SkillFeature<
19
19
  public description = 'The scaffolding needed to run a Skill'
20
20
  public readonly installOrderWeight = 100
21
21
 
22
- public packageDependencies: NpmPackage[] = [
22
+ protected _packageDependencies: NpmPackage[] = [
23
23
  { name: '@sprucelabs/error' },
24
24
  { name: '@sprucelabs/spruce-skill-utils' },
25
25
  { name: '@sprucelabs/spruce-skill-booter' },
@@ -1,5 +1,6 @@
1
+ import path from 'path'
1
2
  import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas'
2
- import { namesUtil } from '@sprucelabs/spruce-skill-utils'
3
+ import { diskUtil, namesUtil } from '@sprucelabs/spruce-skill-utils'
3
4
  import SpruceError from '../../../errors/SpruceError'
4
5
  import AbstractStore, { StoreOptions } from '../../../stores/AbstractStore'
5
6
  import { CurrentSkill, RegisteredSkill } from '../../../types/cli.types'
@@ -130,25 +131,66 @@ export default class SkillStoreImpl
130
131
  return skill.isRegistered
131
132
  }
132
133
 
134
+ public getGoModuleName(options?: { shouldIncludePathFromCwd?: boolean }) {
135
+ const { shouldIncludePathFromCwd = false } = options || {}
136
+
137
+ let goModFile = diskUtil.resolvePath(this.cwd, 'go.mod')
138
+ if (!diskUtil.doesFileExist(goModFile)) {
139
+ goModFile = diskUtil.resolvePath(this.cwd, '../go.mod')
140
+ }
141
+
142
+ if (!diskUtil.doesFileExist(goModFile)) {
143
+ throw new SpruceError({
144
+ code: 'DIRECTORY_NOT_GO_MODULE',
145
+ friendlyMessage: `Couldn't find a go.mod file in the current directory or its parent. Are you in a Go module?`,
146
+ cwd: this.cwd,
147
+ })
148
+ }
149
+ const goModContents = diskUtil.readFile(goModFile)
150
+ const moduleLine = goModContents.match(/module\s+([^\s]+)/)
151
+ const goModuleName = moduleLine?.[1] as string
152
+
153
+ if (shouldIncludePathFromCwd) {
154
+ const goModDir = path.dirname(goModFile)
155
+ const relativePath = this.cwd.replace(goModDir, '')
156
+
157
+ if (relativePath) {
158
+ return `${goModuleName}${relativePath}`
159
+ }
160
+ }
161
+
162
+ return goModuleName
163
+ }
164
+
133
165
  private getNamespaceFromPkg() {
166
+ if (this.isGoModule()) {
167
+ const module = this.getGoModuleName()
168
+ const moduleParts = module.split('/') ?? []
169
+ return moduleParts.pop() as string
170
+ }
171
+
134
172
  const nameFromPackage = this.Service('pkg').getSkillNamespace()
135
173
  if (!nameFromPackage) {
136
174
  throw new Error(
137
175
  'You need need to set skill.namespace in the package.json'
138
176
  )
139
177
  }
140
- return nameFromPackage
178
+ return nameFromPackage as string
179
+ }
180
+
181
+ private isGoModule() {
182
+ return diskUtil.detectProjectLanguage(this.cwd) === 'go'
141
183
  }
142
184
 
143
185
  public async loadCurrentSkillsNamespace() {
144
- const fallback = namesUtil.toPascal(this.getNamespaceFromPkg())
186
+ const fallback = this.getNamespaceFromPkg()
145
187
 
146
- if (this.Service('auth').getCurrentSkill()) {
188
+ if (!this.isGoModule() && this.Service('auth').getCurrentSkill()) {
147
189
  const current = await this.loadCurrentSkill()
148
190
  return namesUtil.toPascal(current.slug ?? fallback)
149
191
  }
150
192
 
151
- return fallback
193
+ return namesUtil.toPascal(fallback)
152
194
  }
153
195
 
154
196
  public async setCurrentSkillsNamespace(namespace: string) {
@@ -16,7 +16,7 @@ export default class StoreFeature extends AbstractFeature {
16
16
  isRequired: true,
17
17
  },
18
18
  ]
19
- public packageDependencies = [
19
+ public _packageDependencies = [
20
20
  { name: '@sprucelabs/spruce-store-plugin@latest', isDev: false },
21
21
  { name: '@sprucelabs/data-stores@latest', isDev: false },
22
22
  ]
@@ -25,7 +25,7 @@ export default class TestFeature extends AbstractFeature {
25
25
  { code: 'skill', isRequired: false },
26
26
  { code: 'node', isRequired: true },
27
27
  ]
28
- public packageDependencies: NpmPackage[] = [
28
+ public _packageDependencies: NpmPackage[] = [
29
29
  { name: '@sprucelabs/test@latest', isDev: true },
30
30
  { name: '@sprucelabs/test-utils@latest', isDev: true },
31
31
  { name: '@sprucelabs/jest-json-reporter@latest', isDev: true },