Skip to content

Commit

Permalink
chore: make typescript optional in build
Browse files Browse the repository at this point in the history
  • Loading branch information
Caele committed May 24, 2022
1 parent 0457175 commit c90fe4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion commands/build/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const postcss = require('rollup-plugin-postcss');
const replace = require('@rollup/plugin-replace');
const sourcemaps = require('rollup-plugin-sourcemaps');
const jsxPlugin = require('@babel/plugin-transform-react-jsx');
const typescriptPlugin = require('@rollup/plugin-typescript');
const json = require('@rollup/plugin-json');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
Expand Down Expand Up @@ -78,8 +77,15 @@ const config = ({
const auth = typeof author === 'object' ? `${author.name} <${author.email}>` : author || '';
const moduleName = name.split('/').reverse()[0];
const extensions = ['.mjs', '.js', '.jsx', '.json', '.node'];

let typescriptPlugin;
if (typescript) {
extensions.push('.tsx', '.ts');
try {
typescriptPlugin = require('@rollup/plugin-typescript'); // eslint-disable-line
} catch (e) {
throw new Error(`Please install '@rollup/plugin-typescript' to build using typescript.`);
}
}

const banner = `/*
Expand Down
2 changes: 1 addition & 1 deletion commands/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-replace": "4.0.0",
"@rollup/plugin-typescript": "8.3.2",
"chalk": "4.1.2",
"extend": "3.0.2",
"postcss": "^8.4.13",
Expand All @@ -42,6 +41,7 @@
},
"devDependencies": {
"tslib": "*",
"@rollup/plugin-typescript": "8.3.2",
"typescript": ">=4.6.4"
}
}
6 changes: 6 additions & 0 deletions commands/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ yargs.usage('nebula <command> [options]');

const tryAddCommand = (m) => {
let cmd;
let error;
try {
cmd = require(`${m}/command`); // eslint-disable-line
} catch (e) {
error = e;
cmd = importCwd.silent(`${m}/command`);
}

if (cmd) {
yargs.command(cmd);
} else {
// Print the error
if (error) {
console.log(`Error from import: ${error.message}`);
}
// add dummy command in order to instruct user how to install missing package
const comm = m.split('-')[1];
yargs.command({
Expand Down

0 comments on commit c90fe4b

Please sign in to comment.