Skip to content

Commit

Permalink
Merge pull request #73 from smorimoto/silent-opt
Browse files Browse the repository at this point in the history
Add `silent` option
  • Loading branch information
jihchi authored Apr 7, 2024
2 parents 008f289 + 10c3e1a commit 34c8c0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default defineConfig({
output: './lib/js',
suffix: '.mjs',
},
silent: false,
}),
],
});
Expand Down
21 changes: 14 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ type ReScriptProcess = {
shutdown: () => void;
};

async function launchReScript(watch: boolean): Promise<ReScriptProcess> {
async function launchReScript(
watch: boolean,
silent: boolean
): Promise<ReScriptProcess> {
const cmd = watch
? 'rescript build -with-deps -w'
: 'rescript build -with-deps';
Expand All @@ -30,8 +33,10 @@ async function launchReScript(watch: boolean): Promise<ReScriptProcess> {

function dataListener(chunk: any) {
const output = chunk.toString().trimEnd();
// eslint-disable-next-line no-console
console.log(logPrefix, output);
if (!silent) {
// eslint-disable-next-line no-console
console.log(logPrefix, output);
}
if (watch && output.includes('>>>> Finish compiling')) {
compileOnce(true);
}
Expand Down Expand Up @@ -63,17 +68,19 @@ interface Config {
output?: string;
suffix?: string;
};
silent?: boolean;
}

export default function createReScriptPlugin(config?: Config): Plugin {
let root: string;
let usingLoader = false;
let childProcessReScript: undefined | ReScriptProcess;

// Retrieve loader config
// Retrieve config
const output = config?.loader?.output ?? './lib/es6';
const suffix = config?.loader?.suffix ?? '.bs.js';
const suffixRegex = new RegExp(`${suffix.replace('.', '\\.')}$`);
const silent = config?.silent ?? false;

return {
name: '@jihchi/vite-plugin-rescript',
Expand All @@ -94,10 +101,10 @@ export default function createReScriptPlugin(config?: Config): Plugin {
// The watch command can only be run by one process at the same time.
const isLocked = existsSync(path.resolve('./.bsb.lock'));

const watch = !isLocked && (command === 'serve' || Boolean(build.watch));

if (needReScript) {
childProcessReScript = await launchReScript(
!isLocked && (command === 'serve' || Boolean(build.watch))
);
childProcessReScript = await launchReScript(watch, silent);
}
},
config: (userConfig) => ({
Expand Down

0 comments on commit 34c8c0d

Please sign in to comment.