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
5 changes: 5 additions & 0 deletions .changeset/silly-drinks-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/plugin-cli": patch
---

Add watch event detail about eventName and its target
9 changes: 7 additions & 2 deletions packages/plugin-cli/src/utils/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';

import { logger, time } from '@ima/dev-utils/logger';
import { logger, time, printTime } from '@ima/dev-utils/logger';
import anymatch from 'anymatch';
import chalk from 'chalk';
import chokidar from 'chokidar';
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function parsePkgJson(basePath: string): Promise<{
}

function errorHandler(error: Error) {
logger.error('An error occurred while wathing files');
logger.error('An error occurred while watching files');
console.error(error);
}

Expand Down Expand Up @@ -187,6 +187,7 @@ export async function watch(args: Arguments) {
.on('error', errorHandler)
.on('all', async (eventName, filePath) => {
const contextPath = path.relative(inputDir, filePath);
const fileName = path.basename(filePath);

batch(async () => {
switch (eventName) {
Expand All @@ -203,13 +204,17 @@ export async function watch(args: Arguments) {
const outputContextPath = path.join(outputPath, contextPath);

if (fs.existsSync(outputContextPath)) {
logger.write(
`${printTime()} ${chalk.green('Unlink')}: ${fileName}`
);
await fs.promises.rm(outputContextPath, {
recursive: true,
});
}
},
cwd
);

break;

default:
Expand Down
8 changes: 7 additions & 1 deletion packages/plugin-cli/src/utils/process.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';

import { logger } from '@ima/dev-utils/logger';
import { logger, printTime } from '@ima/dev-utils/logger';
import chalk from 'chalk';

import {
Expand Down Expand Up @@ -255,6 +255,12 @@ export async function createProcessingPipeline(ctx: Context) {
filePath,
outputDir,
};
const outputFilename = path.join(outputDir, fileName);

ctx.command === 'link' &&
logger.write(
`${printTime()} ${chalk.green('Linking')}: ${outputFilename}`
);

// Process transforms
source = await processTransformers(
Expand Down