Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jan 26, 2025
1 parent 113188f commit 18c7d9a
Show file tree
Hide file tree
Showing 9 changed files with 2,147 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.yarn
artifacts
cache
coverage
node_modules
typechain-types
dist
dist/typechain-types
docs
57 changes: 57 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require("path");

/**
* @type {import("eslint").Linter.Config}
*/
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
extends: ["plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
},
plugins: [
"@typescript-eslint",
"prettier",
"simple-import-sort",
"sort-keys-fix",
"typescript-sort-keys",
"prefer-arrow",
],
rules: {
"@typescript-eslint/sort-type-union-intersection-members": "error",
camelcase: "off",
"func-style": ["error", "expression", { allowArrowFunctions: true }],
"prefer-arrow/prefer-arrow-functions": [
"warn",
{
classPropertiesAllowed: false,
disallowPrototype: true,
singleReturnOnly: false,
},
],
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"sort-keys-fix/sort-keys-fix": "error",
"typescript-sort-keys/interface": "error",
"typescript-sort-keys/string-enum": "error",
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
},
typescript: {
project: path.join(__dirname, "tsconfig.json"),
},
},
},
};
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"create-universal-contract": "./dist/index.js"
},
"scripts": {
"build": "yarn tsc"
"build": "yarn tsc",
"lint:fix": "npm run lint:js:fix",
"lint:js:fix": "eslint --ext .js,.ts . --fix",
"lint:js": "eslint --ext .js,.ts .",
"lint": "npm run lint:js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,6 +40,18 @@
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/marked-terminal": "^6.1.1",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^8.21.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^10.0.1",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^3.3.0",
"prettier": "^3.4.2",
"typescript": "^5.7.3"
}
}
2 changes: 1 addition & 1 deletion src/cloneRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const cloneRepository = async (
tempDir: string,
branchName: string,
options: any,
isVerbose: boolean
isVerbose: boolean,
) => {
if (!options.cache || !fs.existsSync(tempDir)) {
if (fs.existsSync(tempDir)) {
Expand Down
12 changes: 6 additions & 6 deletions src/copyExample.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import fs from "fs-extra";
import path from "path";
import { select } from "@inquirer/prompts";
import fs from "fs-extra";
import { marked } from "marked";
import { markedTerminal } from "marked-terminal";
import path from "path";

marked.use(markedTerminal() as any);

export const copyExample = async (
chosenExample: string,
examplesDir: string,
outputDir: string,
isVerbose: boolean
isVerbose: boolean,
) => {
const sourceDir = path.join(examplesDir, chosenExample);

Expand All @@ -20,20 +20,20 @@ export const copyExample = async (
const targetDir = isOutputDirJustName
? path.resolve(process.cwd(), outputDir)
: path.isAbsolute(outputDir)
? outputDir
: path.resolve(process.cwd(), outputDir);
? outputDir
: path.resolve(process.cwd(), outputDir);

const finalTargetDir = isOutputDirJustName
? path.join(targetDir)
: path.join(targetDir, chosenExample);

if (fs.existsSync(finalTargetDir)) {
const overwrite = await select({
message: `The directory "${finalTargetDir}" already exists. Do you want to overwrite it?`,
choices: [
{ name: "Yes, overwrite it", value: true },
{ name: "No, cancel the operation", value: false },
],
message: `The directory "${finalTargetDir}" already exists. Do you want to overwrite it?`,
});

if (!overwrite) {
Expand Down
4 changes: 2 additions & 2 deletions src/getExampleDirectories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const getExampleDirectories = async (examplesDir: string) => {
description = packageJson.description || description;
}

return { name: dir.name, description };
})
return { description, name: dir.name };
}),
);

return examples;
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node
import { Command } from "commander";
import os from "os";
import path from "path";

import { cloneRepository } from "./cloneRepository";
import { copyExample } from "./copyExample";
import { getExampleDirectories } from "./getExampleDirectories";
import { promptForExample } from "./promptForExample";
import { copyExample } from "./copyExample";
import path from "path";
import os from "os";

const program = new Command();
const REPO_URL = "https://github.com/zeta-chain/example-contracts.git";
Expand All @@ -17,14 +18,14 @@ program
.name("create-universal-contracts")
.description(
"CLI tool for creating universal contracts on ZetaChain.\n" +
"For more information, visit: https://zetachain.com/docs"
"For more information, visit: https://zetachain.com/docs",
)
.option("--no-cache", "Bypass cached repository and re-clone")
.option("--verbose", "Enable verbose logging")
.option(
"--output <directory>",
"Specify custom output directory or name",
process.cwd()
process.cwd(),
);

program.parse(process.argv);
Expand Down
6 changes: 3 additions & 3 deletions src/promptForExample.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { select } from "@inquirer/prompts";

export const promptForExample = async (
directories: { name: string; description: string }[]
directories: { description: string; name: string }[],
): Promise<string> => {
const choices = directories.map((dir) => ({
name: `${dir.name}\t${dir.description}`,
value: dir.name,
short: dir.name,
value: dir.name,
}));

const chosenExample = await select({
message: "Which example do you want to create?",
choices,
message: "Which example do you want to create?",
});

return chosenExample;
Expand Down
Loading

0 comments on commit 18c7d9a

Please sign in to comment.