Skip to content

Commit

Permalink
feat: include script filename in path
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 15, 2024
1 parent 9ec4910 commit 3242ed9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/deploy-script-support/src/writeCoreEvalParts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { E } from '@endo/far';

import { createBundles } from '@agoric/internal/src/node/createBundles.js';
import { deeplyFulfilledObject } from '@agoric/internal';
import path from 'node:path';
import { defangAndTrim, mergePermits, stringify } from './code-gen.js';
import {
makeCoreProposalBehavior,
Expand All @@ -14,6 +15,7 @@ import {
* @import {CoreEvalDescriptor} from './externalTypes.js';
*/

// TODO consider using dots instead of dashes distinguish the module shape qualifierfrom the identifier. (e.g. `-plan.json' to `.plan.json`)
/**
* @typedef CoreEvalPlan
* @property {string} name
Expand All @@ -26,7 +28,7 @@ import {
* @callback WriteCoreEval write to disk the files needed for a CoreEval (js code to`${filePrefix}.js`, permits to `${filePrefix}-permit.json`, an overall
* summary to `${filePrefix}-plan.json), plus whatever bundles bundles the code loads)
* see CoreEval in {@link '/golang/cosmos/x/swingset/types/swingset.pb.go'}
* @param {string} filePrefix name on disk
* @param {string} evalName name on disk
* @param {import('./externalTypes.js').CoreEvalBuilder} builder
* @returns {Promise<CoreEvalPlan>}
*/
Expand Down Expand Up @@ -100,7 +102,7 @@ export const makeWriteCoreEval = (
Promise.resolve()
);
/** @type {WriteCoreEval} */
const writeCoreEval = async (filePrefix, builder) => {
const writeCoreEval = async (evalName, builder, scriptModule) => {
/**
*
* @param {string} entrypoint
Expand Down Expand Up @@ -132,7 +134,7 @@ export const makeWriteCoreEval = (

// Serialise the installations.
mutex = E.when(mutex, async () => {
// console.log('installing', { filePrefix, entrypoint, bundlePath });
// console.log('installing', { evalName, entrypoint, bundlePath });
const spec = await getBundleSpec(bundle, getBundler, opts);
bundles.push({
entrypoint,
Expand Down Expand Up @@ -161,7 +163,7 @@ export const makeWriteCoreEval = (
harden(builder({ publishRef, install })),
);
const { sourceSpec, getManifestCall } = evalDescriptor;
// console.log('created', { filePrefix, sourceSpec, getManifestCall });
// console.log('created', { evalName, sourceSpec, getManifestCall });

// Extract the top-level permit.
const { permits: evalPermits, manifest: customManifest } =
Expand All @@ -170,7 +172,7 @@ export const makeWriteCoreEval = (
// Get an install
const manifestBundleRef = await publishRef(install(sourceSpec));

// console.log('writing', { filePrefix, manifestBundleRef, sourceSpec });
// console.log('writing', { evalName, manifestBundleRef, sourceSpec });
const code = `\
// This is generated by writeCoreEval; please edit!
/* eslint-disable */
Expand All @@ -189,24 +191,29 @@ behavior;

const trimmed = defangAndTrim(code);

const permitFile = `${filePrefix}-permit.json`;
// If the scriptModule is present, include it in the name of the plan
const planName = scriptModule
? `${path.basename(scriptModule, '.js')}-${evalName}`
: evalName;

const permitFile = `${planName}-permit.json`;
log(`creating ${permitFile}`);
await writeFile(permitFile, JSON.stringify(evalPermits, null, 2));

const codeFile = `${filePrefix}.js`;
const codeFile = `${planName}.js`;
log(`creating ${codeFile}`);
await writeFile(codeFile, trimmed);

/** @type {CoreEvalPlan} */
const plan = {
name: filePrefix,
name: planName,
script: codeFile,
permit: permitFile,
bundles,
};

await writeFile(
`${filePrefix}-plan.json`,
`${planName}-plan.json`,
`${JSON.stringify(plan, null, 2)}\n`,
);

Expand Down

0 comments on commit 3242ed9

Please sign in to comment.