mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 08:32:52 +08:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import * as fs from 'fs-extra';
|
|
import * as path from 'path';
|
|
|
|
import { PLUGIN_PATHS } from '../build/helpers';
|
|
import { EMIT_PATH } from '../build/transformers/extract-injectables';
|
|
import { generateDeclarations, transpile } from '../build/transpile';
|
|
|
|
generateDeclarations();
|
|
transpile();
|
|
|
|
const outDirs = PLUGIN_PATHS.map(p =>
|
|
p.replace('src', 'dist').replace(/[\\/]index.ts/, '')
|
|
);
|
|
const injectableClasses = fs.readJSONSync(EMIT_PATH);
|
|
|
|
outDirs.forEach(dir => {
|
|
const classes = injectableClasses.filter(
|
|
entry => entry.dirName === dir.split(/[\\/]+/).pop()
|
|
);
|
|
|
|
let jsFile: string = fs.readFileSync(path.join(dir, 'index.js'), 'utf-8'),
|
|
dtsFile: string = fs.readFileSync(path.join(dir, 'index.d.ts'), 'utf-8');
|
|
|
|
classes.forEach(entry => {
|
|
dtsFile = dtsFile.replace(
|
|
`class ${entry.className} `,
|
|
'class ' + entry.className + 'Original '
|
|
);
|
|
dtsFile += `\nexport declare const ${entry.className}: ${
|
|
entry.className
|
|
}Original;`;
|
|
jsFile = jsFile.replace(
|
|
new RegExp(`([\\s\\(])${entry.className}([\\s\\.;\\(,])`, 'g'),
|
|
'$1' + entry.className + 'Original$2'
|
|
);
|
|
jsFile = jsFile.replace(
|
|
`export { ${entry.className}Original }`,
|
|
`var ${entry.className} = new ${entry.className}Original();\nexport { ${
|
|
entry.className
|
|
} }`
|
|
);
|
|
});
|
|
|
|
fs.writeFileSync(path.join(dir, 'index.js'), jsFile, 'utf-8');
|
|
fs.writeFileSync(path.join(dir, 'index.d.ts'), dtsFile, 'utf-8');
|
|
});
|