mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-20 00:06:24 +08:00
refactor(): run prettier
This commit is contained in:
@@ -19,7 +19,7 @@ export const ROOT = resolve(__dirname, '../../');
|
||||
export const TS_CONFIG = clone(require(resolve(ROOT, 'tsconfig.json')));
|
||||
export const COMPILER_OPTIONS = TS_CONFIG.compilerOptions;
|
||||
export const PLUGINS_ROOT = join(ROOT, 'src/@awesome-cordova-plugins/plugins/');
|
||||
export const PLUGIN_PATHS = readdirSync(PLUGINS_ROOT).map(d => join(PLUGINS_ROOT, d, 'index.ts'));
|
||||
export const PLUGIN_PATHS = readdirSync(PLUGINS_ROOT).map((d) => join(PLUGINS_ROOT, d, 'index.ts'));
|
||||
|
||||
export function getDecorator(node: Node, index = 0): Decorator {
|
||||
if (node.decorators && node.decorators[index]) {
|
||||
@@ -31,7 +31,7 @@ export function hasDecorator(decoratorName: string, node: Node): boolean {
|
||||
return (
|
||||
node.decorators &&
|
||||
node.decorators.length &&
|
||||
node.decorators.findIndex(d => getDecoratorName(d) === decoratorName) > -1
|
||||
node.decorators.findIndex((d) => getDecoratorName(d) === decoratorName) > -1
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function getDecoratorArgs(decorator: any) {
|
||||
const properties: any[] = getRawDecoratorArgs(decorator);
|
||||
const args = {};
|
||||
|
||||
properties.forEach(prop => {
|
||||
properties.forEach((prop) => {
|
||||
let val: number | boolean;
|
||||
|
||||
switch (prop.initializer.kind) {
|
||||
|
||||
@@ -53,14 +53,14 @@ export function transpileNgx() {
|
||||
}
|
||||
|
||||
export function generateDeclarationFiles() {
|
||||
generateDeclarations(PLUGIN_PATHS.map(p => p.replace('index.ts', 'ngx/index.ts')));
|
||||
generateDeclarations(PLUGIN_PATHS.map((p) => p.replace('index.ts', 'ngx/index.ts')));
|
||||
}
|
||||
|
||||
export function generateLegacyBundles() {
|
||||
[
|
||||
resolve(ROOT, 'dist/@awesome-cordova-plugins/core/index.js'),
|
||||
...PLUGIN_PATHS.map(p => p.replace(join(ROOT, 'src'), join(ROOT, 'dist')).replace('index.ts', 'ngx/index.js')),
|
||||
].forEach(p =>
|
||||
...PLUGIN_PATHS.map((p) => p.replace(join(ROOT, 'src'), join(ROOT, 'dist')).replace('index.ts', 'ngx/index.js')),
|
||||
].forEach((p) =>
|
||||
rollup({
|
||||
input: p,
|
||||
onwarn(warning, warn) {
|
||||
@@ -68,7 +68,7 @@ export function generateLegacyBundles() {
|
||||
warn(warning);
|
||||
},
|
||||
external: ['@angular/core', '@awesome-cordova-plugins/core', 'rxjs', 'tslib'],
|
||||
}).then(bundle =>
|
||||
}).then((bundle) =>
|
||||
bundle.write({
|
||||
file: join(dirname(p), 'bundle.js'),
|
||||
format: 'cjs',
|
||||
@@ -79,9 +79,9 @@ export function generateLegacyBundles() {
|
||||
|
||||
// remove reference to @awesome-cordova-plugins/core decorators
|
||||
export function modifyMetadata() {
|
||||
PLUGIN_PATHS.map(p =>
|
||||
PLUGIN_PATHS.map((p) =>
|
||||
p.replace(join(ROOT, 'src'), join(ROOT, 'dist')).replace('index.ts', 'ngx/index.metadata.json')
|
||||
).forEach(p => {
|
||||
).forEach((p) => {
|
||||
const content = readJSONSync(p);
|
||||
let _prop: { members: { [x: string]: any[] } };
|
||||
for (const prop in content[0].metadata) {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// removes the __extends method that is added automatically by typescript
|
||||
module.exports = source => source.replace(/var\s__extends\s=\s\(this\s&&[\sa-z\._\(\)\|{}=:\[\]&,;?]+}\)\(\);/i, '');
|
||||
module.exports = (source) => source.replace(/var\s__extends\s=\s\(this\s&&[\sa-z\._\(\)\|{}=:\[\]&,;?]+}\)\(\);/i, '');
|
||||
|
||||
@@ -23,11 +23,11 @@ export const EMIT_PATH = resolve(ROOT, 'injectable-classes.json');
|
||||
*/
|
||||
export function extractInjectables() {
|
||||
return (ctx: TransformationContext) => {
|
||||
return tsSourceFile => {
|
||||
return (tsSourceFile) => {
|
||||
if (tsSourceFile.fileName.indexOf('src/@awesome-cordova-plugins/plugins') > -1) {
|
||||
visitEachChild(
|
||||
tsSourceFile,
|
||||
node => {
|
||||
(node) => {
|
||||
if (node.kind !== SyntaxKind.ClassDeclaration) {
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -39,22 +39,22 @@ function transformImports(file: SourceFile, ctx: TransformationContext, ngcBuild
|
||||
if (decorators.length) {
|
||||
let methods = [];
|
||||
|
||||
decorators.forEach(d => (methods = getMethodsForDecorator(d).concat(methods)));
|
||||
decorators.forEach((d) => (methods = getMethodsForDecorator(d).concat(methods)));
|
||||
|
||||
const methodElements = methods.map(m => factory.createIdentifier(m));
|
||||
const methodNames = methodElements.map(el => el.escapedText);
|
||||
const methodElements = methods.map((m) => factory.createIdentifier(m));
|
||||
const methodNames = methodElements.map((el) => el.escapedText);
|
||||
|
||||
importStatement.importClause.namedBindings.elements = [
|
||||
factory.createIdentifier('AwesomeCordovaNativePlugin'),
|
||||
...methodElements,
|
||||
...importStatement.importClause.namedBindings.elements.filter(
|
||||
el => keep.indexOf(el.name.text) !== -1 && methodNames.indexOf(el.name.text) === -1
|
||||
(el) => keep.indexOf(el.name.text) !== -1 && methodNames.indexOf(el.name.text) === -1
|
||||
),
|
||||
];
|
||||
|
||||
if (ngcBuild) {
|
||||
importStatement.importClause.namedBindings.elements = importStatement.importClause.namedBindings.elements.map(
|
||||
binding => {
|
||||
(binding) => {
|
||||
if (binding.escapedText) {
|
||||
binding.name = {
|
||||
text: binding.escapedText,
|
||||
@@ -71,7 +71,7 @@ function transformImports(file: SourceFile, ctx: TransformationContext, ngcBuild
|
||||
|
||||
export function importsTransformer(ngcBuild?: boolean) {
|
||||
return (ctx: TransformationContext) => {
|
||||
return tsSourceFile => {
|
||||
return (tsSourceFile) => {
|
||||
return transformImports(tsSourceFile, ctx, ngcBuild);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ export function transformMembers(cls: ClassDeclaration) {
|
||||
members.push(getter, setter);
|
||||
});
|
||||
|
||||
propertyIndices.reverse().forEach(i => members.splice(i, 1));
|
||||
propertyIndices.reverse().forEach((i) => members.splice(i, 1));
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ function transformClass(cls: any, ngcBuild?: boolean) {
|
||||
|
||||
cls = factory.createClassDeclaration(
|
||||
ngcBuild && cls.decorators && cls.decorators.length
|
||||
? cls.decorators.filter(d => getDecoratorName(d) === 'Injectable')
|
||||
? cls.decorators.filter((d) => getDecoratorName(d) === 'Injectable')
|
||||
: undefined, // remove Plugin and Injectable decorators
|
||||
[factory.createToken(SyntaxKind.ExportKeyword)],
|
||||
cls.name,
|
||||
@@ -55,10 +55,10 @@ function transformClasses(file: SourceFile, ctx: TransformationContext, ngcBuild
|
||||
Logger.silly('Transforming file: ' + file.fileName);
|
||||
return visitEachChild(
|
||||
file,
|
||||
node => {
|
||||
(node) => {
|
||||
if (
|
||||
node.kind !== SyntaxKind.ClassDeclaration ||
|
||||
(node.modifiers && node.modifiers.find(v => v.kind === SyntaxKind.DeclareKeyword))
|
||||
(node.modifiers && node.modifiers.find((v) => v.kind === SyntaxKind.DeclareKeyword))
|
||||
) {
|
||||
return node;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ function transformClasses(file: SourceFile, ctx: TransformationContext, ngcBuild
|
||||
|
||||
export function pluginClassTransformer(ngcBuild?: boolean): TransformerFactory<SourceFile> {
|
||||
return (ctx: TransformationContext) => {
|
||||
return tsSourceFile => {
|
||||
return (tsSourceFile) => {
|
||||
if (tsSourceFile.fileName.indexOf('src/@awesome-cordova-plugins/plugins') > -1) {
|
||||
return transformClasses(tsSourceFile, ctx, ngcBuild);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ async function run(pluginsDir: string) {
|
||||
|
||||
async function generateTypedoc(root: string, outputPath = typedocTmp, outputDocsPath = typedocDocsTmp) {
|
||||
const pluginDirs = await readdir(root);
|
||||
const paths = pluginDirs.map(dir => resolve(root, dir, 'index.ts'));
|
||||
const paths = pluginDirs.map((dir) => resolve(root, dir, 'index.ts'));
|
||||
typedoc.bootstrap({
|
||||
/*
|
||||
mode: 'modules',
|
||||
@@ -96,7 +96,7 @@ function processPlugin(pluginModule): Plugin {
|
||||
*/
|
||||
const getPluginDecorator = (child: any) => {
|
||||
if (isPlugin(child)) {
|
||||
const decorator = child.decorators.find(d => d.name === 'Plugin');
|
||||
const decorator = child.decorators.find((d) => d.name === 'Plugin');
|
||||
|
||||
console.log('Found decorator', decorator.arguments, child);
|
||||
return runInNewContext(`(${decorator.arguments.config})`);
|
||||
@@ -105,7 +105,7 @@ const getPluginDecorator = (child: any) => {
|
||||
|
||||
const getTag = (child: any, tagName: string): string => {
|
||||
if (hasTags(child)) {
|
||||
const tag = child.comment.tags.find(t => t.tag === tagName);
|
||||
const tag = child.comment.tags.find((t) => t.tag === tagName);
|
||||
if (tag) {
|
||||
return tag.text;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ const isPlugin = (child: any): boolean =>
|
||||
isClass(child) &&
|
||||
hasTags(child) &&
|
||||
Array.isArray(child.decorators) &&
|
||||
child.decorators.some(d => d.name === 'Plugin');
|
||||
child.decorators.some((d) => d.name === 'Plugin');
|
||||
|
||||
const hasPlugin = (child: any): boolean => child.children.some(isPlugin);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ const Package = require('dgeni').Package,
|
||||
path = require('path'),
|
||||
config = require('../config.json');
|
||||
|
||||
module.exports = currentVersion => {
|
||||
module.exports = (currentVersion) => {
|
||||
return (
|
||||
new Package('ionic-native-docs', [jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage])
|
||||
|
||||
@@ -40,7 +40,7 @@ module.exports = currentVersion => {
|
||||
computePathsProcessor.pathTemplates = [
|
||||
{
|
||||
docTypes: ['class'],
|
||||
getOutputPath: doc => 'content/' + config.v2DocsDir + '/' + doc.name + '/index.md',
|
||||
getOutputPath: (doc) => 'content/' + config.v2DocsDir + '/' + doc.name + '/index.md',
|
||||
},
|
||||
];
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ const Package = require('dgeni').Package,
|
||||
path = require('path'),
|
||||
config = require('../config.json');
|
||||
|
||||
module.exports = currentVersion => {
|
||||
module.exports = (currentVersion) => {
|
||||
return (
|
||||
new Package('ionic-native-readmes', [jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage])
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = currentVersion => {
|
||||
computePathsProcessor.pathTemplates = [
|
||||
{
|
||||
docTypes: ['class'],
|
||||
getOutputPath: doc =>
|
||||
getOutputPath: (doc) =>
|
||||
doc.originalModule.replace(config.pluginDir + '/', '').replace(/\/index$/, '/README.md'),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
name: 'capital',
|
||||
process: str => (str ? str.charAt(0).toUpperCase() + str.substring(1) : ''),
|
||||
process: (str) => (str ? str.charAt(0).toUpperCase() + str.substring(1) : ''),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
name: 'dashify',
|
||||
process: str => (str ? str.replace(/\s/g, '-') : ''),
|
||||
process: (str) => (str ? str.replace(/\s/g, '-') : ''),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
name: 'dump',
|
||||
process: obj => console.log(obj),
|
||||
process: (obj) => console.log(obj),
|
||||
};
|
||||
|
||||
@@ -4,6 +4,6 @@ module.exports = function removePrivateApi() {
|
||||
name: 'remove-private-api',
|
||||
description: 'Prevent the private apis from being rendered',
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => docs.filter(doc => !doc.private && (!doc.tags || !doc.tags.tagsByName.get('hidden'))),
|
||||
$process: (docs) => docs.filter((doc) => !doc.private && (!doc.tags || !doc.tags.tagsByName.get('hidden'))),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -5,9 +5,9 @@ module.exports = function jekyll(renderDocsProcessor) {
|
||||
description: 'Create jekyll includes',
|
||||
$runAfter: ['paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => {
|
||||
$process: (docs) => {
|
||||
// pretty up and sort the docs object for menu generation
|
||||
docs = docs.filter(doc => (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page');
|
||||
docs = docs.filter((doc) => (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page');
|
||||
|
||||
docs.push({
|
||||
docType: 'class',
|
||||
@@ -22,7 +22,7 @@ module.exports = function jekyll(renderDocsProcessor) {
|
||||
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
||||
});
|
||||
|
||||
docs.forEach(doc => {
|
||||
docs.forEach((doc) => {
|
||||
if (!doc.outputPath) {
|
||||
return;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ module.exports = function jekyll(renderDocsProcessor) {
|
||||
|
||||
const betaDocs = [];
|
||||
|
||||
docs = docs.filter(doc => {
|
||||
docs = docs.filter((doc) => {
|
||||
if (doc.beta === true) {
|
||||
betaDocs.push(doc);
|
||||
return false;
|
||||
|
||||
@@ -3,8 +3,8 @@ module.exports = function markProperties() {
|
||||
return {
|
||||
name: 'mark-properties',
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs =>
|
||||
docs.map(doc => {
|
||||
$process: (docs) =>
|
||||
docs.map((doc) => {
|
||||
for (let i in doc.members) {
|
||||
if (doc.members.hasOwnProperty(i) && typeof doc.members[i].parameters === 'undefined') {
|
||||
doc.members[i].isProperty = true;
|
||||
|
||||
@@ -4,13 +4,13 @@ module.exports = function npmId(renderDocsProcessor) {
|
||||
name: 'npm-id',
|
||||
$runAfter: ['paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => {
|
||||
$process: (docs) => {
|
||||
// pretty up and sort the docs object for menu generation
|
||||
docs = docs.filter(function (doc) {
|
||||
return (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page';
|
||||
});
|
||||
|
||||
docs.forEach(doc => {
|
||||
docs.forEach((doc) => {
|
||||
doc.npmId = doc.id.match(/plugins\/(.*)\/index/)[1];
|
||||
});
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
module.exports = function parseOptional() {
|
||||
return {
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => {
|
||||
docs.forEach(doc => {
|
||||
$process: (docs) => {
|
||||
docs.forEach((doc) => {
|
||||
if (doc.members && doc.members.length) {
|
||||
for (let i in doc.members) {
|
||||
if (doc.members[i].params && doc.members[i].params.length) {
|
||||
|
||||
@@ -5,11 +5,11 @@ module.exports = function readmes(renderDocsProcessor) {
|
||||
description: 'Create jekyll includes',
|
||||
$runAfter: ['paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => {
|
||||
$process: (docs) => {
|
||||
// pretty up and sort the docs object for menu generation
|
||||
docs = docs.filter(doc => (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page');
|
||||
docs = docs.filter((doc) => (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page');
|
||||
|
||||
docs.forEach(doc => {
|
||||
docs.forEach((doc) => {
|
||||
doc.outputPath = doc.outputPath.replace('src/@awesome-cordova-plugins/', '');
|
||||
});
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ module.exports = function removePrivateMembers() {
|
||||
description: 'Remove member docs with @private tags',
|
||||
$runAfter: ['tags-parsed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: docs => {
|
||||
docs.forEach(doc => {
|
||||
$process: (docs) => {
|
||||
docs.forEach((doc) => {
|
||||
if (doc.members) {
|
||||
doc.members = doc.members.filter(member => !member.tags.tagsByName.get('hidden'));
|
||||
doc.members = doc.members.filter((member) => !member.tags.tagsByName.get('hidden'));
|
||||
}
|
||||
|
||||
if (doc.statics) {
|
||||
doc.statics = doc.statics.filter(staticMethod => !staticMethod.tags.tagsByName.get('hidden'));
|
||||
doc.statics = doc.statics.filter((staticMethod) => !staticMethod.tags.tagsByName.get('hidden'));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ const config = require('./config.json'),
|
||||
fs = require('fs-extra'),
|
||||
Dgeni = require('dgeni');
|
||||
|
||||
module.exports = gulp => {
|
||||
module.exports = (gulp) => {
|
||||
gulp.task('docs', () => {
|
||||
try {
|
||||
const ionicPackage = require('./dgeni/dgeni-config')(projectPackage.version),
|
||||
dgeni = new Dgeni([ionicPackage]);
|
||||
|
||||
return dgeni.generate().then(docs => console.log(docs.length + ' docs generated'));
|
||||
return dgeni.generate().then((docs) => console.log(docs.length + ' docs generated'));
|
||||
} catch (err) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ module.exports = gulp => {
|
||||
try {
|
||||
const ionicPackage = require('./dgeni/dgeni-readmes-config')(projectPackage.version),
|
||||
dgeni = new Dgeni([ionicPackage]);
|
||||
return dgeni.generate().then(docs => console.log(docs.length + ' README files generated'));
|
||||
return dgeni.generate().then((docs) => console.log(docs.length + ' README files generated'));
|
||||
} catch (err) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ function createIndexFile() {
|
||||
let fileContent = '';
|
||||
fileContent += INJECTABLE_CLASSES.map(getPluginImport).join('\n');
|
||||
fileContent += `\nwindow.IonicNative = {\n`;
|
||||
fileContent += INJECTABLE_CLASSES.map(e => e.className).join(',\n');
|
||||
fileContent += INJECTABLE_CLASSES.map((e) => e.className).join(',\n');
|
||||
fileContent += '\n};\n';
|
||||
fileContent += `require('./@awesome-cordova-plugins/core/bootstrap').checkReady();\n`;
|
||||
fileContent += `require('./@awesome-cordova-plugins/core/ng1').initAngular1(window.IonicNative);`;
|
||||
|
||||
@@ -8,16 +8,16 @@ import { generateDeclarations, transpile } from '../build/transpile';
|
||||
generateDeclarations();
|
||||
transpile();
|
||||
|
||||
const outDirs = PLUGIN_PATHS.map(p => p.replace(join(ROOT, 'src'), 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());
|
||||
outDirs.forEach((dir) => {
|
||||
const classes = injectableClasses.filter((entry) => entry.dirName === dir.split(/[\\/]+/).pop());
|
||||
|
||||
let jsFile: string = readFileSync(join(dir, 'index.js'), 'utf-8'),
|
||||
dtsFile: string = readFileSync(join(dir, 'index.d.ts'), 'utf-8');
|
||||
|
||||
classes.forEach(entry => {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user