mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Adding sourceMap flag to extension cli to enable debugging (#9932)
This commit is contained in:
@@ -26,7 +26,15 @@ import { getLanguageFromPath, isLanguage } from '../utils/languages';
|
||||
import { Language } from '../types';
|
||||
import loadConfig from '../utils/load-config';
|
||||
|
||||
type BuildOptions = { type: string; input: string; output: string; language: string; force: boolean; watch: boolean };
|
||||
type BuildOptions = {
|
||||
type: string;
|
||||
input: string;
|
||||
output: string;
|
||||
language: string;
|
||||
force: boolean;
|
||||
watch: boolean;
|
||||
sourceMaps: boolean;
|
||||
};
|
||||
|
||||
export default async function build(options: BuildOptions): Promise<void> {
|
||||
const packagePath = path.resolve('package.json');
|
||||
@@ -79,8 +87,8 @@ export default async function build(options: BuildOptions): Promise<void> {
|
||||
|
||||
const spinner = ora('Building Directus extension...').start();
|
||||
|
||||
const rollupOptions = getRollupOptions(type, language, input, config.plugins);
|
||||
const rollupOutputOptions = getRollupOutputOptions(type, output);
|
||||
const rollupOptions = getRollupOptions(type, language, input, config.plugins, options);
|
||||
const rollupOutputOptions = getRollupOutputOptions(type, output, options);
|
||||
|
||||
if (options.watch) {
|
||||
const watcher = rollupWatch({
|
||||
@@ -127,7 +135,8 @@ function getRollupOptions(
|
||||
type: ExtensionType,
|
||||
language: Language,
|
||||
input: string,
|
||||
plugins: Plugin[] = []
|
||||
plugins: Plugin[] = [],
|
||||
options: BuildOptions
|
||||
): RollupOptions {
|
||||
if (isAppExtension(type)) {
|
||||
return {
|
||||
@@ -147,7 +156,7 @@ function getRollupOptions(
|
||||
},
|
||||
preventAssignment: true,
|
||||
}),
|
||||
terser(),
|
||||
options.sourceMaps ? null : terser(),
|
||||
],
|
||||
};
|
||||
} else {
|
||||
@@ -166,13 +175,13 @@ function getRollupOptions(
|
||||
},
|
||||
preventAssignment: true,
|
||||
}),
|
||||
terser(),
|
||||
options.sourceMaps ? null : terser(),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getRollupOutputOptions(type: ExtensionType, output: string): RollupOutputOptions {
|
||||
function getRollupOutputOptions(type: ExtensionType, output: string, options: BuildOptions): RollupOutputOptions {
|
||||
if (isAppExtension(type)) {
|
||||
return {
|
||||
file: output,
|
||||
@@ -183,6 +192,7 @@ function getRollupOutputOptions(type: ExtensionType, output: string): RollupOutp
|
||||
file: output,
|
||||
format: 'cjs',
|
||||
exports: 'default',
|
||||
sourcemap: options.sourceMaps,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ program
|
||||
.option('-l, --language <language>', 'overwrite the language to use')
|
||||
.option('-f, --force', 'ignore the package manifest')
|
||||
.option('-w, --watch', 'watch and rebuild on changes')
|
||||
.option('-m --sourceMaps', 'include source maps in output')
|
||||
.action(build);
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user