@sprucelabs/spruce-cli 28.2.3 → 29.0.1
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 +24 -0
- package/build/.spruce/errors/errors.types.d.ts +23 -2
- package/build/.spruce/errors/options.types.d.ts +4 -1
- package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.d.ts +3 -0
- package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.js +20 -0
- package/build/.spruce/errors/spruceCli/directoryNotGoModule.schema.js.map +1 -0
- package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.d.ts +7 -2
- package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.js +36 -13
- package/build/__tests__/behavioral/OverridingCommandsInPackageJson.test.js.map +1 -1
- package/build/__tests__/behavioral/events/DifferentEventOptions.test.d.ts +16 -0
- package/build/__tests__/behavioral/events/DifferentEventOptions.test.js +105 -0
- package/build/__tests__/behavioral/events/DifferentEventOptions.test.js.map +1 -0
- package/build/__tests__/behavioral/events/KeepingEventsInSync.test.js.map +1 -1
- package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.d.ts +5 -0
- package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.js +32 -0
- package/build/__tests__/behavioral/features/InstallFeaturesInGo.test.js.map +1 -0
- package/build/__tests__/behavioral/organization/CreatingAnOrg.test.d.ts +5 -0
- package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js +21 -13
- package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js.map +1 -1
- package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.d.ts +1 -1
- package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.js +7 -7
- package/build/__tests__/behavioral/schemas/KeepingSchemasInSync.test.js.map +1 -1
- package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.d.ts +39 -0
- package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.js +289 -0
- package/build/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.js.map +1 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.d.ts +7 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.js +46 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.js.map +1 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.d.ts +5 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.js +31 -0
- package/build/__tests__/behavioral/schemas/SyncingSchemasInGo.test.js.map +1 -0
- package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js +1 -1
- package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js.map +1 -1
- package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js +10 -1
- package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js.map +1 -1
- package/build/__tests__/implementation/SkillStore.test.d.ts +5 -0
- package/build/__tests__/implementation/SkillStore.test.js +37 -0
- package/build/__tests__/implementation/SkillStore.test.js.map +1 -1
- package/build/__tests__/support/EventFaker.d.ts +7 -0
- package/build/__tests__/support/EventFaker.js +43 -0
- package/build/__tests__/support/EventFaker.js.map +1 -1
- package/build/cli/Cli.js +12 -9
- package/build/cli/Cli.js.map +1 -1
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/SpruceError.js.map +1 -1
- package/build/errors/directoryNotGoModule.builder.d.ts +12 -0
- package/build/errors/directoryNotGoModule.builder.js +15 -0
- package/build/errors/directoryNotGoModule.builder.js.map +1 -0
- package/build/features/AbstractAction.d.ts +1 -0
- package/build/features/AbstractAction.js +5 -1
- package/build/features/AbstractAction.js.map +1 -1
- package/build/features/AbstractFeature.d.ts +8 -1
- package/build/features/AbstractFeature.js +12 -1
- package/build/features/AbstractFeature.js.map +1 -1
- package/build/features/ActionFactory.js +1 -2
- package/build/features/ActionFactory.js.map +1 -1
- package/build/features/ActionQuestionAsker.js +0 -1
- package/build/features/ActionQuestionAsker.js.map +1 -1
- package/build/features/FeatureInstaller.d.ts +1 -0
- package/build/features/FeatureInstaller.js +21 -7
- package/build/features/FeatureInstaller.js.map +1 -1
- package/build/features/FeatureInstallerFactory.d.ts +1 -0
- package/build/features/FeatureInstallerFactory.js +7 -0
- package/build/features/FeatureInstallerFactory.js.map +1 -1
- package/build/features/OverrideActionDecorator.js +1 -1
- package/build/features/OverrideActionDecorator.js.map +1 -1
- package/build/features/VersionResolver.js +1 -1
- package/build/features/VersionResolver.js.map +1 -1
- package/build/features/agent/AgentFeature.d.ts +1 -1
- package/build/features/agent/AgentFeature.js +1 -1
- package/build/features/agent/AgentFeature.js.map +1 -1
- package/build/features/conversation/ConversationFeature.d.ts +1 -1
- package/build/features/conversation/ConversationFeature.js +1 -1
- package/build/features/conversation/ConversationFeature.js.map +1 -1
- package/build/features/dependencies/DependencyFeature.d.ts +0 -1
- package/build/features/dependencies/DependencyFeature.js +0 -1
- package/build/features/dependencies/DependencyFeature.js.map +1 -1
- package/build/features/deploy/DeployFeature.d.ts +1 -1
- package/build/features/deploy/DeployFeature.js +1 -1
- package/build/features/deploy/DeployFeature.js.map +1 -1
- package/build/features/error/ErrorFeature.d.ts +1 -1
- package/build/features/error/ErrorFeature.js +1 -1
- package/build/features/error/ErrorFeature.js.map +1 -1
- package/build/features/event/EventFeature.d.ts +1 -1
- package/build/features/event/EventFeature.js +1 -1
- package/build/features/event/EventFeature.js.map +1 -1
- package/build/features/eventContract/EventContractFeature.d.ts +1 -3
- package/build/features/eventContract/EventContractFeature.js +0 -2
- package/build/features/eventContract/EventContractFeature.js.map +1 -1
- package/build/features/node/NodeFeature.d.ts +1 -1
- package/build/features/node/NodeFeature.js +1 -1
- package/build/features/node/NodeFeature.js.map +1 -1
- package/build/features/onboard/OnboardFeature.d.ts +1 -3
- package/build/features/onboard/OnboardFeature.js +0 -2
- package/build/features/onboard/OnboardFeature.js.map +1 -1
- package/build/features/organization/OrganizationFeature.d.ts +0 -1
- package/build/features/organization/OrganizationFeature.js +0 -1
- package/build/features/organization/OrganizationFeature.js.map +1 -1
- package/build/features/permission/PermissionFeature.d.ts +2 -3
- package/build/features/permission/PermissionFeature.js +1 -2
- package/build/features/permission/PermissionFeature.js.map +1 -1
- package/build/features/person/PersonFeature.d.ts +1 -3
- package/build/features/person/PersonFeature.js +0 -2
- package/build/features/person/PersonFeature.js.map +1 -1
- package/build/features/polish/PolishFeature.d.ts +1 -1
- package/build/features/polish/PolishFeature.js +1 -1
- package/build/features/polish/PolishFeature.js.map +1 -1
- package/build/features/sandbox/SandboxFeature.d.ts +0 -1
- package/build/features/sandbox/SandboxFeature.js +0 -1
- package/build/features/sandbox/SandboxFeature.js.map +1 -1
- package/build/features/schema/SchemaFeature.d.ts +2 -3
- package/build/features/schema/SchemaFeature.js +6 -1
- package/build/features/schema/SchemaFeature.js.map +1 -1
- package/build/features/schema/actions/SyncAction.d.ts +5 -2
- package/build/features/schema/actions/SyncAction.js +50 -16
- package/build/features/schema/actions/SyncAction.js.map +1 -1
- package/build/features/schema/utilities/schemaDisk.utility.d.ts +7 -0
- package/build/features/schema/utilities/schemaDisk.utility.js +22 -4
- package/build/features/schema/utilities/schemaDisk.utility.js.map +1 -1
- package/build/features/schema/utilities/schemaGenerator.utility.d.ts +1 -0
- package/build/features/schema/utilities/schemaGenerator.utility.js +18 -10
- package/build/features/schema/utilities/schemaGenerator.utility.js.map +1 -1
- package/build/features/schema/writers/SchemaWriter.d.ts +9 -9
- package/build/features/schema/writers/SchemaWriter.js +38 -17
- package/build/features/schema/writers/SchemaWriter.js.map +1 -1
- package/build/features/skill/SkillFeature.d.ts +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.d.ts +5 -0
- package/build/features/skill/stores/SkillStore.js +40 -3
- 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 +1 -1
- package/build/features/store/StoreFeature.js.map +1 -1
- package/build/features/test/TestFeature.d.ts +1 -1
- package/build/features/test/TestFeature.js +1 -1
- package/build/features/test/TestFeature.js.map +1 -1
- package/build/features/test/TestReporter.js +1 -1
- package/build/features/test/TestReporter.js.map +1 -1
- package/build/features/view/ViewFeature.d.ts +1 -1
- package/build/features/view/ViewFeature.js +1 -1
- package/build/features/view/ViewFeature.js.map +1 -1
- package/build/migration/EsLint9Migrator.d.ts +1 -0
- package/build/packageManager/NodePackageManager.d.ts +14 -0
- package/build/packageManager/NodePackageManager.js +88 -0
- package/build/packageManager/NodePackageManager.js.map +1 -0
- package/build/packageManager/packageManager.types.d.ts +16 -0
- package/build/packageManager/packageManager.types.js +3 -0
- package/build/packageManager/packageManager.types.js.map +1 -0
- package/build/services/GoPackageManager.d.ts +10 -0
- package/build/services/GoPackageManager.js +39 -0
- package/build/services/GoPackageManager.js.map +1 -0
- package/build/services/PkgService.d.ts +3 -7
- package/build/services/PkgService.js +13 -68
- package/build/services/PkgService.js.map +1 -1
- package/build/templateItemBuilders/SchemaTemplateItemBuilder.js.map +1 -1
- package/build/tests/AbstractCliTest.d.ts +5 -1
- package/build/tests/AbstractCliTest.js +15 -3
- package/build/tests/AbstractCliTest.js.map +1 -1
- package/build/tests/fixtures/FeatureFixture.js +4 -1
- package/build/tests/fixtures/FeatureFixture.js.map +1 -1
- package/build/tests/fixtures/GoFixture.d.ts +12 -0
- package/build/tests/fixtures/GoFixture.js +39 -0
- package/build/tests/fixtures/GoFixture.js.map +1 -0
- package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.d.ts +1 -0
- package/build/widgets/terminalKit/TkTextWidget.js +3 -2
- package/build/widgets/terminalKit/TkTextWidget.js.map +1 -1
- package/build/writers/AbstractWriter.js +7 -6
- package/build/writers/AbstractWriter.js.map +1 -1
- package/package.json +30 -30
- package/src/.spruce/errors/errors.types.ts +32 -2
- package/src/.spruce/errors/options.types.ts +4 -1
- package/src/.spruce/errors/spruceCli/directoryNotGoModule.schema.ts +23 -0
- package/src/__tests__/behavioral/OverridingCommandsInPackageJson.test.ts +60 -13
- package/src/__tests__/behavioral/events/DifferentEventOptions.test.ts +134 -0
- package/src/__tests__/behavioral/events/KeepingEventsInSync.test.ts +0 -1
- package/src/__tests__/behavioral/features/InstallFeaturesInGo.test.ts +17 -0
- package/src/__tests__/behavioral/organization/CreatingAnOrg.test.ts +29 -22
- package/src/__tests__/behavioral/schemas/KeepingSchemasInSync.test.ts +6 -9
- package/src/__tests__/behavioral/schemas/SyncingCoreSchemasInGo.test.ts +376 -0
- package/src/__tests__/behavioral/schemas/SyncingSchemasInChildDirInGo.test.ts +46 -0
- package/src/__tests__/behavioral/schemas/SyncingSchemasInGo.test.ts +23 -0
- package/src/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.ts +1 -1
- package/src/__tests__/behavioral/upgrading/UpdatingDependencies2.test.ts +15 -2
- package/src/__tests__/implementation/SkillStore.test.ts +44 -1
- package/src/__tests__/support/EventFaker.ts +56 -0
- package/src/cli/Cli.ts +20 -12
- package/src/errors/SpruceError.ts +4 -0
- package/src/errors/directoryNotGoModule.builder.ts +13 -0
- package/src/features/AbstractAction.ts +6 -4
- package/src/features/AbstractFeature.ts +20 -1
- package/src/features/ActionFactory.ts +2 -2
- package/src/features/ActionQuestionAsker.ts +0 -1
- package/src/features/FeatureInstaller.ts +30 -6
- package/src/features/FeatureInstallerFactory.ts +9 -0
- package/src/features/OverrideActionDecorator.ts +1 -1
- package/src/features/VersionResolver.ts +2 -1
- package/src/features/agent/AgentFeature.ts +1 -1
- package/src/features/conversation/ConversationFeature.ts +1 -1
- package/src/features/dependencies/DependencyFeature.ts +0 -1
- package/src/features/deploy/DeployFeature.ts +1 -1
- package/src/features/error/ErrorFeature.ts +1 -1
- package/src/features/event/EventFeature.ts +1 -1
- package/src/features/eventContract/EventContractFeature.ts +1 -3
- package/src/features/node/NodeFeature.ts +1 -1
- package/src/features/onboard/OnboardFeature.ts +1 -7
- package/src/features/organization/OrganizationFeature.ts +0 -1
- package/src/features/permission/PermissionFeature.ts +1 -3
- package/src/features/person/PersonFeature.ts +1 -4
- package/src/features/polish/PolishFeature.ts +1 -1
- package/src/features/sandbox/SandboxFeature.ts +0 -1
- package/src/features/schema/SchemaFeature.ts +8 -2
- package/src/features/schema/actions/SyncAction.ts +68 -26
- package/src/features/schema/utilities/schemaDisk.utility.ts +43 -11
- package/src/features/schema/utilities/schemaGenerator.utility.ts +33 -13
- package/src/features/schema/writers/SchemaWriter.ts +71 -25
- package/src/features/skill/SkillFeature.ts +1 -1
- package/src/features/skill/stores/SkillStore.ts +51 -5
- package/src/features/store/StoreFeature.ts +1 -1
- package/src/features/test/TestFeature.ts +1 -1
- package/src/features/test/TestReporter.ts +1 -1
- package/src/features/view/ViewFeature.ts +1 -1
- package/src/packageManager/NodePackageManager.ts +115 -0
- package/src/packageManager/packageManager.types.ts +21 -0
- package/src/services/GoPackageManager.ts +45 -0
- package/src/services/PkgService.ts +17 -92
- package/src/templateItemBuilders/SchemaTemplateItemBuilder.ts +6 -6
- package/src/tests/AbstractCliTest.ts +19 -5
- package/src/tests/fixtures/FeatureFixture.ts +3 -1
- package/src/tests/fixtures/GoFixture.ts +39 -0
- package/src/widgets/terminalKit/TkTextWidget.ts +3 -2
- package/src/writers/AbstractWriter.ts +15 -6
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import pathUtil from 'path'
|
|
2
2
|
import { Schema, SchemaError, SchemaTemplateItem } from '@sprucelabs/schema'
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
?
|
|
68
|
+
? this.resolveStandaloneSchemaTypesFilePath({
|
|
51
69
|
cwd,
|
|
52
70
|
schemaTypesDestinationDirOrFile,
|
|
53
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
233
|
+
schema,
|
|
234
|
+
language,
|
|
210
235
|
})
|
|
211
236
|
|
|
212
|
-
|
|
213
|
-
? diskUtil.resolveRelativePath(
|
|
214
|
-
pathUtil.dirname(resolvedDestination),
|
|
215
|
-
options.typesFile
|
|
216
|
-
)
|
|
217
|
-
: undefined
|
|
237
|
+
typesFile = this.resolveTypesFile(typesFile, resolvedDestination)
|
|
218
238
|
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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) {
|
|
@@ -200,6 +242,10 @@ export default class SkillStoreImpl
|
|
|
200
242
|
return this.fetchAllSkills({ shouldOnlyShowMine: true })
|
|
201
243
|
}
|
|
202
244
|
|
|
245
|
+
public static setCurrentSkill(skill: CurrentSkill) {
|
|
246
|
+
this.currentSkill = skill
|
|
247
|
+
}
|
|
248
|
+
|
|
203
249
|
public async fetchAllSkills(query?: {
|
|
204
250
|
shouldOnlyShowMine?: boolean
|
|
205
251
|
namespaces?: string[]
|
|
@@ -16,7 +16,7 @@ export default class StoreFeature extends AbstractFeature {
|
|
|
16
16
|
isRequired: true,
|
|
17
17
|
},
|
|
18
18
|
]
|
|
19
|
-
public
|
|
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
|
|
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 },
|
|
@@ -54,7 +54,7 @@ export default class TestReporter {
|
|
|
54
54
|
private minWidth = 50
|
|
55
55
|
private isRpTraining: boolean
|
|
56
56
|
private trainingTokenPopup?: PopupWidget
|
|
57
|
-
private shouldStripCwdFromErrors =
|
|
57
|
+
private shouldStripCwdFromErrors = true
|
|
58
58
|
// private orientationWhenErrorLogWasShown: TestReporterOrientation =
|
|
59
59
|
// 'landscape'
|
|
60
60
|
|
|
@@ -9,7 +9,7 @@ export default class ViewFeature extends AbstractFeature {
|
|
|
9
9
|
public code: FeatureCode = 'view'
|
|
10
10
|
public actionsDir = diskUtil.resolvePath(__dirname, 'actions')
|
|
11
11
|
|
|
12
|
-
public readonly
|
|
12
|
+
public readonly _packageDependencies: NpmPackage[] = [
|
|
13
13
|
{
|
|
14
14
|
name: '@sprucelabs/heartwood-view-controllers@latest',
|
|
15
15
|
},
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import pathUtil from 'path'
|
|
2
|
+
import { diskUtil } from '@sprucelabs/spruce-skill-utils'
|
|
3
|
+
import { CommandService } from '../services/CommandService'
|
|
4
|
+
import PkgService, { AddOptions } from '../services/PkgService'
|
|
5
|
+
import isCi from '../utilities/isCi'
|
|
6
|
+
import {
|
|
7
|
+
PackageManager,
|
|
8
|
+
PackageManagerConstructorOptions,
|
|
9
|
+
} from './packageManager.types'
|
|
10
|
+
|
|
11
|
+
export default class NodePackageManager implements PackageManager {
|
|
12
|
+
private pkgService: PkgService
|
|
13
|
+
private cwd: string
|
|
14
|
+
private commandService: CommandService
|
|
15
|
+
|
|
16
|
+
public constructor(options: PackageManagerConstructorOptions) {
|
|
17
|
+
const { pkgService, commandService, cwd } = options
|
|
18
|
+
this.pkgService = pkgService
|
|
19
|
+
this.commandService = commandService
|
|
20
|
+
this.cwd = cwd
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async installDependencies(
|
|
24
|
+
pkg?: string[] | string,
|
|
25
|
+
options?: AddOptions
|
|
26
|
+
) {
|
|
27
|
+
const shouldCleanupLockFiles = options?.shouldCleanupLockFiles !== false
|
|
28
|
+
const deleteLockFile = shouldCleanupLockFiles
|
|
29
|
+
? () => this.pkgService.deleteLockFile()
|
|
30
|
+
: () => {}
|
|
31
|
+
|
|
32
|
+
if (!pkg) {
|
|
33
|
+
await this.commandService.execute('yarn', { args: ['install'] })
|
|
34
|
+
deleteLockFile()
|
|
35
|
+
return { totalInstalled: -1, totalSkipped: -1 }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
deleteLockFile()
|
|
39
|
+
|
|
40
|
+
const packages = Array.isArray(pkg) ? pkg : [pkg]
|
|
41
|
+
const toInstall = []
|
|
42
|
+
const labsModules: string[] = []
|
|
43
|
+
|
|
44
|
+
let totalInstalled = 0
|
|
45
|
+
let totalSkipped = 0
|
|
46
|
+
|
|
47
|
+
for (const thisPackage of packages) {
|
|
48
|
+
const isInstalled =
|
|
49
|
+
!options?.shouldForceInstall &&
|
|
50
|
+
this.pkgService.isInstalled(thisPackage)
|
|
51
|
+
if (thisPackage.startsWith('@sprucelabs/') || !isInstalled) {
|
|
52
|
+
toInstall.push(this.pkgService.stripLatest(thisPackage))
|
|
53
|
+
totalInstalled++
|
|
54
|
+
} else {
|
|
55
|
+
totalSkipped++
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (totalInstalled > 0) {
|
|
60
|
+
const { executable, args } = this.buildCommandAndArgs(
|
|
61
|
+
toInstall,
|
|
62
|
+
options
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const isInWorkspace = this.pkgService.get('workspaces')?.length > 0
|
|
66
|
+
if (isInWorkspace) {
|
|
67
|
+
args.push('-W')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await this.commandService.execute(executable, {
|
|
71
|
+
args,
|
|
72
|
+
})
|
|
73
|
+
} else if (
|
|
74
|
+
!diskUtil.doesDirExist(pathUtil.join(this.cwd, 'node_modules'))
|
|
75
|
+
) {
|
|
76
|
+
await this.commandService.execute('yarn', { args: ['install'] })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
deleteLockFile()
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
totalInstalled: totalInstalled + labsModules.length,
|
|
83
|
+
totalSkipped,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public async uninstallDependencies(pkg: string[] | string) {
|
|
88
|
+
const packages = Array.isArray(pkg) ? pkg : [pkg]
|
|
89
|
+
const args: string[] = ['uninstall', ...packages]
|
|
90
|
+
await this.commandService.execute('npm', {
|
|
91
|
+
args,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
await this.installDependencies()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private buildCommandAndArgs(
|
|
98
|
+
toInstall: string[],
|
|
99
|
+
options: AddOptions | undefined
|
|
100
|
+
) {
|
|
101
|
+
const args: any[] = [
|
|
102
|
+
isCi() && '--cache-folder',
|
|
103
|
+
isCi() && diskUtil.createRandomTempDir(),
|
|
104
|
+
'add',
|
|
105
|
+
...toInstall,
|
|
106
|
+
].filter((a) => !!a)
|
|
107
|
+
|
|
108
|
+
if (options?.isDev) {
|
|
109
|
+
args.push('-D')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const executable = 'yarn'
|
|
113
|
+
return { executable, args }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CommandService } from '../services/CommandService'
|
|
2
|
+
import PkgService, { AddOptions } from '../services/PkgService'
|
|
3
|
+
|
|
4
|
+
export interface PackageManager {
|
|
5
|
+
installDependencies(
|
|
6
|
+
pkg?: string[] | string,
|
|
7
|
+
options?: AddOptions
|
|
8
|
+
): Promise<{
|
|
9
|
+
totalInstalled: number
|
|
10
|
+
totalSkipped: number
|
|
11
|
+
}>
|
|
12
|
+
uninstallDependencies?(dependencies: string[] | string): Promise<void>
|
|
13
|
+
isInstalled?(pkg: string): boolean
|
|
14
|
+
deleteLockFile?(): void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PackageManagerConstructorOptions {
|
|
18
|
+
pkgService: PkgService
|
|
19
|
+
commandService: CommandService
|
|
20
|
+
cwd: string
|
|
21
|
+
}
|