Skip to content

Commit

Permalink
[cli] mops watch refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenVoich committed Oct 3, 2024
1 parent 80f0757 commit 63c34ba
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import process from 'node:process';
import fs from 'node:fs';
import events from 'node:events';
import {Command, Argument, Option} from 'commander';

import {init} from './commands/init.js';
Expand Down Expand Up @@ -34,6 +35,8 @@ declare global {
var mopsReplicaTestRunning : boolean;
}

events.setMaxListeners(20);

let networkFile = getNetworkFile();
if (fs.existsSync(networkFile)) {
globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export async function sources({conflicts = 'ignore' as 'warning' | 'error' | 'ig
}

return `--package ${name} ${pkgBaseDir}`;
});
}).filter(x => x != null);
}
2 changes: 1 addition & 1 deletion cli/commands/test/reporters/silent-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SilentReporter implements Reporter {
this.failedFiles += Number(mmf.failed !== 0);

if (mmf.failed) {
let output = `${chalk.red('✖'), absToRel(file)}\n${mmf.getErrorMessages().join('\n')}\n${'-'.repeat(50)}`;
let output = `${chalk.red('✖')} ${absToRel(file)}\n${mmf.getErrorMessages().join('\n')}\n${'-'.repeat(50)}`;

if (this.flushOnError) {
console.log(output);
Expand Down
8 changes: 4 additions & 4 deletions cli/commands/watch/deployer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import os from 'node:os';
import {promisify} from 'node:util';
import {exec, execSync} from 'node:child_process';
import {execFile, execSync} from 'node:child_process';

import {ErrorChecker} from './error-checker.js';
import {Generator} from './generator.js';
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Deployer {
let {signal} = controller;
this.controllers.set(canister, controller);

await promisify(exec)(`dfx canister create ${canister}`, {cwd: rootDir, signal}).catch((error) => {
await promisify(execFile)('dfx', ['canister', 'create', canister], {cwd: rootDir, signal}).catch((error) => {
if (error.code === 'ABORT_ERR') {
return {stderr: ''};
}
Expand All @@ -104,7 +104,7 @@ export class Deployer {

// build
if (this.generator.status !== 'success') {
await promisify(exec)(`dfx build ${canister}`, {cwd: rootDir, signal}).catch((error) => {
await promisify(execFile)('dfx', ['build', canister], {cwd: rootDir, signal}).catch((error) => {
if (error.code === 'ABORT_ERR') {
return {stderr: ''};
}
Expand All @@ -113,7 +113,7 @@ export class Deployer {
}

// install
await promisify(exec)(`dfx canister install --mode=auto ${canister}`, {cwd: rootDir, signal}).catch((error) => {
await promisify(execFile)('dfx', ['canister', 'install', '--mode=auto', canister], {cwd: rootDir, signal}).catch((error) => {
if (error.code === 'ABORT_ERR') {
return {stderr: ''};
}
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/watch/error-checker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {exec} from 'node:child_process';
import {execFile} from 'node:child_process';
import {promisify} from 'node:util';
import os from 'node:os';
import chalk from 'chalk';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ErrorChecker {

await parallel(os.cpus().length, paths, async (file) => {
try {
await promisify(exec)(`${mocPath} --check ${deps.join(' ')} ${file}`, {cwd: rootDir});
await promisify(execFile)(mocPath, ['--check', ...deps.flatMap(x => x.split(' ')), file], {cwd: rootDir});
}
catch (error : any) {
error.message.split('\n').forEach((line : string) => {
Expand Down
10 changes: 5 additions & 5 deletions cli/commands/watch/generator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from 'node:os';
import {promisify} from 'node:util';
import {execFile} from 'node:child_process';
import chalk from 'chalk';

import {ErrorChecker} from './error-checker.js';
import {parallel} from '../../parallel.js';
import os from 'node:os';

import {promisify} from 'node:util';
import {exec} from 'node:child_process';
import {getRootDir} from '../../mops.js';

export class Generator {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Generator {
let {signal} = controller;
this.controllers.set(canister, controller);

await promisify(exec)(`dfx generate ${canister}`, {cwd: rootDir, signal}).catch((error) => {
await promisify(execFile)('dfx', ['generate', canister], {cwd: rootDir, signal}).catch((error) => {
if (error.code === 'ABORT_ERR') {
return {stderr: ''};
}
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/watch/warning-checker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {exec} from 'node:child_process';
import {execFile} from 'node:child_process';
import {promisify} from 'node:util';
import os from 'node:os';
import chalk from 'chalk';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class WarningChecker {
let {signal} = controller;
this.controllers.set(file, controller);

let {stderr} = await promisify(exec)(`${mocPath} --check ${deps.join(' ')} ${file}`, {cwd: rootDir, signal}).catch((error) => {
let {stderr} = await promisify(execFile)(mocPath, ['--check', ...deps.flatMap(x => x.split(' ')), file], {cwd: rootDir, signal}).catch((error) => {
if (error.code === 'ABORT_ERR') {
return {stderr: ''};
}
Expand Down

0 comments on commit 63c34ba

Please sign in to comment.