Skip to content

Commit

Permalink
Merge pull request #35 from Fgerthoffert/develop
Browse files Browse the repository at this point in the history
Added ability to enable/disable a module for a particular site
  • Loading branch information
Fgerthoffert authored Mar 23, 2020
2 parents 61f3cb1 + 84d8c5e commit f3c4abf
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 124 deletions.
4 changes: 2 additions & 2 deletions src/commands/groovy/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'fs';

import Command from '../../base';

import { submitGroovy } from '../../utils/tools';
import { submitGroovyFile } from '../../utils/tools';

import { exit } from '@oclif/errors';

Expand Down Expand Up @@ -40,7 +40,7 @@ export default class GroovyExecute extends Command {
exit();
}

const submitForm = await submitGroovy(
const submitForm = await submitGroovyFile(
flags.jahiaToolsUsername,
flags.jahiaToolsPassword,
flags.jahiaAdminUrl + '/modules/tools/groovyConsole.jsp?',
Expand Down
5 changes: 5 additions & 0 deletions src/commands/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export default class ManifestCreate extends Command {
id: 'popperjs',
filepath: '/tmp/popperjs-1.16.0.jar',
},
{
type: 'modulesite',
siteId: 'digitall',
moduleId: 'popperjs',
},
{
type: 'asset',
fetch: 'http',
Expand Down
275 changes: 157 additions & 118 deletions src/commands/manifest/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,132 +21,171 @@ import buildModule from '../../components/modules/build';
import importPrepackagedWebproject from '../../components/webprojects/importprepackaged';
import importFileWebproject from '../../components/webprojects/importfile';
import execShellCommand from '../../components/shell/utils/async-exec';
import { submitGroovy } from '../../utils/tools';
import {
enableModule,
disableModule,
} from '../../components/modules/utils/groovy';

import { submitGroovyFile, submitGroovy } from '../../utils/tools';

import { exit } from '@oclif/errors';

export default class ManifestRun extends Command {
static description = 'Install modules from a manifest file';
static description = 'Install modules from a manifest file';

static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
manifest: flags.string({
required: true,
description: 'Specify the filepath to the manifest'
})
};
static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
manifest: flags.string({
required: true,
description: 'Specify the filepath to the manifest',
}),
};

static args = [ { name: 'file' } ];
static args = [{ name: 'file' }];

async run() {
const { flags } = this.parse(ManifestRun);
const t0 = performance.now();
async run() {
const { flags } = this.parse(ManifestRun);
const t0 = performance.now();

if (flags.manifest === undefined) {
console.log('ERROR: Please specify a manifest file');
exit();
}
if (fs.existsSync(flags.manifest) === false) {
console.log('ERROR: Unable to locate manifest file');
exit();
}
if (flags.manifest === undefined) {
console.log('ERROR: Please specify a manifest file');
exit();
}
if (fs.existsSync(flags.manifest) === false) {
console.log('ERROR: Unable to locate manifest file');
exit();
}

const manifestContent = await loadYamlFile(flags.manifest);
if (manifestContent.jobs !== undefined && manifestContent.jobs.length > 0) {
const gClient = await graphqlClient(flags);
await waitAlive(gClient, 500000); // Wait for 500s by default
let browser = null;
let jahiaPage = null;
for (const job of manifestContent.jobs) {
cli.action.start('Running a job of type: ' + job.type);
const t1 = performance.now();
if ([ 'webproject', 'groovy' ].includes(job.type)) {
if (browser === null) {
// eslint-disable-next-line no-await-in-loop
browser = await launchPuppeteer(!flags.debug);
// eslint-disable-next-line no-await-in-loop
jahiaPage = await openJahia(browser, flags);
}
}
if (job.type === 'asset') {
// eslint-disable-next-line no-await-in-loop
await assetsFetch(job);
} else if (job.type === 'build') {
// eslint-disable-next-line no-await-in-loop
const builtModules = await buildModule(job.directory, job.id, job.branch, job.repository);
if (job.deploy === true) {
// eslint-disable-next-line max-depth
for (const jahiaModule of builtModules) {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, jahiaModule, false);
}
}
} else if (job.type === 'module') {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, job.filepath, job.id);
} else if (job.type === 'webproject') {
// eslint-disable-next-line no-await-in-loop
await navPage(
jahiaPage,
flags.jahiaAdminUrl + '/cms/adminframe/default/en/settings.webProjectSettings.html'
);
if (job.source === 'prepackaged') {
// eslint-disable-next-line no-await-in-loop
await importPrepackagedWebproject(jahiaPage, job.sitekey);
} else if (job.source === 'file') {
// eslint-disable-next-line no-await-in-loop
await importFileWebproject(jahiaPage, job.sitekey, job.filepath);
} else {
console.log('ERROR: Unsupported webproject source type');
exit();
}
} else if (job.type === 'groovy') {
// eslint-disable-next-line no-await-in-loop
if (fs.existsSync(job.filepath) === false) {
console.log('ERROR: Unable to access file: ' + job.filepath);
exit();
}
// eslint-disable-next-line no-await-in-loop
const submitForm = await submitGroovy(
flags.jahiaToolsUsername,
flags.jahiaToolsPassword,
flags.jahiaAdminUrl + '/modules/tools/groovyConsole.jsp?',
job.filepath
);
if (submitForm === false) {
console.log(
'ERROR: Unable execute the groovy script, try running it manually through Jahia Tools: ' +
job.filepath
);
exit();
} else {
console.log('Groovy script successfully executed: ' + job.filepath);
}
} else if (job.type === 'shell') {
// eslint-disable-next-line no-await-in-loop
const command = await execShellCommand(job.cmd);
console.log(command);
if (job.output !== undefined) {
fs.writeFileSync(job.output, command);
}
} else {
console.log('ERROR: Unsupported job type');
exit();
}
cli.action.stop(' done (' + Math.round(performance.now() - t1) + ' ms)');
}
const manifestContent = await loadYamlFile(flags.manifest);
if (manifestContent.jobs !== undefined && manifestContent.jobs.length > 0) {
const gClient = await graphqlClient(flags);
await waitAlive(gClient, 500000); // Wait for 500s by default
let browser = null;
let jahiaPage = null;
for (const job of manifestContent.jobs) {
cli.action.start('Running a job of type: ' + job.type);
const t1 = performance.now();
if (['webproject', 'groovy'].includes(job.type)) {
if (browser === null) {
// eslint-disable-next-line no-await-in-loop
browser = await launchPuppeteer(!flags.debug);
// eslint-disable-next-line no-await-in-loop
jahiaPage = await openJahia(browser, flags);
}
}
if (job.type === 'asset') {
// eslint-disable-next-line no-await-in-loop
await assetsFetch(job);
} else if (job.type === 'build') {
// eslint-disable-next-line no-await-in-loop
const builtModules = await buildModule(
job.directory,
job.id,
job.branch,
job.repository,
);
if (job.deploy === true) {
// eslint-disable-next-line max-depth
for (const jahiaModule of builtModules) {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, jahiaModule, false);
}
}
} else if (job.type === 'module') {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, job.filepath, job.id);
} else if (job.type === 'webproject') {
// eslint-disable-next-line no-await-in-loop
await navPage(
jahiaPage,
flags.jahiaAdminUrl +
'/cms/adminframe/default/en/settings.webProjectSettings.html',
);
if (job.source === 'prepackaged') {
// eslint-disable-next-line no-await-in-loop
await importPrepackagedWebproject(jahiaPage, job.sitekey);
} else if (job.source === 'file') {
// eslint-disable-next-line no-await-in-loop
await importFileWebproject(jahiaPage, job.sitekey, job.filepath);
} else {
console.log('ERROR: Unsupported webproject source type');
exit();
}
} else if (job.type === 'groovy') {
// eslint-disable-next-line no-await-in-loop
if (fs.existsSync(job.filepath) === false) {
console.log('ERROR: Unable to access file: ' + job.filepath);
exit();
}
// eslint-disable-next-line no-await-in-loop
const submitForm = await submitGroovyFile(
flags.jahiaToolsUsername,
flags.jahiaToolsPassword,
flags.jahiaAdminUrl + '/modules/tools/groovyConsole.jsp?',
job.filepath,
);
if (submitForm === false) {
console.log(
'ERROR: Unable execute the groovy script, try running it manually through Jahia Tools: ' +
job.filepath,
);
exit();
} else {
console.log('Groovy script successfully executed: ' + job.filepath);
}
} else if (job.type === 'modulesite') {
let groovyScript = enableModule
.replace('SITEID', job.siteId)
.replace('MODULEID', job.moduleId);
if (job.action === 'disable') {
groovyScript = disableModule
.replace('SITEID', job.siteId)
.replace('MODULEID', job.moduleId);
}
// eslint-disable-next-line no-await-in-loop
const groovySubmit = await submitGroovy(
flags.jahiaToolsUsername,
flags.jahiaToolsPassword,
flags.jahiaAdminUrl + '/modules/tools/groovyConsole.jsp?',
groovyScript,
);
if (groovySubmit === false) {
console.log(
'ERROR: Unable execute the groovy script, try running it manually through Jahia Tools',
);
exit();
} else {
console.log('Groovy script successfully executed');
}
} else if (job.type === 'shell') {
// eslint-disable-next-line no-await-in-loop
const command = await execShellCommand(job.cmd);
console.log(command);
if (job.output !== undefined) {
fs.writeFileSync(job.output, command);
}
} else {
console.log('ERROR: Unsupported job type');
exit();
}
cli.action.stop(
' done (' + Math.round(performance.now() - t1) + ' ms)',
);
}

if (jahiaPage !== null) {
await jahiaPage.close();
}
if (browser !== null) {
await closePuppeteer(browser);
}
} else {
console.log('Manifest is empty and does not contain any jobs');
}
const t1 = performance.now();
console.log('Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.');
}
if (jahiaPage !== null) {
await jahiaPage.close();
}
if (browser !== null) {
await closePuppeteer(browser);
}
} else {
console.log('Manifest is empty and does not contain any jobs');
}
const t1 = performance.now();
console.log(
'Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.',
);
}
}
62 changes: 62 additions & 0 deletions src/commands/modules/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { flags } from '@oclif/command';
import { performance } from 'perf_hooks';

import Command from '../../base';

import graphqlClient from '../../utils/graphql/client';
import waitAlive from '../../utils/waitAlive';

import { exit } from '@oclif/errors';

import { submitGroovy } from '../../utils/tools';
import { disableModule } from '../../components/modules/utils/groovy';

export default class ModulesEnable extends Command {
static description = 'Disable a module on a particular site';

static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
mid: flags.string({
required: true,
description: 'Module ID (for example: augmented-search-ui)',
}),
sid: flags.string({
required: true,
description: 'Site ID (for example: digitall)',
}),
};

static args = [{ name: 'file' }];

async run() {
const { flags } = this.parse(ModulesEnable);
const t0 = performance.now();

const gClient = await graphqlClient(flags);
await waitAlive(gClient, 500000); // Wait for 500s by default

const groovyScript = disableModule
.replace('SITEID', flags.sid)
.replace('MODULEID', flags.mid);

const submitForm = await submitGroovy(
flags.jahiaToolsUsername,
flags.jahiaToolsPassword,
flags.jahiaAdminUrl + '/modules/tools/groovyConsole.jsp?',
groovyScript,
);
if (submitForm === false) {
console.log(
'ERROR: Unable execute the groovy script, try running it manually through Jahia Tools',
);
exit();
} else {
console.log('Groovy script successfully executed');
}
const t1 = performance.now();
console.log(
'Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.',
);
}
}
Loading

0 comments on commit f3c4abf

Please sign in to comment.