|
@@ -1,13 +1,25 @@
|
|
|
#!/usr/bin/env zx
|
|
#!/usr/bin/env zx
|
|
|
import "zx/globals";
|
|
import "zx/globals";
|
|
|
|
|
|
|
|
-// $.verbose = false;
|
|
|
|
|
|
|
+$.verbose = false;
|
|
|
|
|
|
|
|
-const projects = {
|
|
|
|
|
|
|
+const CLIENTS = ["js", "rust"];
|
|
|
|
|
+const PROJECTS = {
|
|
|
"counter-shank": ["--shank"],
|
|
"counter-shank": ["--shank"],
|
|
|
"counter-anchor": ["--shank"],
|
|
"counter-anchor": ["--shank"],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// Parse CLI arguments.
|
|
|
|
|
+const selectedProjects = argv._;
|
|
|
|
|
+const projects =
|
|
|
|
|
+ selectedProjects.length > 0
|
|
|
|
|
+ ? Object.keys(PROJECTS).filter((project) =>
|
|
|
|
|
+ selectedProjects.includes(project)
|
|
|
|
|
+ )
|
|
|
|
|
+ : Object.keys(PROJECTS);
|
|
|
|
|
+const runTests = !!argv.test;
|
|
|
|
|
+
|
|
|
|
|
+// Resolve paths.
|
|
|
const bin = path.resolve(__dirname, "../outfile.cjs");
|
|
const bin = path.resolve(__dirname, "../outfile.cjs");
|
|
|
const submodulesDirectory = path.resolve(__dirname, "../submodules/");
|
|
const submodulesDirectory = path.resolve(__dirname, "../submodules/");
|
|
|
|
|
|
|
@@ -15,7 +27,7 @@ if (!fs.existsSync(submodulesDirectory)) {
|
|
|
fs.mkdirSync(submodulesDirectory);
|
|
fs.mkdirSync(submodulesDirectory);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-for (const projectName in projects) {
|
|
|
|
|
|
|
+for (const projectName of projects) {
|
|
|
// Go the submodules directory before creating each project.
|
|
// Go the submodules directory before creating each project.
|
|
|
cd(submodulesDirectory);
|
|
cd(submodulesDirectory);
|
|
|
|
|
|
|
@@ -25,24 +37,72 @@ for (const projectName in projects) {
|
|
|
fs.rmSync(projectName, { recursive: true, force: true });
|
|
fs.rmSync(projectName, { recursive: true, force: true });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Create the project.
|
|
|
|
|
- const verb = projectExists ? "Re-creating" : "Creating";
|
|
|
|
|
- echo(`${verb} project ${projectName}...`);
|
|
|
|
|
- const projectArgs = projects[projectName];
|
|
|
|
|
- await $`node ${[bin, projectName, ...projectArgs, "--force", "--default"]}`;
|
|
|
|
|
|
|
+ // Log project start.
|
|
|
|
|
+ echo(chalk.blue(chalk.bold(`${projectName}:`)));
|
|
|
|
|
+
|
|
|
|
|
+ // Scaffold the project.
|
|
|
|
|
+ const args = [projectName, ...PROJECTS[projectName]];
|
|
|
|
|
+ await executeStep(
|
|
|
|
|
+ "scaffold the project",
|
|
|
|
|
+ () => $`node ${[bin, ...args, "--force", "--default"]}`
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// Go inside the created project.
|
|
// Go inside the created project.
|
|
|
const projectDirectory = path.resolve(submodulesDirectory, projectName);
|
|
const projectDirectory = path.resolve(submodulesDirectory, projectName);
|
|
|
cd(projectDirectory);
|
|
cd(projectDirectory);
|
|
|
const pkg = require(path.resolve(projectDirectory, "package.json"));
|
|
const pkg = require(path.resolve(projectDirectory, "package.json"));
|
|
|
|
|
|
|
|
- // Install the project's dependencies.
|
|
|
|
|
- await $`pnpm install`;
|
|
|
|
|
|
|
+ // Install project's dependencies.
|
|
|
|
|
+ await executeStep("install NPM dependencies", async () => {
|
|
|
|
|
+ await $`pnpm install`;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Generate IDLs.
|
|
|
|
|
+ if ("generate:idls" in pkg.scripts) {
|
|
|
|
|
+ await executeStep("generate IDLs", async () => {
|
|
|
|
|
+ await $`pnpm generate:idls`;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Generate the clients.
|
|
|
|
|
- if ("generate" in pkg.scripts) {
|
|
|
|
|
- await $`pnpm generate`;
|
|
|
|
|
|
|
+ // Generate clients.
|
|
|
|
|
+ if ("generate:clients" in pkg.scripts) {
|
|
|
|
|
+ await executeStep("generate clients", async () => {
|
|
|
|
|
+ await $`pnpm generate:clients`;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (runTests) {
|
|
|
|
|
+ // Test programs.
|
|
|
|
|
+ if ("programs:test" in pkg.scripts) {
|
|
|
|
|
+ await executeStep("test programs", async () => {
|
|
|
|
|
+ await $`pnpm programs:test`;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Test clients.
|
|
|
|
|
+ for (const client of CLIENTS) {
|
|
|
|
|
+ if (`clients:${client}:test` in pkg.scripts) {
|
|
|
|
|
+ await executeStep(`test ${client} clients`, async () => {
|
|
|
|
|
+ await $`pnpm clients:${client}:test`;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Add line break between projects.
|
|
|
|
|
+ echo("");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
echo(chalk.green("All projects were created successfully!"));
|
|
echo(chalk.green("All projects were created successfully!"));
|
|
|
|
|
+
|
|
|
|
|
+async function executeStep(title, fn) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const capitalizedTitle = title.charAt(0).toUpperCase() + title.slice(1);
|
|
|
|
|
+ await spinner(`${capitalizedTitle}...`, fn);
|
|
|
|
|
+ echo(chalk.green("✔︎") + ` ${capitalizedTitle}.`);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ echo(chalk.red("✘") + ` Failed to ${title}.\n`);
|
|
|
|
|
+ echo(e);
|
|
|
|
|
+ process.exit(1);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|