Skip to content

Commit

Permalink
feat(plugins): add support for plugins shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuuGan committed Jun 20, 2020
1 parent 8027378 commit 68e0301
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions bin/pluginsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Debug from 'debug';
import path from 'path';
import { ExportPluginCtor, ExportPluginModule } from '../lib/types';
import { Utils } from '../lib/utils';
import { plugins } from '../lib';

const info = Debug('sol-merger:info');
const error = Debug('sol-merger:error');
Expand All @@ -24,6 +25,11 @@ export class PluginsLoader {
async getPlugins(): Promise<ExportPluginCtor[]> {
const result: ExportPluginCtor[] = [];
for (const pluginPath of this.#pluginPaths) {
const defaultPlugin = plugins[pluginPath];
if (defaultPlugin) {
result.push(defaultPlugin);
continue;
}
const fullPluginPath = this.getPluginPath(pluginPath);
if (!fullPluginPath) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const merge = async (file: string, options: SolMergerOptions = {}) => {
};

export * from './antlr/visitors/types';
export { plugins } from './plugins';

export {
Merger,
FileAnalyzer,
Expand Down
1 change: 0 additions & 1 deletion lib/plugins.ts

This file was deleted.

6 changes: 6 additions & 0 deletions lib/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ExportPluginCtor } from '../types';
import { ExportPlugin as SPDXLicenseRemovePlugin } from './SPDXLicenseRemovePlugin';

export const plugins: Record<string, ExportPluginCtor | undefined> = {
SPDXLicenseRemovePlugin,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"test": "mocha",
"build": "tsc --newLine lf -p tsconfig.app.json",
"build": "rm -r dist || true && tsc --newLine lf -p tsconfig.app.json",
"lint": "tslint -p tsconfig.app.json",
"antlr4ts": "antlr4ts -visitor Solidity.g4",
"changelog": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -r 0"
Expand Down
5 changes: 5 additions & 0 deletions test-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ sol-merger --export-plugin ./dist/lib/plugins/SPDXLicenseRemovePlugin.js "test/c

compareFile compiled/LocalImportsWithSPDX.sol

rm -rf compiled
sol-merger --export-plugin SPDXLicenseRemovePlugin "test/contracts/*.sol" compiled

compareFile compiled/LocalImportsWithSPDX.sol

# Remove Comments
echo "Compilation with --remove-comments option"
rm -rf compiled
Expand Down
8 changes: 6 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from 'chai';
import path from 'path';
import { merge, Merger } from '../lib/index';
import { SPDXLicenseRemovePlugin } from '../lib/plugins';
import { plugins } from '../lib/plugins';
import { assertWithFile, testFile } from './utils';

describe('Solidity Merger', () => {
Expand Down Expand Up @@ -93,8 +93,12 @@ describe('Solidity Merger', () => {
});

it('should compile use plugins correctly', async () => {
if (!plugins.SPDXLicenseRemovePlugin) {
assert.fail('SPDXLicenseRemovePlugin is not defined');
return;
}
await testFile('LocalImportsWithSPDX', {
exportPlugins: [SPDXLicenseRemovePlugin],
exportPlugins: [plugins.SPDXLicenseRemovePlugin],
});
});

Expand Down

0 comments on commit 68e0301

Please sign in to comment.