mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +08:00
4f8f99fa44
BREAKING CHANGE: Minimum Angular version requirement updated to 19.2.14 - Angular Core: 19.0.5 → 19.2.14 (latest Angular 19 LTS) - Zone.js: 0.15.0 → 0.15.1 (latest compatibility) - TypeScript: 5.6.3 (latest supported by Angular 19) Testing Infrastructure Modernization: - Jest: 27.5.1 → 29.7.0 (major upgrade for better performance) - ts-jest: 27.1.5 → 29.3.4 (TypeScript 5.6+ compatibility) - @types/jest: 27.5.2 → 29.5.14 (latest type definitions) - jest-environment-jsdom: Added 29.7.0 (required for Jest 29) - RxJS: 7.8.1 → 7.8.2 (latest patch version) Package Generator Improvements: - Fixed package.json generator to use correct author from main package.json - Updated RxJS peer dependency to ^7.8.0 (modern version range) - Updated core version dependency to use current package version dynamically - Ensured consistency across all generated plugin package.json files This update brings the project to the latest Angular 19 LTS with enhanced testing capabilities, improved build performance, and modernized dependency management. All builds and tests passing successfully.
153 lines
4.3 KiB
TypeScript
153 lines
4.3 KiB
TypeScript
import { readdirSync } from 'fs-extra';
|
|
import { camelCase, clone } from 'lodash';
|
|
import { join, resolve } from 'path';
|
|
import {
|
|
ArrayLiteralExpression,
|
|
Decorator,
|
|
Expression,
|
|
factory,
|
|
Node,
|
|
ObjectLiteralElementLike,
|
|
ObjectLiteralExpression,
|
|
SyntaxKind,
|
|
} from 'typescript';
|
|
|
|
import { Logger } from '../logger';
|
|
|
|
export const ROOT = resolve(__dirname, '../../');
|
|
// tslint:disable-next-line:no-var-requires
|
|
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 function getDecorator(node: Node, index = 0): Decorator {
|
|
const decorators = (node as any).decorators;
|
|
if (decorators && decorators[index]) {
|
|
return decorators[index];
|
|
}
|
|
}
|
|
|
|
export function hasDecorator(decoratorName: string, node: Node): boolean {
|
|
const decorators = (node as any).decorators;
|
|
return (
|
|
decorators && decorators.length && decorators.findIndex((d: any) => getDecoratorName(d) === decoratorName) > -1
|
|
);
|
|
}
|
|
|
|
export function getDecoratorName(decorator: any) {
|
|
return decorator.expression.expression.text;
|
|
}
|
|
|
|
export function getRawDecoratorArgs(decorator: any): any[] {
|
|
if (decorator.expression.arguments.length === 0) return [];
|
|
return decorator.expression.arguments[0].properties;
|
|
}
|
|
|
|
export function getDecoratorArgs(decorator: any) {
|
|
const properties: any[] = getRawDecoratorArgs(decorator);
|
|
const args = {};
|
|
|
|
properties.forEach((prop) => {
|
|
let val: number | boolean;
|
|
|
|
switch (prop.initializer.kind) {
|
|
case SyntaxKind.StringLiteral:
|
|
case SyntaxKind.Identifier:
|
|
val = prop.initializer.text;
|
|
break;
|
|
|
|
case SyntaxKind.ArrayLiteralExpression:
|
|
val = prop.initializer.elements.map((e: any) => e.text);
|
|
break;
|
|
|
|
case SyntaxKind.TrueKeyword:
|
|
val = true;
|
|
break;
|
|
|
|
case SyntaxKind.FalseKeyword:
|
|
val = false;
|
|
break;
|
|
|
|
case SyntaxKind.NumericLiteral:
|
|
val = Number(prop.initializer.text);
|
|
break;
|
|
|
|
default:
|
|
Logger.debug('Unexpected property value type: ' + prop.initializer.kind);
|
|
throw new Error('Unexpected property value type << helpers.ts >>');
|
|
}
|
|
|
|
args[prop.name.text] = val;
|
|
});
|
|
|
|
return args;
|
|
}
|
|
|
|
/**
|
|
* FROM STENCIL
|
|
* Convert a js value into typescript AST
|
|
* @param val array, object, string, boolean, or number
|
|
* @returns Typescript Object Literal, Array Literal, String Literal, Boolean Literal, Numeric Literal
|
|
*/
|
|
export function convertValueToLiteral(val: any) {
|
|
if (Array.isArray(val)) {
|
|
return arrayToArrayLiteral(val);
|
|
}
|
|
if (typeof val === 'object') {
|
|
return objectToObjectLiteral(val);
|
|
}
|
|
if (typeof val === 'number') {
|
|
return factory.createNumericLiteral(val);
|
|
}
|
|
if (typeof val === 'string') {
|
|
return factory.createStringLiteral(val);
|
|
}
|
|
if (typeof val === 'boolean') {
|
|
return val ? factory.createTrue() : factory.createFalse();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* FROM STENCIL
|
|
* Convert a js object into typescript AST
|
|
* @param obj key value object
|
|
* @returns Typescript Object Literal Expression
|
|
*/
|
|
function objectToObjectLiteral(obj: { [key: string]: any }): ObjectLiteralExpression {
|
|
const newProperties: ObjectLiteralElementLike[] = Object.keys(obj).map((key: string): ObjectLiteralElementLike => {
|
|
return factory.createPropertyAssignment(
|
|
factory.createStringLiteral(key),
|
|
convertValueToLiteral(obj[key]) as Expression
|
|
);
|
|
});
|
|
|
|
return factory.createObjectLiteralExpression(newProperties);
|
|
}
|
|
|
|
/**
|
|
* FROM STENCIL
|
|
* Convert a js array into typescript AST
|
|
* @param list arrayÏ
|
|
* @returns Typescript Array Literal Expression
|
|
*/
|
|
function arrayToArrayLiteral(list: any[]): ArrayLiteralExpression {
|
|
const newList: any[] = list.map(convertValueToLiteral);
|
|
return factory.createArrayLiteralExpression(newList);
|
|
}
|
|
|
|
export function getMethodsForDecorator(decoratorName: string) {
|
|
switch (decoratorName) {
|
|
case 'CordovaProperty':
|
|
return ['cordovaPropertyGet', 'cordovaPropertySet'];
|
|
case 'InstanceProperty':
|
|
return ['instancePropertyGet', 'instancePropertySet'];
|
|
case 'CordovaCheck':
|
|
return ['checkAvailability'];
|
|
case 'InstanceCheck':
|
|
return ['instanceAvailability'];
|
|
}
|
|
|
|
return [camelCase(decoratorName)];
|
|
}
|