forked from raaihank/simple-tags-input
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.mjs
More file actions
26 lines (22 loc) · 1.05 KB
/
package.mjs
File metadata and controls
26 lines (22 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Helper file for the npm run build
// For the classic usage, removes 'export' and attaches wrapper for windows/module/commonjs
// NOTE: expects output to have a __export default class__ which it converted to 'class' and
// then the window/module attachments
import { readFileSync, writeFileSync } from 'fs';
import { argv } from 'process';
// class name we're working
const Class = 'Input2Tags'
const input = argv[2];
const output = argv[3] || input;
let code = readFileSync(input, 'utf8');
// replace & append
if( code.indexOf('export default class') > -1 )
code = code.replace(`export default class`, `class ${Class}`);
else if( code.indexOf('export ') > -1 )
code = code.replace(`export `, '');
else{
console.log( `ERROR: Unable to find export'ed class.` )
process.exit(-1)
}
const appendCode = `if(typeof window!=='undefined')window.${Class}=${Class};else if(typeof module!=='undefined'&&module.exports)module.exports=${Class}; else if(typeof define==='function'&&define.amd)define(()=>${Class});`
writeFileSync(output, code + appendCode, 'utf8');