Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat(cli): sourcemap option
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 12, 2018
1 parent 8d3badc commit f9ef816
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ const buildDisplayVersion = async () => {
*
* @param sassOption
*/
const buildSassOption = (context: ReturnType<typeof buildContext>, options: commandLineArgs.CommandLineOptions) => {
const buildSassOption = (
context: ReturnType<typeof buildContext>,
options: commandLineArgs.CommandLineOptions,
outFile: string | undefined
) => {
const sassOption = context.options.create();
//Set default values
sassOption.outputStyle = OutputStyle.SASS_STYLE_NESTED;
Expand All @@ -84,6 +88,8 @@ const buildSassOption = (context: ReturnType<typeof buildContext>, options: comm
Object.keys(options)
.map(key => ({ key, value: options[key] }))
.forEach(({ key, value }) => {
d(`Setting sass options for `, { key, value });

switch (key) {
case 'stdin':
break;
Expand All @@ -104,7 +110,16 @@ const buildSassOption = (context: ReturnType<typeof buildContext>, options: comm
sassOption.addPluginPath(value);
break;
case 'sourcemap':
break;
sassOption.sourceMapEmbed = value === 'inline' || (value === 'auto' && !outFile);
if (!!outFile && !sassOption.sourceMapEmbed) {
sassOption.sourceMapFile = `${outFile}.map`;
}
d(`Setting source map`, {
value,
outFile,
embed: sassOption.sourceMapEmbed,
mapFile: sassOption.sourceMapFile
});
case 'omitMapComment':
sassOption.omitMapComment = true;
break;
Expand Down Expand Up @@ -136,13 +151,14 @@ const main = async () => {

const { loadModule } = await import('./loadModule');
const { context } = await loadModule();
const sassOption = buildSassOption(context, options);

const files: Array<string> = options.files || [];
if (files.length > 2) {
throw new Error(`Unexpected arguments provided, '${files.slice(2)}'`);
}

const [, outFile] = files;
const sassOption = buildSassOption(context, options, outFile);

sassOption.dispose();
};

Expand Down

0 comments on commit f9ef816

Please sign in to comment.