Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally copy model listing JSON file as post-generate step #492

Closed
chrispcampbell opened this issue Jun 4, 2024 · 0 comments · Fixed by #493 or #476
Closed

Optionally copy model listing JSON file as post-generate step #492

chrispcampbell opened this issue Jun 4, 2024 · 0 comments · Fixed by #493 or #476
Assignees

Comments

@chrispcampbell
Copy link
Contributor

chrispcampbell commented Jun 4, 2024

The build package (used by sde dev and sde bundle) currently generates a {model}.json listing file (generated internally by sde generate --list) every time the model is compiled. This file is optional and not needed for most projects, but will be needed in cases where you want to provide custom lookup or gaming inputs at runtime (since it is used to determine the index/spec info for each variable you want to access).

The file can currently be accessed by reaching into the sde-prep/build directory, or copied to a location of your choice like this using a custom build plugin:

    plugins: [
      // Copy the generated model listing to the app so that it can be loaded
      // at runtime
      {
        postGenerate: async context => {
          const srcPath = joinPath(context.config.prepDir, 'build', 'processed.json')
          const dstName = 'listing.json'
          const stagedFilePath = context.prepareStagedFile('model', dstName, generatedFilePath(), dstName)
          await copyFile(srcPath, stagedFilePath)
          return true
        }
      }
    ]

It would be better if we had a proper option in UserConfig that copies the file automatically in a post-generate step, so that the complex code above is not needed. Something like this:

  /**
   * If defined, a JSON file that lists all dimensions and variables in the model will be
   * written to the provided path.  This can be an absolute path, or if it is a relative
   * path it will be resolved relative to the `rootDir` for the project.
   */
  outListingFile?: string

Using this option, the config above can be simplified down to:

  outListingFile: 'src/generated/listing.json'

And the build process will take care of copying the generated file to the requested location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment