tiddlywiki-plugin-dev
Version:
[](https://github.com/tiddly-gittly)
130 lines (129 loc) • 4.6 kB
JavaScript
import { Command } from "commander";
const createProgram = (actions) => {
const program = new Command();
program.name("tiddlywiki-plugin-dev").description(
"Tiddlywiki plugin development tool, working with https://github.com/tiddly-gittly/Modern.TiddlyDev"
);
program.command("dev").description(
"Start a TiddlyWiki server with your plugin(s) for test. It will always watch the file changes in the plugin folder(s) and wiki folder, then refresh the browser page automatically."
).option("--wiki <wiki-path>", "Path of your wiki to publish", "./wiki").option("--src <src-path>", "Root path of developing plugins", "./src").option(
"--write-wiki",
"Write back changes from browser to the wiki. (If without this, wiki is readonly)"
).option(
"--lan",
"Listen on 0.0.0.0, so it can be open on mobile phone on same lan wifi (If without this, wiki is on `127.0.0.1`, which can only open on the local machine)"
).option(
"--exclude <exclude-filter>",
"Filter to exclude publishing plugins. e.g. [prefix[$:/plugins/aaa/]]",
void 0
).action(
async ({
wiki,
exclude,
src,
writeWiki,
lan
}) => {
await actions.runDev(wiki, src, {
writeWiki,
excludeFilter: exclude,
lan
});
}
);
program.command("test").description("Run tests using Jasmine plugin. And works simillar to dev.").option("--wiki <wiki-path>", "Path of your wiki to publish", "./wiki").option("--src <src-path>", "Root path of developing plugins", "./src").option(
"--exclude <exclude-filter>",
"Filter to exclude publishing plugins. e.g. [prefix[$:/plugins/aaa/]]",
void 0
).action(
async ({
wiki,
exclude,
src
}) => {
await actions.runTest(wiki, src, exclude);
}
);
program.command("build").description("Build plugins for Modern.TiddlyDev").option("--library", "whether to build plugin library files", false).option("--output <output>", "set output directory", "dist").option("--wiki <wiki-path>", "Path of your wiki to publish", "./wiki").option("--src <src-path>", "Root path of developing plugins", "./src").option(
"--exclude <exclude-filter>",
"Filter to exclude publishing plugins. e.g. [prefix[$:/plugins/aaa/]]",
void 0
).action(
async ({
library,
output,
src,
wiki,
exclude
}) => {
if (library) {
await actions.buildLibrary(output, exclude, src, wiki);
} else {
await actions.build(output, exclude, src);
}
process.exit(0);
}
);
program.command("new").description("Create a new plugin").option("--src <src-path>", "Root path of developing plugins", "./src").action(async ({ src }) => {
await actions.createPlugin(src);
});
program.command("init").description("Create a Modern.TiddlyDev project").argument("<project>", "Direction name of project").option("--repo <github-url>", "Magic for China mainland user", void 0).option("--npm <npm-url>", "Magic for China mainland user", void 0).action(
async (project, { repo, npm }) => {
await actions.init(
project,
repo || "https://github.com/tiddly-gittly/Modern.TiddlyDev.git",
npm
);
}
);
program.command("publish").description("Publish wiki").argument("[dist]", "Destination folder to publish", "dist").option(
"-e, --exclude <exclude-filter>",
"Filter to exclude publishing tiddlers",
"-[is[draft]]"
).option(
"--exclude-plugin <exclude-plugin-filter>",
"Filter to exclude publishing plugins. e.g. [prefix[$:/plugins/aaa/]]",
void 0
).option("--offline", "Generate single wiki file", false).option("--src <src-path>", "Root path of developing plugins", "./src").option(
"--html <html-file>",
"File name of generated index html file",
"index.html"
).option("--no-library", "Do not generate plugin library", true).option("--wiki <wiki-path>", "Path of your wiki to publish", "./wiki").action(
async (dist, {
offline,
exclude,
excludePlugin,
library,
html,
wiki,
src
}) => {
if (offline) {
await actions.publishOfflineHTML(
wiki,
dist,
html,
exclude,
library,
src,
excludePlugin
);
} else {
await actions.publishOnlineHTML(
wiki,
dist,
html,
exclude,
library,
src,
excludePlugin
);
}
process.exit(0);
}
);
return program;
};
export {
createProgram
};