Skip to content

Commit

Permalink
separate common and contract template processing
Browse files Browse the repository at this point in the history
  • Loading branch information
codespool committed May 8, 2023
1 parent 318f139 commit fbb90be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"inquirer-fuzzy-path": "^2.3.0",
"js-toml": "^0.1.1",
"listr2": "5.0.7",
"lodash": "^4.17.21",
"mocha": "10.2.0",
"mocha-suppress-logs": "0.3.1",
"mochawesome": "7.1.3",
Expand Down
29 changes: 23 additions & 6 deletions packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import TOML from "@iarna/toml";
import { choice, email, name, pickLanguage, pickTemplate } from "../../lib/prompts";
import {
checkCliDependencies,
copyTemplateFiles,
copyCommonTemplateFiles,
copyContractTemplateFiles,
downloadNode,
installDeps,
ChainAccount,
Expand All @@ -30,7 +31,7 @@ import {
import { getAllTemplateNames, getTemplates } from "@astar-network/swanky-templates";
import { BaseCommand } from "../../lib/baseCommand";
import globby = require("globby");

import { merge } from "lodash";
import inquirerFuzzyPath from "inquirer-fuzzy-path";

const {
Expand Down Expand Up @@ -146,6 +147,23 @@ export class Init extends BaseCommand {
await this.generate(args.projectName);
}

const templates = getTemplates("ink");
this.taskQueue.push({
task: copyCommonTemplateFiles,
args: [templates.templatesPath, this.projectPath],
runningMessage: "Copying common template files",
});

this.taskQueue.push({
task: processTemplates,
args: [
this.projectPath,
{
project_name: paramCase(args.projectName),
},
],
runningMessage: "Processing common templates",
});
this.taskQueue.push({
task: installDeps,
args: [this.projectPath],
Expand Down Expand Up @@ -238,14 +256,13 @@ export class Init extends BaseCommand {
});

this.taskQueue.push({
task: copyTemplateFiles,
task: copyContractTemplateFiles,
args: [
templates.templatesPath,
path.resolve(templates.contractTemplatesPath, answers.contractTemplate),
answers.contractName,
this.projectPath,
],
runningMessage: "Copying template files",
runningMessage: "Copying contract template files",
});

this.taskQueue.push({
Expand All @@ -263,7 +280,7 @@ export class Init extends BaseCommand {
contract_language: contractLanguage,
},
],
runningMessage: "Processing templates",
runningMessage: "Processing contract template",
});

this.configBuilder.contracts = {
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/lib/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ export async function checkCliDependencies(spinner: Spinner) {
}
}

export async function copyTemplateFiles(
templatesPath: string,
contractTemplatePath: string,
contractName: string,
projectPath: string
) {
export async function copyCommonTemplateFiles(templatesPath: string, projectPath: string) {
await ensureDir(projectPath);
const commonFiles = await globby(`*`, { cwd: templatesPath });
await Promise.all(
Expand All @@ -39,7 +34,6 @@ export async function copyTemplateFiles(
})
);
await rename(path.resolve(projectPath, "gitignore"), path.resolve(projectPath, ".gitignore"));
await copyContractTemplateFiles(contractTemplatePath, contractName, projectPath);
}

export async function copyContractTemplateFiles(
Expand Down

0 comments on commit fbb90be

Please sign in to comment.