Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/shaggy-meals-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@mimicprotocol/cli": patch
"@mimicprotocol/lib-ts": patch
"@mimicprotocol/test-ts": patch
---

Change directory to positional argument in init and test command
16 changes: 10 additions & 6 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { confirm } from '@inquirer/prompts'
import { Command, Flags } from '@oclif/core'
import { Args, Command, Flags } from '@oclif/core'
import * as fs from 'fs'
import * as path from 'path'
import simpleGit from 'simple-git'
Expand All @@ -10,16 +10,20 @@ import log from '../log'
export default class Init extends Command {
static override description = 'Initializes a new Mimic-compatible project structure in the specified directory'

static override examples = ['<%= config.bin %> <%= command.id %> --directory ./new-project --force']
static override examples = ['<%= config.bin %> <%= command.id %> ./new-project --force']

static override args = {
directory: Args.string({ description: 'Directory to initialize project', required: false, default: './' }),
}

static override flags = {
directory: Flags.string({ char: 'd', description: 'Directory to initialize project', default: './' }),
force: Flags.boolean({ char: 'f', description: 'Overwrite existing files if they already exist', default: false }),
}

public async run(): Promise<void> {
const { flags } = await this.parse(Init)
const { directory, force } = flags
const { args, flags } = await this.parse(Init)
const { directory } = args
const { force } = flags
const fullDirectory = path.resolve(directory)

if (force && fs.existsSync(fullDirectory) && fs.readdirSync(fullDirectory).length > 0) {
Expand Down Expand Up @@ -50,7 +54,7 @@ export default class Init extends Command {
this.error(`Directory ${log.highlightText(fullDirectory)} is not empty`, {
code: 'DirectoryNotEmpty',
suggestions: [
'You can specify the directory with --directory',
'You can specify the directory as a positional argument',
`You can ${log.warnText('overwrite')} an existing directory with --force`,
],
})
Expand Down
23 changes: 11 additions & 12 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Command, Flags } from '@oclif/core'
import { spawnSync } from 'child_process'
import { Args, Command, Flags } from '@oclif/core'
import * as path from 'path'

import { execBinCommand } from '../lib/packageManager'

export default class Test extends Command {
static override description = 'Runs task tests'

static override examples = ['<%= config.bin %> <%= command.id %> --directory ./']
static override examples = ['<%= config.bin %> <%= command.id %> ./']

static override flags = {
directory: Flags.string({ char: 'd', description: 'task directory', default: './' }),
skipCompile: Flags.boolean({ description: 'skip codegen and compile steps' }),
static override args = {
directory: Args.string({ description: 'task directory', required: false, default: './' }),
}

private runOrExit(cmd: string, args: string[], cwd: string) {
const result = spawnSync(cmd, args, { cwd, stdio: 'inherit' })
if (result.status !== 0) this.exit(result.status ?? 1)
static override flags = {
'skip-compile': Flags.boolean({ description: 'skip codegen and compile steps' }),
}

public async run(): Promise<void> {
const { flags } = await this.parse(Test)
const baseDir = path.resolve(flags.directory)
const { args, flags } = await this.parse(Test)
const { directory } = args
const { 'skip-compile': skipCompile } = flags
const baseDir = path.resolve(directory)
const testPath = path.join(baseDir, 'tests')

if (!flags.skipCompile) {
if (!skipCompile) {
const cg = execBinCommand('mimic', ['codegen'], baseDir)
if (cg.status !== 0) this.exit(cg.status ?? 1)
const cp = execBinCommand('mimic', ['compile'], baseDir)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/tests/commands/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('init', () => {
}

context('when force flag is not passed', () => {
const command = ['init', `--directory ${commandPath}`]
const command = ['init', commandPath]

context('when the directory exists', () => {
beforeEach('create directory', () => {
Expand All @@ -39,7 +39,7 @@ describe('init', () => {
})

context('when force flag is passed', () => {
const command = ['init', `--directory ${commandPath}`, '--force']
const command = ['init', commandPath, '--force']

context('when the directory exists', () => {
beforeEach('create directory', () => {
Expand Down