Skip to content

Commit

Permalink
refactor: replace help.md alias import with help file generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Feb 9, 2022
1 parent 91d2dbd commit 1e6f5a9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -14,3 +14,5 @@ test/tmp
test/typescript/typings
perf/
.nyc_output/

cli/help.ts
4 changes: 2 additions & 2 deletions cli/cli.ts
@@ -1,8 +1,8 @@
import process from 'process';
import help from 'help.md';
import argParser from 'yargs-parser';
import { version } from '../package.json';
import { commandAliases } from '../src/utils/options/mergeOptions';
import help from './help';
import run from './run/index';

const command = argParser(process.argv.slice(2), {
Expand All @@ -11,7 +11,7 @@ const command = argParser(process.argv.slice(2), {
});

if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
console.log(`\n${help.replace('__VERSION__', version)}\n`);
console.log(`\n${help}\n`);
} else if (command.version) {
console.log(`rollup v${version}`);
} else {
Expand Down
35 changes: 0 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -58,7 +58,6 @@
"fsevents": "~2.3.2"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -103,7 +102,6 @@
"requirejs": "^2.3.6",
"rollup": "^2.67.0",
"rollup-plugin-license": "^2.6.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-thatworks": "^1.0.4",
"shx": "^0.3.4",
Expand Down
13 changes: 0 additions & 13 deletions rollup.config.ts
@@ -1,13 +1,10 @@
import { promises as fs } from 'fs';
import { resolve } from 'path';
import { env } from 'process';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import type { RollupOptions, WarningHandlerWithDefault } from 'rollup';
import { string } from 'rollup-plugin-string';
import { terser } from 'rollup-plugin-terser';
import addCliEntry from './build-plugins/add-cli-entry';
import conditionalFsEventsImport from './build-plugins/conditional-fsevents-import';
Expand Down Expand Up @@ -50,25 +47,16 @@ const onwarn: WarningHandlerWithDefault = warning => {
throw new Error(warning.message);
};

const moduleAliases = {
entries: {
'help.md': resolve('cli/help.md')
},
resolve: ['.js', '.json', '.md']
};

const treeshake = {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false
};

const nodePlugins = [
alias(moduleAliases),
nodeResolve(),
json(),
conditionalFsEventsImport(),
string({ include: '**/*.md' }),
commonjs({
ignoreTryCatch: false,
include: 'node_modules/**'
Expand Down Expand Up @@ -141,7 +129,6 @@ export default async function (
],
plugins: [
replaceBrowserModules(),
alias(moduleAliases),
nodeResolve({ browser: true }),
json(),
commonjs(),
Expand Down
18 changes: 18 additions & 0 deletions scripts/generate-help-module.js
@@ -0,0 +1,18 @@
'use strict';

const { promises: fs } = require('fs');
const { resolve } = require('path');

async function generateHelpModule() {
const mdFilename = resolve(__dirname, '../cli/help.md');
const mdContent = await fs.readFile(mdFilename, 'utf8');

const tsFilename = resolve(__dirname, '../cli/help.ts');
const tsContent = `import { version } from '../package.json';
export default \`${mdContent.replace('__VERSION__', '${version}').replace(/`/g, '\\`')}\`;
`;
await fs.writeFile(tsFilename, tsContent);
}

generateHelpModule();

0 comments on commit 1e6f5a9

Please sign in to comment.