Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add option to exclude files from test and script selection
Browse files Browse the repository at this point in the history
- Excludes files
- Improve github workflow
- Update readme
  • Loading branch information
marc-aurele-besner committed Apr 3, 2022
1 parent 438abd8 commit 54a1f83
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 29 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/PrettierAndTSLint.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Prettier

on:
pull_request:
workflow_dispatch:

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
- uses: actions/checkout@v2with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Prettify code
uses: creyD/[email protected]
with:
prettier_options: --write src/
only_changed: True
22 changes: 22 additions & 0 deletions .github/workflows/tslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: TSLint

on:
pull_request:
workflow_dispatch:

jobs:
tslint:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout
- uses: actions/checkout@v2with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: NPM Clean Install
run: npm ci
- name: TSLint
uses: mooyoul/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
pattern: 'src/*.ts'
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![license](https://img.shields.io/github/license/jamesisaac/react-native-background-task.svg)](https://opensource.org/licenses/MIT)

# hardhat-awesome-cli
# 👷 hardhat-awesome-cli
Hardhat made awesome with a flexible CLI to help run test, deploy and more.

# This package is not yet published on npmjs, for now
Expand Down Expand Up @@ -38,15 +38,22 @@ or inside hardhat.config.ts
import hardhatAwesomeCli from 'hardhat-awesome-cli'
```

## Done
## 💪 Done
- Run test on all or sigle test file (from all your file in test/)
- Run scripts on all or sigle scripts file (from all your file in scripts/)
- Setting:
- Settings:
- Activate/Disable chain to show on test/scripts options
- Build .env file with rpc url and private key (or mnemonic)
- More settings
- Exclude files from, tests and scripts selection (useful for config and share helper file)
- Create Mock contracts (ERC20, ERC721, ERC1155 + Upgradeable version)

## To do:
- Settings:
- Build .env file with rpc url and private key (inject both chain and .env info in hardhat.config)
- Select or exclude file from the test&script directory (to generate a list of different test&scripts to be run and not show these files)
- Add tool to log all contracts deploy on each chain (1 unique contractName/chain + full log)
## 🏗️ To do:
- Inject chain settings, rpc and accounts in hardhat.config
- Offer to generate deployment script and test script for Mock contract created
- Deployment contract generator
- More Settings:
- Create github workflows file to run test and coverage test
- Setup slack API or email report to receive a copy of test result and contracts list deployed
- Add tool to log all contracts deploy on each chain (1 unique contractName/chain + full log)
- Add option to create Admin Proxy and Transparent proxy w/ appropriate deployment scripts
194 changes: 191 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const buildActivatedChainList = async () => {
return chainList
}

const buildTestsList = async () => {
const buildAllTestsList = async () => {
const testList = []
if (fs.existsSync('test')) {
testList.push({
Expand All @@ -171,7 +171,7 @@ const buildTestsList = async () => {
return testList
}

const buildScriptsList = async () => {
const buildAllScriptsList = async () => {
const testList = []
if (fs.existsSync('scripts')) {
const files = fs.readdirSync('scripts')
Expand All @@ -192,6 +192,44 @@ const buildScriptsList = async () => {
return testList
}

const buildTestsList = async () => {
let allTestList = await buildAllTestsList()
let excludedFiles = await buildExcludedFile()
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test) => test.directory === 'test')
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.map((file) => {
return file.filePath
})
allTestList = allTestList.filter((script) => {
return !excludedFiles.includes(script.filePath)
})
return allTestList
}
} else {
return allTestList
}
}

const buildScriptsList = async () => {
let allScriptList = await buildAllScriptsList()
let excludedFiles = await buildExcludedFile()
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test) => test.directory === 'scripts')
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.map((file) => {
return file.filePath
})
allScriptList = allScriptList.filter((script) => {
return !excludedFiles.includes(script.filePath)
})
return allScriptList
}
} else {
return allScriptList
}
}

const buildMockContract = async (contractName) => {
const packageRootPath = path.join(path.dirname(require.main.filename), '../../../hardhat-easy-cli/src/mockContracts')
if (fs.existsSync('scripts')) {
Expand All @@ -214,13 +252,26 @@ const buildMockContract = async (contractName) => {
}
}

const buildExcludedFile = async () => {
let fileSetting: any = []
if (fs.existsSync(fileHardhatAwesomeCLI)) {
const rawdata: any = fs.readFileSync(fileHardhatAwesomeCLI)
fileSetting = JSON.parse(rawdata)
if (fileSetting && fileSetting.excludedFiles) {
return fileSetting.excludedFiles
}
}
return []
}

const addChain = async (chainName, chainToAdd) => {
let fileSetting: any = []
if (fs.existsSync(fileHardhatAwesomeCLI)) {
const rawdata: any = fs.readFileSync(fileHardhatAwesomeCLI)
fileSetting = JSON.parse(rawdata)
if (fileSetting && !fileSetting.activatedChain) {
fileSetting = {
...fileSetting,
activatedChain: []
}
}
Expand Down Expand Up @@ -294,6 +345,80 @@ const addCustomChain = async (chainDetails) => {
}
}

const addExcludedFiles = async (directory, filePath) => {
let fileSetting: any = []
const fileToAdd = {
directory,
filePath
}
if (fs.existsSync(fileHardhatAwesomeCLI)) {
const rawdata: any = fs.readFileSync(fileHardhatAwesomeCLI)
fileSetting = JSON.parse(rawdata)
if (fileSetting && !fileSetting.excludedFiles) {
fileSetting = {
...fileSetting,
excludedFiles: []
}
}
} else {
fileSetting = {
excludedFiles: []
}
}
if (fileSetting && fileSetting.excludedFiles) {
if (fileSetting.excludedFiles.length > 0) {
if (!fileSetting.excludedFiles.find((file) => file.directory === directory && file.filePath === filePath)) {
fileSetting.excludedFiles.push(fileToAdd)
}
} else {
fileSetting.excludedFiles.push(fileToAdd)
}
} else {
fileSetting.push({
excludedFiles: [fileToAdd]
})
}
try {
fs.writeFileSync(fileHardhatAwesomeCLI, JSON.stringify(fileSetting, null, 2))
} catch {
console.log(chalk.red('Error adding file: ' + directory + '/' + filePath + ' to your excluded files settings!'))
}
}

const removeExcludedFiles = async (directory, filePath) => {
let allFiles: any = []
const excludedFiles: any = []
if (directory === 'test') {
allFiles = (await buildAllTestsList())
.filter((test) => test.type === 'file')
.map((file) => {
return file.filePath
})
} else if (directory === 'script') {
allFiles = (await buildAllScriptsList())
.filter((script) => script.type === 'file')
.map((file) => {
return file.filePath
})
}
const fileToRemove = allFiles.find((file) => file.directory === directory && file.filePath === filePath)
let fileSetting: any = []
if (fs.existsSync(fileHardhatAwesomeCLI)) {
const rawdata: any = fs.readFileSync(fileHardhatAwesomeCLI)
fileSetting = JSON.parse(rawdata)
if (fileSetting && fileSetting.excludedFiles) {
if (fileSetting.excludedFiles.length > 0) {
fileSetting.excludedFiles
.filter((file) => file.directory === directory && file.filePath === filePath)
.forEach(() => {
fileSetting.excludedFiles.pop(fileToRemove)
fs.writeFileSync(fileHardhatAwesomeCLI, JSON.stringify(fileSetting, null, 2))
})
}
}
}
}

const getEnvValue = async (envName) => {
if (fs.existsSync(fileEnvHardhatAwesomeCLI)) {
const allEnv = require('dotenv').config({ path: fileEnvHardhatAwesomeCLI })
Expand Down Expand Up @@ -588,7 +713,70 @@ const serveSettingSelector = async (env) => {
})
}

const serveMoreSettingSelector = async () => {}
const serveExcludeFileSelector = async (option) => {
let allFiles: any = []
let excludedFiles: any = await buildExcludedFile()
if (option === 'test') {
allFiles = await buildAllTestsList()
} else if (option === 'scripts') {
allFiles = await buildAllScriptsList()
}
if (allFiles && allFiles.length > 0) {
allFiles = allFiles
.filter((test) => test.type === 'file')
.map((file) => {
return file.filePath
})
}
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test) => test.directory === option)
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.map((file) => {
return file.filePath
})
}
}
await inquirer
.prompt([
{
type: 'checkbox',
name: 'allFiles',
message: 'Select the files you want to exclude',
choices: allFiles,
default: excludedFiles
}
])
.then(async (activateFilesSelected) => {
allFiles.map(async (file: any) => {
if (activateFilesSelected.allFiles.includes(file)) {
await addExcludedFiles(option, file)
} else {
await removeExcludedFiles(option, file)
}
})
console.log(chalk.green('Settings updated!'))
})
}

const serveMoreSettingSelector = async () => {
await inquirer
.prompt([
{
type: 'list',
name: 'moreSettings',
message: 'Select a mock contract',
choices: ['Exclude test file from the tests selection list', 'Exclude script file from the scripts selection list']
}
])
.then(async (moreSettingsSelected) => {
if (moreSettingsSelected.moreSettings === 'Exclude test file from the tests selection list') {
await serveExcludeFileSelector('test')
}
if (moreSettingsSelected.moreSettings === 'Exclude script file from the scripts selection list') {
await serveExcludeFileSelector('scripts')
}
})
}

const serveMockContractCreatorSelector = async () => {
if (MockContractsList) {
Expand Down

0 comments on commit 54a1f83

Please sign in to comment.