Prepare shared glossary documents
This commit is contained in:
@@ -43,6 +43,11 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
return nil, fmt.Errorf("prepare: session id is required")
|
||||
}
|
||||
|
||||
glossaryDocuments, err := config.ResolveGlossaries(env.Config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: resolve glossaries: %w", err)
|
||||
}
|
||||
|
||||
paths, err := ensureLayoutForEnv(env, sessionID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: ensure workdir layout: %w", err)
|
||||
@@ -53,7 +58,6 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
|
||||
speakersInput := stableInputSource(env.Config.StableInputs.SpeakersFile, env.Config.Session.Inputs.SpeakersFile, sessionSrc)
|
||||
autocorrectInput := stableInputSource(env.Config.StableInputs.AutocorrectFile, env.Config.Session.Inputs.AutocorrectFile, sessionSrc)
|
||||
glossaryInput := stableInputSource(env.Config.StableInputs.GlossaryFile, config.OptionalString(env.Config.Session.Inputs.GlossaryFile), sessionSrc)
|
||||
spellCatalogInput := stableInputSource(env.Config.StableInputs.SpellCatalogFile, env.Config.Session.Inputs.SpellCatalogFile, sessionSrc)
|
||||
|
||||
speakersSrc, err := resolveConfigRelativePath(speakersInput)
|
||||
@@ -64,10 +68,6 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: autocorrect path: %w", err)
|
||||
}
|
||||
glossarySrc, err := resolveConfigRelativePath(glossaryInput)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: glossary path: %w", err)
|
||||
}
|
||||
spellCatalogConfigured := strings.TrimSpace(spellCatalogInput.Path) != ""
|
||||
spellCatalogSrc := ""
|
||||
if spellCatalogConfigured {
|
||||
@@ -86,7 +86,6 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
}{
|
||||
{path: speakersSrc, name: "speakers.yml"},
|
||||
{path: autocorrectSrc, name: "autocorrect.yml"},
|
||||
{path: glossarySrc, name: "glossary.yml"},
|
||||
} {
|
||||
if err := requireFile(required.path, required.name); err != nil {
|
||||
return nil, fmt.Errorf("prepare: %w", err)
|
||||
@@ -165,20 +164,6 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
{kind: "speakers", src: speakersSrc, dst: filepath.Join(paths.InputsDir, "speakers.yml"), source: speakersInput.Source},
|
||||
{kind: "autocorrect", src: autocorrectSrc, dst: filepath.Join(paths.InputsDir, "autocorrect.yml"), source: autocorrectInput.Source},
|
||||
}
|
||||
for _, prepared := range []struct {
|
||||
sourceID string
|
||||
input config.ResolvedInputFile
|
||||
src string
|
||||
}{{sourceID: artifactpolicy.SourceInputGlossary, input: glossaryInput, src: glossarySrc}} {
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource(prepared.sourceID)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("prepare: prepared-input descriptor %q is unavailable", prepared.sourceID)
|
||||
}
|
||||
preparedConfigFiles = append(preparedConfigFiles, preparedConfigFile{
|
||||
kind: descriptor.ManifestKind, src: prepared.src,
|
||||
dst: filepath.Join(paths.InputsDir, descriptor.Filename), source: prepared.input.Source,
|
||||
})
|
||||
}
|
||||
spellDescriptor, ok := artifactpolicy.DescribePreparedInputSource(artifactpolicy.SourceInputSpellCatalog)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("prepare: spell catalog prepared-input descriptor is unavailable")
|
||||
@@ -202,6 +187,27 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
}
|
||||
registerConfigInput(cfgFile.kind, cfgFile.dst, checksum, cfgFile.source)
|
||||
}
|
||||
for _, item := range []struct{ name, source string }{
|
||||
{"party", artifactpolicy.SourceInputGlossaryParty},
|
||||
{"campaign", artifactpolicy.SourceInputGlossaryCampaign},
|
||||
{"setting", artifactpolicy.SourceInputGlossarySetting},
|
||||
{"spells", artifactpolicy.SourceInputGlossarySpells},
|
||||
} {
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("prepare: missing descriptor %q", item.source)
|
||||
}
|
||||
dst := filepath.Join(paths.InputsDir, descriptor.Filename)
|
||||
if err := fileops.EnsureWorkspaceDirectory(filepath.Dir(dst)); err != nil {
|
||||
return nil, fmt.Errorf("prepare: create glossary directory: %w", err)
|
||||
}
|
||||
data := glossaryDocuments[item.name]
|
||||
checksum, err := writeBytesIfChanged(env.ArtifactStore, dst, data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: materialize %s: %w", descriptor.ManifestKind, err)
|
||||
}
|
||||
inputs = append(inputs, manifest.InputRecord{Kind: descriptor.ManifestKind, Path: dst, Checksum: checksum, Size: int64(len(data)), Source: "derived_from_configuration"})
|
||||
}
|
||||
partyInputs, err := materializePreparedPartyInputs(env.ArtifactStore, env.Config, paths.InputsDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user