Skip to content

Commit 32977d4

Browse files
committed
Preserve manifest during ui sync
1 parent 0431b4b commit 32977d4

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

packages/cli/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ function syncUiOutput(args: {
11931193
schemaPathForHints?: string;
11941194
withTests?: boolean;
11951195
compiledJson: string;
1196+
manifestJson?: string | null;
11961197
}) {
11971198
const resolvedOutDir = path.resolve(args.outDir);
11981199
const templateDir = resolveNextExportUiTemplateDir();
@@ -1210,6 +1211,12 @@ function syncUiOutput(args: {
12101211
ensureDir(path.dirname(compiledPublicPath));
12111212
fs.writeFileSync(compiledPublicPath, args.compiledJson);
12121213

1214+
if (args.manifestJson) {
1215+
ensureDir(path.join(uiDir, 'public', '.well-known', 'tokenhost'));
1216+
fs.writeFileSync(path.join(uiDir, 'public', '.well-known', 'tokenhost', 'manifest.json'), args.manifestJson);
1217+
fs.writeFileSync(path.join(uiDir, 'public', 'manifest.json'), args.manifestJson);
1218+
}
1219+
12131220
if (args.withTests) {
12141221
addGeneratedUiTestScaffold(uiDir, templateDir);
12151222
console.log(`Wrote ui/tests/ (generated app test scaffold)`);
@@ -3064,16 +3071,19 @@ program
30643071
const schema = loadThsSchemaOrThrow(schemaPath);
30653072
const outDir = path.resolve(opts.out);
30663073
const compiledPath = path.join(outDir, 'compiled', 'App.json');
3074+
const manifestPath = path.join(outDir, 'manifest.json');
30673075
if (!fs.existsSync(compiledPath)) {
30683076
throw new Error(`Missing compiled/App.json in ${outDir}. Run \`th generate\`, \`th build\`, or \`th up\` first.`);
30693077
}
30703078
const compiledJson = fs.readFileSync(compiledPath, 'utf-8');
3079+
const manifestJson = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf-8') : null;
30713080
syncUiOutput({
30723081
schema,
30733082
outDir,
30743083
schemaPathForHints: schemaPath,
30753084
withTests: opts.withTests,
3076-
compiledJson
3085+
compiledJson,
3086+
manifestJson
30773087
});
30783088
});
30793089

test/testCliGenerateUi.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ function writeCompiledArtifact(filePath) {
2727
);
2828
}
2929

30+
function writeManifest(filePath, overrides = {}) {
31+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
32+
fs.writeFileSync(
33+
filePath,
34+
JSON.stringify(
35+
{
36+
appName: 'Test App',
37+
appSlug: 'test-app',
38+
ui: { baseUrl: 'http://127.0.0.1:3001/' },
39+
deployments: [
40+
{
41+
chainId: 314159,
42+
chainName: 'filecoin_calibration',
43+
contractAddress: '0x0000000000000000000000000000000000000001'
44+
}
45+
],
46+
...overrides
47+
},
48+
null,
49+
2
50+
)
51+
);
52+
}
53+
3054
function runTh(args, cwd) {
3155
const res = spawnSync('node', [path.resolve('packages/cli/dist/index.js'), ...args], {
3256
cwd,
@@ -270,13 +294,16 @@ describe('th ui sync', function () {
270294
const outDir = path.join(dir, 'out');
271295
writeJson(schemaPath, minimalSchema());
272296
writeCompiledArtifact(path.join(outDir, 'compiled', 'App.json'));
297+
writeManifest(path.join(outDir, 'manifest.json'));
273298

274299
const res = runTh(['ui', 'sync', schemaPath, '--out', outDir], process.cwd());
275300
expect(res.status, res.stderr || res.stdout).to.equal(0);
276301

277302
expect(fs.existsSync(path.join(outDir, 'ui', 'package.json'))).to.equal(true);
278303
expect(fs.existsSync(path.join(outDir, 'ui', 'src', 'generated', 'ths.ts'))).to.equal(true);
279304
expect(fs.existsSync(path.join(outDir, 'ui', 'public', 'compiled', 'App.json'))).to.equal(true);
305+
expect(fs.existsSync(path.join(outDir, 'ui', 'public', 'manifest.json'))).to.equal(true);
306+
expect(fs.existsSync(path.join(outDir, 'ui', 'public', '.well-known', 'tokenhost', 'manifest.json'))).to.equal(true);
280307
expect(fs.existsSync(path.join(outDir, 'contracts', 'App.sol'))).to.equal(false);
281308
});
282309

0 commit comments

Comments
 (0)