#!/usr/bin/env node
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
import {CustomWidgetBuilder} from "./CustomWidgetBuilder";
import {WebComponentCopier} from "./WebComponentCopier";
import {CliDefinition} from "./CliDefinition";
import fs from "fs";
import path from "path";
try {
let cli = new CliDefinition();
let params = cli.getParams();
let command = cli.getCommand();
if (params.outputDir) {
createDirIfNeeded(params.outputDir);
}
switch (command) {
case CliDefinition.genPropertiesCommand:
case CliDefinition.genPropertiesCommandAlias:
new CustomWidgetBuilder().generatePropertyFileFromWcFile(params.webComponentSource, params.outputDir);
break;
case CliDefinition.genPropertiesTemplateCommand:
case CliDefinition.genPropertiesTemplateCommandAlias:
new CustomWidgetBuilder().generatePropertyFileFromWcName(params.webComponentName, params.outputDir);
break;
case CliDefinition.genWidgetCommand:
case CliDefinition.genWidgetCommandAlias:
new CustomWidgetBuilder().generateWidget(params.propertiesFile, params.webComponentBundle, params.outputDir);
break;
case CliDefinition.genWidgetAssetsCommand:
case CliDefinition.genWidgetAssetsCommandAlias:
new CustomWidgetBuilder().generateWidgetAssets(params.propertiesFile, params.webComponentBundle, params.outputDir);
break;
case CliDefinition.duplicateWidgetCommand:
case CliDefinition.duplicateWidgetCommandAlias:
new WebComponentCopier().copyWebComponent(params.srcDir, params.destDir);
break;
default:
console.error("Invalid command: " + command);
}
function createDirIfNeeded(dir: string) {
if (!fs.existsSync(dir)) {
if (!fs.existsSync(path.dirname(dir))) {
throw new Error(`Directory does not exist: ${path.dirname(dir)}`);
}
fs.mkdirSync(dir);
}
}
} catch (error) {
console.error(error.message);
}