refactor(): run prettier

This commit is contained in:
Daniel Sogl
2021-09-27 22:09:05 +02:00
parent 3896aca5aa
commit 99a0e0282d
31 changed files with 126 additions and 134 deletions
+3 -3
View File
@@ -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) {
+6 -6
View File
@@ -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 -1
View File
@@ -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;
}
+6 -6
View File
@@ -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);
};
};
+1 -1
View File
@@ -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;
}
+4 -4
View File
@@ -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);
}