Skip to content

Commit bcef447

Browse files
Using postinstallScript instead of setupPapi
Running a single "papi update" command with existing polkadot-api.json is considerably faster than adding each network, plus more `postinstallScript` is a more versatile approach.
1 parent 52e4ecc commit bcef447

File tree

9 files changed

+8341
-26
lines changed

9 files changed

+8341
-26
lines changed

src/scripts/backSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ program
2020
program.parse();
2121
const options: { source: string; template: TemplateNames; rm: boolean } = program.opts();
2222

23-
const alwaysIgnorePatterns = [/^\.papi\/metadata.*/, /^\.gitignore$/];
23+
const alwaysIgnorePatterns = [/^\.papi\/metadata.*/, /^\.papi\/descriptors.*/, /^\.gitignore$/];
2424

2525
const gitignoreContents = fs.readFileSync(path.join(options.source, ".gitignore"), "utf-8");
2626
const gitignoreIg = ignore().add(gitignoreContents);

src/templateConfigs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import reactSolidityHardhat from "./react-solidity-hardhat";
33
import reactSolidityRemix from "./react-solidity-remix";
44

55
export type TemplateConfig = {
6-
setupPapi: boolean;
76
instructions: string;
87
npmRoots: string[];
8+
postinstallScript?: string;
99
};
1010

1111
export const configs: Record<string, TemplateConfig> = {

src/templateConfigs/react-papi-tailwind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { TemplateConfig } from "#src/templateConfigs/index";
22
import { colors as c } from "#src/util/log";
33

44
const config: TemplateConfig = {
5-
setupPapi: true,
65
npmRoots: ["/"],
76
instructions: `
87
${c.secondary("Start app:")}
98
${c.code("npm run dev")}`,
9+
postinstallScript: "npx papi update",
1010
};
1111

1212
export default config;

src/templateConfigs/react-solidity-hardhat.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { TemplateConfig } from "#src/templateConfigs/index";
22
import { colors as c } from "#src/util/log";
33

44
const config: TemplateConfig = {
5-
setupPapi: false,
65
npmRoots: ["contracts", "frontend"],
76
instructions: `
87
${c.primary("Develop smart contracts:")}

src/templateConfigs/react-solidity-remix.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { TemplateConfig } from "#src/templateConfigs/index";
22
import { colors as c } from "#src/util/log";
33

44
const config: TemplateConfig = {
5-
setupPapi: false,
65
npmRoots: ["contracts", "frontend"],
76
instructions: `
87
${c.primary("For Remix environment:")}

src/util/childProcess.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import cp from "child_process";
22

3-
export function spawnAndWait(cmd: string, args: string[], { cwd }: { cwd?: string }): Promise<void> {
3+
export function spawnAndWait(
4+
cmd: string,
5+
args: string[],
6+
{
7+
cwd,
8+
shell = true,
9+
}: {
10+
cwd?: string;
11+
shell?: boolean;
12+
},
13+
): Promise<void> {
414
return new Promise((resolve, reject) => {
5-
const proc = cp.spawn(cmd, args, { stdio: "inherit", shell: true, cwd: cwd ?? process.cwd() });
15+
const proc = cp.spawn(cmd, args, { stdio: "inherit", shell, cwd: cwd ?? process.cwd() });
616
proc.on("exit", (code, signal) => {
717
if (code === 0) resolve();
818
else

src/util/spawnTemplate.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export async function spawnTemplate(dappData: DappData): Promise<void> {
1313
await copyTemplate(dappData, targetDir, templatesDir);
1414
await updateFiles(dappData, targetDir);
1515
await installDeps(targetDir, dappData);
16-
if (dappData.config.setupPapi) {
17-
await setupPapi(targetDir);
16+
if (dappData.config.postinstallScript) {
17+
await spawnAndWait("bash", ["-c", dappData.config.postinstallScript], { cwd: targetDir, shell: false });
1818
}
1919

2020
console.log(
@@ -65,20 +65,3 @@ async function installDeps(targetDir: string, dappData: DappData): Promise<void>
6565
await spawnAndWait("npm", ["install"], { cwd: path.join(targetDir, root) });
6666
}
6767
}
68-
69-
async function setupPapi(targetDir: string): Promise<void> {
70-
console.log(c.primary("Setting up polkadot-api..."));
71-
72-
await spawnAndWait("npx", ["papi", "add", "--skip-codegen", "-n", "paseo", "paseo"], { cwd: targetDir });
73-
await spawnAndWait("npx", ["papi", "add", "--skip-codegen", "-n", "paseo_asset_hub", "paseo_asset_hub"], {
74-
cwd: targetDir,
75-
});
76-
await spawnAndWait("npx", ["papi", "add", "--skip-codegen", "-n", "polkadot", "polkadot"], {
77-
cwd: targetDir,
78-
});
79-
await spawnAndWait("npx", ["papi", "add", "--skip-codegen", "-n", "polkadot_asset_hub", "polkadot_asset_hub"], {
80-
cwd: targetDir,
81-
});
82-
83-
await spawnAndWait("npx", ["papi"], { cwd: targetDir });
84-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": 0,
3+
"descriptorPath": ".papi/descriptors",
4+
"entries": {
5+
"paseo": {
6+
"chain": "paseo",
7+
"metadata": ".papi/metadata/paseo.scale",
8+
"genesis": "0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f",
9+
"codeHash": "0xcc4b027a0dbb5e0f389dd8418c41012d618290a22f84af8411c8fd20b2738304"
10+
},
11+
"paseo_asset_hub": {
12+
"chain": "paseo_asset_hub",
13+
"metadata": ".papi/metadata/paseo_asset_hub.scale",
14+
"genesis": "0xd6eec26135305a8ad257a20d003357284c8aa03d0bdb2b357ab0a22371e11ef2",
15+
"codeHash": "0xb7f52ff9b4fb5124568a5b8cbfcebba2bc9318bcb5916b69457c10bc6a2d0ac5"
16+
},
17+
"polkadot": {
18+
"chain": "polkadot",
19+
"metadata": ".papi/metadata/polkadot.scale",
20+
"genesis": "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
21+
"codeHash": "0x716bb701ec19452fa522cdaa83ef101d368ba2bcfd89fde9acb6f793a420a616"
22+
},
23+
"polkadot_asset_hub": {
24+
"chain": "polkadot_asset_hub",
25+
"metadata": ".papi/metadata/polkadot_asset_hub.scale",
26+
"genesis": "0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f",
27+
"codeHash": "0x6e20bc52aaaafd1de82ba7d2a3c0fa39193787e240b93608489cf72a4c46a584"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)