Skip to content

Commit

Permalink
feat(cli): add info command to list available compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
joneff committed Sep 5, 2022
1 parent 7dcfe77 commit e32c87d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './build';
export * from './compile';
export * from './info';
export * from './migrate';
39 changes: 39 additions & 0 deletions src/cli/commands/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const compilerList = [
'node-sass',
'sass',
'sass-embedded'
];

export function cliInfo() {
const compilerInfo = getCompilerInfo(compilerList);

if (compilerInfo.length > 0) {
process.stdout.write('The following sass compilers are installed:\n');
compilerInfo.forEach(info => {
const [ main ] = info.split('\n');
const [ compiler, version ] = main.split('\t');

process.stdout.write(`- ${compiler}\t${version}\n`);
});
} else {
process.stdout.write('No sass compilers found!\n');
}
}

function getCompilerInfo(compilerList : string[]) {
const compilerInfo: string[] = [];
compilerList.forEach(name => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { info } = require(name);

if (info) {
compilerInfo.push( info );
}
} catch (e) {
// no compiler with such name
}
});

return compilerInfo;
}

0 comments on commit e32c87d

Please sign in to comment.