mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-20 00:06:24 +08:00
core(): remove unused files
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
import { outputJson, readdir, readJson } from 'fs-extra';
|
||||
import { basename, dirname, resolve } from 'path';
|
||||
import { Application } from 'typedoc';
|
||||
import TypeDoc = require('typedoc');
|
||||
import { runInNewContext } from 'vm';
|
||||
|
||||
interface Plugin {
|
||||
packageName: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
platforms: string[];
|
||||
usage: string;
|
||||
repo: string;
|
||||
installVariables: string[];
|
||||
cordovaPlugin: {
|
||||
name: string;
|
||||
};
|
||||
premierSlug: string;
|
||||
capacitorIncompatible: boolean;
|
||||
}
|
||||
|
||||
const rootDir = resolve(__dirname, '../..');
|
||||
const typedocDocsTmp = resolve(__dirname, 'typedoc-docs');
|
||||
const typedocTmp = resolve(__dirname, 'typedoc.tmp.json');
|
||||
const pluginsDir = resolve(rootDir, 'src/@awesome-cordova-plugins/plugins');
|
||||
const typedoc = new Application();
|
||||
|
||||
typedoc.options.addReader(new TypeDoc.TSConfigReader());
|
||||
typedoc.options.addReader(new TypeDoc.TypeDocReader());
|
||||
|
||||
run(pluginsDir);
|
||||
|
||||
async function run(pluginsDir: string) {
|
||||
try {
|
||||
const typedocData = await generateTypedoc(pluginsDir);
|
||||
const modules = typedocData.children.filter(isModule);
|
||||
const plugins = modules.filter(hasPlugin).map(processPlugin);
|
||||
await outputJson(resolve(__dirname, 'plugins.json'), plugins, {
|
||||
spaces: 2,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Unable to generate typedoc', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function generateTypedoc(root: string, outputPath = typedocTmp, outputDocsPath = typedocDocsTmp) {
|
||||
const pluginDirs = await readdir(root);
|
||||
const paths = pluginDirs.map((dir) => resolve(root, dir, 'index.ts'));
|
||||
typedoc.bootstrap({
|
||||
/*
|
||||
mode: 'modules',
|
||||
ignoreCompilerErrors: true,
|
||||
*/
|
||||
entryPoints: paths,
|
||||
tsconfig: `tsconfig.json`,
|
||||
});
|
||||
const project = typedoc.converter.convert(typedoc.getEntryPoints() ?? []);
|
||||
|
||||
await typedoc.generateDocs(project, outputDocsPath);
|
||||
await typedoc.generateJson(project, outputPath);
|
||||
|
||||
return readJson(outputPath);
|
||||
}
|
||||
|
||||
function processPlugin(pluginModule): Plugin {
|
||||
const pluginClass = pluginModule.children.find(isPlugin);
|
||||
console.log(pluginClass);
|
||||
const decorator = getPluginDecorator(pluginClass);
|
||||
const packageName = `@awesome-cordova-plugins/${basename(dirname(pluginModule.originalName))}`;
|
||||
const displayName = getTag(pluginClass, 'name');
|
||||
const usage = getTag(pluginClass, 'usage');
|
||||
const description = getTag(pluginClass, 'description');
|
||||
const premierSlug = getTag(pluginClass, 'premier');
|
||||
const capIncompat = getTag(pluginClass, 'capacitorincompatible');
|
||||
const capacitorIncompatible = capIncompat ? true : undefined;
|
||||
return {
|
||||
packageName,
|
||||
displayName,
|
||||
description,
|
||||
usage,
|
||||
platforms: decorator.platforms,
|
||||
repo: decorator.repo,
|
||||
installVariables: decorator.installVariables,
|
||||
cordovaPlugin: {
|
||||
name: decorator.plugin,
|
||||
},
|
||||
premierSlug,
|
||||
capacitorIncompatible,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Typedoc only gives us the Plugin decorator internals
|
||||
* as a string. So, rather than try to parse that with a RegExp,
|
||||
* we evaluate it using Node's vm module.
|
||||
*/
|
||||
const getPluginDecorator = (child: any) => {
|
||||
if (isPlugin(child)) {
|
||||
const decorator = child.decorators.find((d) => d.name === 'Plugin');
|
||||
|
||||
console.log('Found decorator', decorator.arguments, child);
|
||||
return runInNewContext(`(${decorator.arguments.config})`);
|
||||
}
|
||||
};
|
||||
|
||||
const getTag = (child: any, tagName: string): string => {
|
||||
if (hasTags(child)) {
|
||||
const tag = child.comment.tags.find((t) => t.tag === tagName);
|
||||
if (tag) {
|
||||
return tag.text;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isModule = (child: any): boolean => child.kind === 1;
|
||||
|
||||
const isClass = (child: any): boolean => child.kind === 128;
|
||||
|
||||
const isPlugin = (child: any): boolean =>
|
||||
isClass(child) &&
|
||||
hasTags(child) &&
|
||||
Array.isArray(child.decorators) &&
|
||||
child.decorators.some((d) => d.name === 'Plugin');
|
||||
|
||||
const hasPlugin = (child: any): boolean => child.children.some(isPlugin);
|
||||
|
||||
const hasTags = (child: any): boolean => child.comment && Array.isArray(child.comment.tags);
|
||||
@@ -1,3 +0,0 @@
|
||||
# docs-json
|
||||
|
||||
This script reads and generates [typedoc](https://github.com/TypeStrong/typedoc) data for each of the plugins in `src/@awesome-cordova-plugins/plugins`. That data is then formatted and output as `plugins.json` in this directory.
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
ARG_DEFS=(
|
||||
"--repository=(.*)"
|
||||
"--directory=(.*)"
|
||||
"[--depth=(.*)]"
|
||||
"[--branch=(.*)]"
|
||||
)
|
||||
|
||||
function run {
|
||||
rm -rf $DIRECTORY
|
||||
mkdir -p $DIRECTORY
|
||||
|
||||
echo "-- Cloning $REPOSITORY#$BRANCH to $DIRECTORY..."
|
||||
|
||||
ARGS="--branch=${BRANCH:-master} --depth=3"
|
||||
if [[ "$DEPTH" != "" ]]; then
|
||||
ARGS="$ARGS --depth=$DEPTH"
|
||||
fi
|
||||
|
||||
git config --global user.email "hi@ionicframework.com"
|
||||
git config --global user.name "Ionitron"
|
||||
|
||||
git clone git@github.com:ionic-team/$REPOSITORY.git $DIRECTORY $ARGS
|
||||
cd $DIRECTORY
|
||||
git fetch origin --tags
|
||||
cd ../
|
||||
}
|
||||
|
||||
source $(dirname $0)/../utils.inc.sh
|
||||
@@ -1,2 +0,0 @@
|
||||
git config --global user.email "hi@ionicframework.com"
|
||||
git config --global user.name "Ionitron"
|
||||
Reference in New Issue
Block a user