feat(cli): add machine-readable CLI help, recommendation, and configuration flows
This commit is contained in:
+50
-38
@@ -1,23 +1,29 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import { GitzoneConfig } from './classes.gitzoneconfig.js';
|
||||
import * as plugins from "./plugins.js";
|
||||
import * as paths from "./paths.js";
|
||||
import { GitzoneConfig } from "./classes.gitzoneconfig.js";
|
||||
import { getRawCliMode } from "./helpers.climode.js";
|
||||
|
||||
const gitzoneSmartcli = new plugins.smartcli.Smartcli();
|
||||
|
||||
export let run = async () => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const rawCliMode = await getRawCliMode();
|
||||
|
||||
// get packageInfo
|
||||
const projectInfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
|
||||
|
||||
// check for updates
|
||||
const smartupdateInstance = new plugins.smartupdate.SmartUpdate();
|
||||
await smartupdateInstance.check(
|
||||
'gitzone',
|
||||
projectInfo.npm.version,
|
||||
'http://gitzone.gitlab.io/gitzone/changelog.html',
|
||||
);
|
||||
console.log('---------------------------------------------');
|
||||
if (rawCliMode.checkUpdates) {
|
||||
const smartupdateInstance = new plugins.smartupdate.SmartUpdate();
|
||||
await smartupdateInstance.check(
|
||||
"gitzone",
|
||||
projectInfo.npm.version,
|
||||
"http://gitzone.gitlab.io/gitzone/changelog.html",
|
||||
);
|
||||
}
|
||||
if (rawCliMode.output === "human") {
|
||||
console.log("---------------------------------------------");
|
||||
}
|
||||
gitzoneSmartcli.addVersion(projectInfo.npm.version);
|
||||
|
||||
// ======> Standard task <======
|
||||
@@ -26,8 +32,13 @@ export let run = async () => {
|
||||
* standard task
|
||||
*/
|
||||
gitzoneSmartcli.standardCommand().subscribe(async (argvArg) => {
|
||||
const modStandard = await import('./mod_standard/index.js');
|
||||
await modStandard.run();
|
||||
const modStandard = await import("./mod_standard/index.js");
|
||||
await modStandard.run(argvArg);
|
||||
});
|
||||
|
||||
gitzoneSmartcli.addCommand("help").subscribe(async (argvArg) => {
|
||||
const modStandard = await import("./mod_standard/index.js");
|
||||
await modStandard.run(argvArg);
|
||||
});
|
||||
|
||||
// ======> Specific tasks <======
|
||||
@@ -35,43 +46,44 @@ export let run = async () => {
|
||||
/**
|
||||
* commit something
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('commit').subscribe(async (argvArg) => {
|
||||
const modCommit = await import('./mod_commit/index.js');
|
||||
gitzoneSmartcli.addCommand("commit").subscribe(async (argvArg) => {
|
||||
const modCommit = await import("./mod_commit/index.js");
|
||||
await modCommit.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* deprecate a package on npm
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('deprecate').subscribe(async (argvArg) => {
|
||||
const modDeprecate = await import('./mod_deprecate/index.js');
|
||||
gitzoneSmartcli.addCommand("deprecate").subscribe(async (argvArg) => {
|
||||
const modDeprecate = await import("./mod_deprecate/index.js");
|
||||
await modDeprecate.run();
|
||||
});
|
||||
|
||||
/**
|
||||
* docker
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('docker').subscribe(async (argvArg) => {
|
||||
const modDocker = await import('./mod_docker/index.js');
|
||||
gitzoneSmartcli.addCommand("docker").subscribe(async (argvArg) => {
|
||||
const modDocker = await import("./mod_docker/index.js");
|
||||
await modDocker.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* Update all files that comply with the gitzone standard
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('format').subscribe(async (argvArg) => {
|
||||
gitzoneSmartcli.addCommand("format").subscribe(async (argvArg) => {
|
||||
const config = GitzoneConfig.fromCwd();
|
||||
const modFormat = await import('./mod_format/index.js');
|
||||
const modFormat = await import("./mod_format/index.js");
|
||||
|
||||
// Handle format with options
|
||||
// Default is dry-mode, use --write/-w to apply changes
|
||||
await modFormat.run({
|
||||
...argvArg,
|
||||
write: argvArg.write || argvArg.w,
|
||||
dryRun: argvArg['dry-run'],
|
||||
dryRun: argvArg["dry-run"],
|
||||
yes: argvArg.yes,
|
||||
planOnly: argvArg['plan-only'],
|
||||
savePlan: argvArg['save-plan'],
|
||||
fromPlan: argvArg['from-plan'],
|
||||
planOnly: argvArg["plan-only"],
|
||||
savePlan: argvArg["save-plan"],
|
||||
fromPlan: argvArg["from-plan"],
|
||||
detailed: argvArg.detailed,
|
||||
interactive: argvArg.interactive !== false,
|
||||
verbose: argvArg.verbose,
|
||||
@@ -82,54 +94,54 @@ export let run = async () => {
|
||||
/**
|
||||
* run meta commands
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('meta').subscribe(async (argvArg) => {
|
||||
gitzoneSmartcli.addCommand("meta").subscribe(async (argvArg) => {
|
||||
const config = GitzoneConfig.fromCwd();
|
||||
const modMeta = await import('./mod_meta/index.js');
|
||||
const modMeta = await import("./mod_meta/index.js");
|
||||
modMeta.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* open assets
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('open').subscribe(async (argvArg) => {
|
||||
const modOpen = await import('./mod_open/index.js');
|
||||
gitzoneSmartcli.addCommand("open").subscribe(async (argvArg) => {
|
||||
const modOpen = await import("./mod_open/index.js");
|
||||
modOpen.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* add a readme to a project
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('template').subscribe(async (argvArg) => {
|
||||
const modTemplate = await import('./mod_template/index.js');
|
||||
gitzoneSmartcli.addCommand("template").subscribe(async (argvArg) => {
|
||||
const modTemplate = await import("./mod_template/index.js");
|
||||
modTemplate.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* start working on a project
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('start').subscribe(async (argvArg) => {
|
||||
const modTemplate = await import('./mod_start/index.js');
|
||||
gitzoneSmartcli.addCommand("start").subscribe(async (argvArg) => {
|
||||
const modTemplate = await import("./mod_start/index.js");
|
||||
modTemplate.run(argvArg);
|
||||
});
|
||||
|
||||
gitzoneSmartcli.addCommand('helpers').subscribe(async (argvArg) => {
|
||||
const modHelpers = await import('./mod_helpers/index.js');
|
||||
gitzoneSmartcli.addCommand("helpers").subscribe(async (argvArg) => {
|
||||
const modHelpers = await import("./mod_helpers/index.js");
|
||||
modHelpers.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* manage release configuration
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('config').subscribe(async (argvArg) => {
|
||||
const modConfig = await import('./mod_config/index.js');
|
||||
gitzoneSmartcli.addCommand("config").subscribe(async (argvArg) => {
|
||||
const modConfig = await import("./mod_config/index.js");
|
||||
await modConfig.run(argvArg);
|
||||
});
|
||||
|
||||
/**
|
||||
* manage development services (MongoDB, S3/MinIO)
|
||||
*/
|
||||
gitzoneSmartcli.addCommand('services').subscribe(async (argvArg) => {
|
||||
const modServices = await import('./mod_services/index.js');
|
||||
gitzoneSmartcli.addCommand("services").subscribe(async (argvArg) => {
|
||||
const modServices = await import("./mod_services/index.js");
|
||||
await modServices.run(argvArg);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user