refactor(build): use path es6 imports

This commit is contained in:
Daniel Sogl
2021-09-27 20:32:20 +02:00
parent 770052347e
commit f3160e4cc6
6 changed files with 39 additions and 42 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
import { readJSONSync, writeFileSync } from 'fs-extra';
import * as path from 'path';
import { resolve } from 'path';
import * as uglifyJsPlugin from 'uglifyjs-webpack-plugin';
import * as unminifiedPlugin from 'unminified-webpack-plugin';
import * as webpack from 'webpack';
@@ -8,8 +8,8 @@ import { ROOT } from '../build/helpers';
import { cleanEmittedData, EMIT_PATH, InjectableClassEntry } from '../build/transformers/extract-injectables';
import { Logger } from '../logger';
const DIST = path.resolve(ROOT, 'dist');
const INDEX_PATH = path.resolve(DIST, 'index.js');
const DIST = resolve(ROOT, 'dist');
const INDEX_PATH = resolve(DIST, 'index.js');
const INJECTABLE_CLASSES = readJSONSync(EMIT_PATH).map((item: InjectableClassEntry) => {
item.file =
'./' +
@@ -33,14 +33,14 @@ const webpackConfig: webpack.Configuration = {
modules: ['node_modules'],
extensions: ['.js'],
alias: {
'@awesome-cordova-plugins/core': path.resolve(DIST, '@awesome-cordova-plugins/core/index.js'),
'@awesome-cordova-plugins/core': resolve(DIST, '@awesome-cordova-plugins/core/index.js'),
},
},
module: {
rules: [
{
test: /\.js$/,
use: path.resolve(ROOT, 'scripts/build/remove-tslib-helpers.js'),
use: resolve(ROOT, 'scripts/build/remove-tslib-helpers.js'),
},
],
},
+6 -8
View File
@@ -1,5 +1,5 @@
import { readFileSync, readJSONSync, writeFileSync } from 'fs-extra';
import * as path from 'path';
import { join } from 'path';
import { PLUGIN_PATHS, ROOT } from '../build/helpers';
import { EMIT_PATH } from '../build/transformers/extract-injectables';
@@ -8,16 +8,14 @@ import { generateDeclarations, transpile } from '../build/transpile';
generateDeclarations();
transpile();
const outDirs = PLUGIN_PATHS.map(p =>
p.replace(path.join(ROOT, 'src'), path.join(ROOT, 'dist')).replace(/[\\/]index.ts/, '')
);
const outDirs = PLUGIN_PATHS.map(p => p.replace(join(ROOT, 'src'), join(ROOT, 'dist')).replace(/[\\/]index.ts/, ''));
const injectableClasses = readJSONSync(EMIT_PATH);
outDirs.forEach(dir => {
const classes = injectableClasses.filter(entry => entry.dirName === dir.split(/[\\/]+/).pop());
let jsFile: string = readFileSync(path.join(dir, 'index.js'), 'utf-8'),
dtsFile: string = readFileSync(path.join(dir, 'index.d.ts'), 'utf-8');
let jsFile: string = readFileSync(join(dir, 'index.js'), 'utf-8'),
dtsFile: string = readFileSync(join(dir, 'index.d.ts'), 'utf-8');
classes.forEach(entry => {
dtsFile = dtsFile.replace(`class ${entry.className} `, 'class ' + entry.className + 'Original ');
@@ -32,6 +30,6 @@ outDirs.forEach(dir => {
);
});
writeFileSync(path.join(dir, 'index.js'), jsFile, 'utf-8');
writeFileSync(path.join(dir, 'index.d.ts'), dtsFile, 'utf-8');
writeFileSync(join(dir, 'index.js'), jsFile, 'utf-8');
writeFileSync(join(dir, 'index.d.ts'), dtsFile, 'utf-8');
});
+7 -7
View File
@@ -3,7 +3,7 @@ import { exec } from 'child_process';
import { writeJSONSync } from 'fs-extra';
import { merge } from 'lodash';
import { cpus } from 'os';
import * as path from 'path';
import { join, resolve } from 'path';
import { PLUGIN_PATHS, ROOT } from '../build/helpers';
import { Logger } from '../logger';
@@ -26,7 +26,7 @@ const PACKAGE_JSON_BASE = {
},
};
const DIST = path.resolve(ROOT, 'dist/@awesome-cordova-plugins');
const DIST = resolve(ROOT, 'dist/@awesome-cordova-plugins');
const PACKAGES = [];
@@ -48,27 +48,27 @@ function getPackageJsonContent(name: string, peerDependencies = {}, dependencies
}
function writePackageJson(data: any, dir: string) {
const filePath = path.resolve(dir, 'package.json');
const filePath = resolve(dir, 'package.json');
writeJSONSync(filePath, data);
PACKAGES.push(dir);
}
function writeNGXPackageJson(data: any, dir: string) {
const filePath = path.resolve(dir, 'package.json');
const filePath = resolve(dir, 'package.json');
writeJSONSync(filePath, data);
}
function prepare() {
// write @awesome-cordova-plugins/core package.json
writePackageJson(
getPackageJsonContent('core', { rxjs: RXJS_VERSION }, { '@types/cordova': 'latest' }),
path.resolve(DIST, 'core')
resolve(DIST, 'core')
);
// write plugin package.json files
PLUGIN_PATHS.forEach((pluginPath: string) => {
const pluginName = pluginPath.split(/[\/\\]+/).slice(-2)[0];
const packageJsonContents = getPackageJsonContent(pluginName, PLUGIN_PEER_DEPENDENCIES);
const dir = path.resolve(DIST, 'plugins', pluginName);
const ngxDir = path.join(dir, 'ngx');
const dir = resolve(DIST, 'plugins', pluginName);
const ngxDir = join(dir, 'ngx');
writePackageJson(packageJsonContents, dir);
writeNGXPackageJson(packageJsonContents, ngxDir);
});