1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/env node
- /* -----------------------------------------------------------------------------
- | Copyright (c) Jupyter Development Team.
- | Distributed under the terms of the Modified BSD License.
- |----------------------------------------------------------------------------*/
- // Build an extension
- // Inputs:
- // Path to extension (required)
- // Dev vs prod (dev is default)
- // Output path (defaults to <extension>/build)
- // Outputs
- // Webpack build assets
- import * as path from 'path';
- import commander from 'commander';
- import { run } from '@jupyterlab/buildutils';
- commander
- .description('Build an extension')
- .option('--development', 'build in development mode (implies --source-map)')
- .option('--source-map', 'generate source maps')
- .requiredOption('--core-path <path>', 'the core package directory')
- .option(
- '--static-url <url>',
- 'url for build assets, if hosted outside the built extension'
- )
- .option('--watch')
- .action(async cmd => {
- const mode = cmd.development ? 'development' : 'production';
- const corePath = path.resolve(cmd.corePath || process.cwd());
- const packagePath = path.resolve(cmd.args[0]);
- const sourceMap = cmd.sourceMap ? 'true' : '';
- const webpack = require.resolve('webpack-cli/bin/cli.js');
- const config = path.join(__dirname, 'webpack.config.ext.js');
- let cmdText = `node "${webpack}" --config "${config}" --mode ${mode}`;
- if (cmd.watch) {
- cmdText += ' --watch';
- }
- const env = {
- PACKAGE_PATH: packagePath,
- NODE_ENV: mode,
- CORE_PATH: corePath,
- STATIC_URL: cmd.staticUrl,
- SOURCE_MAP: sourceMap
- };
- run(cmdText, { env: { ...process.env, ...env } });
- });
- commander.parse(process.argv);
- // If no arguments supplied
- if (!process.argv.slice(2).length) {
- commander.outputHelp();
- process.exit(1);
- }
|