mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-04 00:13:06 +08:00
refactor(build): use fs-extra es6 imports
This commit is contained in:
parent
87b7de20ff
commit
770052347e
@ -1,7 +1,8 @@
|
||||
import * as ts from 'typescript';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import { readdirSync } from 'fs-extra';
|
||||
import { camelCase, clone } from 'lodash';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export const ROOT = path.resolve(__dirname, '../../');
|
||||
@ -9,7 +10,7 @@ export const ROOT = path.resolve(__dirname, '../../');
|
||||
export const TS_CONFIG = clone(require(path.resolve(ROOT, 'tsconfig.json')));
|
||||
export const COMPILER_OPTIONS = TS_CONFIG.compilerOptions;
|
||||
export const PLUGINS_ROOT = path.join(ROOT, 'src/@awesome-cordova-plugins/plugins/');
|
||||
export const PLUGIN_PATHS = fs.readdirSync(PLUGINS_ROOT).map(d => path.join(PLUGINS_ROOT, d, 'index.ts'));
|
||||
export const PLUGIN_PATHS = readdirSync(PLUGINS_ROOT).map(d => path.join(PLUGINS_ROOT, d, 'index.ts'));
|
||||
|
||||
export function getDecorator(node: ts.Node, index = 0): ts.Decorator {
|
||||
if (node.decorators && node.decorators[index]) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as ts from 'typescript';
|
||||
import * as fs from 'fs-extra';
|
||||
import { copyFileSync, mkdirpSync, readJSONSync, writeJSONSync } from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as rimraf from 'rimraf';
|
||||
import * as rollup from 'rollup';
|
||||
@ -82,11 +82,10 @@ export function generateLegacyBundles() {
|
||||
|
||||
// remove reference to @awesome-cordova-plugins/core decorators
|
||||
export function modifyMetadata() {
|
||||
debugger;
|
||||
PLUGIN_PATHS.map(p =>
|
||||
p.replace(path.join(ROOT, 'src'), path.join(ROOT, 'dist')).replace('index.ts', 'ngx/index.metadata.json')
|
||||
).forEach(p => {
|
||||
const content = fs.readJSONSync(p);
|
||||
const content = readJSONSync(p);
|
||||
let _prop: { members: { [x: string]: any[] } };
|
||||
for (const prop in content[0].metadata) {
|
||||
_prop = content[0].metadata[prop];
|
||||
@ -99,7 +98,7 @@ export function modifyMetadata() {
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeJSONSync(p, content);
|
||||
writeJSONSync(p, content);
|
||||
});
|
||||
}
|
||||
|
||||
@ -120,8 +119,8 @@ function createSourceFiles(): string[] {
|
||||
|
||||
// delete directory
|
||||
rimraf.sync(ngxPath);
|
||||
fs.mkdirpSync(ngxPath);
|
||||
fs.copyFileSync(indexPath, newPath);
|
||||
mkdirpSync(ngxPath);
|
||||
copyFileSync(indexPath, newPath);
|
||||
|
||||
return newPath;
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import { unlinkSync, writeJSONSync } from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
@ -51,9 +51,9 @@ export function extractInjectables() {
|
||||
}
|
||||
|
||||
export function emitInjectableClasses() {
|
||||
fs.writeJSONSync(EMIT_PATH, injectableClasses);
|
||||
writeJSONSync(EMIT_PATH, injectableClasses);
|
||||
}
|
||||
|
||||
export function cleanEmittedData() {
|
||||
fs.unlinkSync(EMIT_PATH);
|
||||
unlinkSync(EMIT_PATH);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import { outputJson, readdir, readJson } from 'fs-extra';
|
||||
import { basename, dirname, resolve } from 'path';
|
||||
import { Application } from 'typedoc';
|
||||
import TypeDoc = require('typedoc');
|
||||
@ -35,7 +35,7 @@ async function run(pluginsDir: string) {
|
||||
const typedocData = await generateTypedoc(pluginsDir);
|
||||
const modules = typedocData.children.filter(isModule);
|
||||
const plugins = modules.filter(hasPlugin).map(processPlugin);
|
||||
await fs.outputJson(resolve(__dirname, 'plugins.json'), plugins, {
|
||||
await outputJson(resolve(__dirname, 'plugins.json'), plugins, {
|
||||
spaces: 2,
|
||||
});
|
||||
} catch (e) {
|
||||
@ -44,7 +44,7 @@ async function run(pluginsDir: string) {
|
||||
}
|
||||
|
||||
async function generateTypedoc(root: string, outputPath = typedocTmp, outputDocsPath = typedocDocsTmp) {
|
||||
const pluginDirs = await fs.readdir(root);
|
||||
const pluginDirs = await readdir(root);
|
||||
const paths = pluginDirs.map(dir => resolve(root, dir, 'index.ts'));
|
||||
typedoc.bootstrap({
|
||||
/*
|
||||
@ -59,7 +59,7 @@ async function generateTypedoc(root: string, outputPath = typedocTmp, outputDocs
|
||||
await typedoc.generateDocs(project, outputDocsPath);
|
||||
await typedoc.generateJson(project, outputPath);
|
||||
|
||||
return fs.readJson(outputPath);
|
||||
return readJson(outputPath);
|
||||
}
|
||||
|
||||
function processPlugin(pluginModule): Plugin {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import { readJSONSync, writeFileSync } from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as uglifyJsPlugin from 'uglifyjs-webpack-plugin';
|
||||
import * as unminifiedPlugin from 'unminified-webpack-plugin';
|
||||
@ -10,7 +10,7 @@ import { Logger } from '../logger';
|
||||
|
||||
const DIST = path.resolve(ROOT, 'dist');
|
||||
const INDEX_PATH = path.resolve(DIST, 'index.js');
|
||||
const INJECTABLE_CLASSES = fs.readJSONSync(EMIT_PATH).map((item: InjectableClassEntry) => {
|
||||
const INJECTABLE_CLASSES = readJSONSync(EMIT_PATH).map((item: InjectableClassEntry) => {
|
||||
item.file =
|
||||
'./' +
|
||||
item.file
|
||||
@ -71,7 +71,7 @@ function createIndexFile() {
|
||||
fileContent += `require('./@awesome-cordova-plugins/core/bootstrap').checkReady();\n`;
|
||||
fileContent += `require('./@awesome-cordova-plugins/core/ng1').initAngular1(window.IonicNative);`;
|
||||
|
||||
fs.writeFileSync(INDEX_PATH, fileContent, { encoding: 'utf-8' });
|
||||
writeFileSync(INDEX_PATH, fileContent, { encoding: 'utf-8' });
|
||||
}
|
||||
|
||||
function compile() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import { readFileSync, readJSONSync, writeFileSync } from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
import { PLUGIN_PATHS, ROOT } from '../build/helpers';
|
||||
@ -11,13 +11,13 @@ transpile();
|
||||
const outDirs = PLUGIN_PATHS.map(p =>
|
||||
p.replace(path.join(ROOT, 'src'), path.join(ROOT, 'dist')).replace(/[\\/]index.ts/, '')
|
||||
);
|
||||
const injectableClasses = fs.readJSONSync(EMIT_PATH);
|
||||
const injectableClasses = 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');
|
||||
let jsFile: string = readFileSync(path.join(dir, 'index.js'), 'utf-8'),
|
||||
dtsFile: string = readFileSync(path.join(dir, 'index.d.ts'), 'utf-8');
|
||||
|
||||
classes.forEach(entry => {
|
||||
dtsFile = dtsFile.replace(`class ${entry.className} `, 'class ' + entry.className + 'Original ');
|
||||
@ -32,6 +32,6 @@ outDirs.forEach(dir => {
|
||||
);
|
||||
});
|
||||
|
||||
fs.writeFileSync(path.join(dir, 'index.js'), jsFile, 'utf-8');
|
||||
fs.writeFileSync(path.join(dir, 'index.d.ts'), dtsFile, 'utf-8');
|
||||
writeFileSync(path.join(dir, 'index.js'), jsFile, 'utf-8');
|
||||
writeFileSync(path.join(dir, 'index.d.ts'), dtsFile, 'utf-8');
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as Queue from 'async-promise-queue';
|
||||
import { exec } from 'child_process';
|
||||
import * as fs from 'fs-extra';
|
||||
import { writeJSONSync } from 'fs-extra';
|
||||
import { merge } from 'lodash';
|
||||
import { cpus } from 'os';
|
||||
import * as path from 'path';
|
||||
@ -49,12 +49,12 @@ function getPackageJsonContent(name: string, peerDependencies = {}, dependencies
|
||||
|
||||
function writePackageJson(data: any, dir: string) {
|
||||
const filePath = path.resolve(dir, 'package.json');
|
||||
fs.writeJSONSync(filePath, data);
|
||||
writeJSONSync(filePath, data);
|
||||
PACKAGES.push(dir);
|
||||
}
|
||||
function writeNGXPackageJson(data: any, dir: string) {
|
||||
const filePath = path.resolve(dir, 'package.json');
|
||||
fs.writeJSONSync(filePath, data);
|
||||
writeJSONSync(filePath, data);
|
||||
}
|
||||
function prepare() {
|
||||
// write @awesome-cordova-plugins/core package.json
|
||||
|
Loading…
Reference in New Issue
Block a user