You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
632 B
17 lines
632 B
4 years ago
|
|
||
4 years ago
|
const INSERT_IMPORT_PLUGINS_COMMENT = '// import plugins here';
|
||
|
const INSERT_USE_PLUGINS_COMMENT = '// use plugins here';
|
||
4 years ago
|
|
||
4 years ago
|
const addPlugins = (originalCode: string = '', plugins: string[] = []): string => {
|
||
|
const modifiedContent: string = originalCode
|
||
4 years ago
|
.replace(new RegExp(INSERT_IMPORT_PLUGINS_COMMENT), () => {
|
||
4 years ago
|
return plugins.map((plugin, index) => `import plugin${index} from '${plugin}';`).join('\n');
|
||
4 years ago
|
})
|
||
|
.replace(new RegExp(INSERT_USE_PLUGINS_COMMENT), () => {
|
||
4 years ago
|
return plugins.map((_, index) => `logic.use(plugin${index});`).join('\n');
|
||
4 years ago
|
});
|
||
4 years ago
|
return modifiedContent;
|
||
4 years ago
|
};
|
||
|
|
||
4 years ago
|
export default addPlugins;
|