Skip to content

Commit

Permalink
Merge pull request #29 from Fgerthoffert/develop
Browse files Browse the repository at this point in the history
Added flag to force module installation
  • Loading branch information
Fgerthoffert authored Feb 18, 2020
2 parents f46bd66 + 4e77541 commit a6bdb64
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 189 deletions.
244 changes: 117 additions & 127 deletions src/commands/manifest/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,137 +26,127 @@ import { 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);
}
}
} 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 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)');
}

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.');
}
}
110 changes: 51 additions & 59 deletions src/commands/modules/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,62 @@ import buildModule from '../../components/modules/build';
import installModule from '../../components/modules/install';

export default class ModulesBuild extends Command {
static description = 'Installs a module';
static description = 'Installs a module';

static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
directory: flags.string({
required: true,
description: 'Directory to use as a base for storing the build artifacts',
}),
file: flags.string({
// required: true,
description:
'Specify the filepath to the module to be installed (jar on filesystem)',
}),
repository: flags.string({
required: true,
description: 'Repository to clone',
default: '[email protected]:Jahia/LDAP-provider.git',
}),
id: flags.string({
required: true,
default: 'ldap',
description: 'Module Id',
}),
branch: flags.string({
required: true,
default: 'master',
description: 'Git repository branch',
}),
deploy: flags.string({
required: false,
default: 'true',
description: 'Trigger a deployment of the module',
}),
};
static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
directory: flags.string({
required: true,
description: 'Directory to use as a base for storing the build artifacts'
}),
file: flags.string({
// required: true,
description: 'Specify the filepath to the module to be installed (jar on filesystem)'
}),
repository: flags.string({
required: true,
description: 'Repository to clone',
default: '[email protected]:Jahia/LDAP-provider.git'
}),
id: flags.string({
required: true,
default: 'ldap',
description: 'Module Id'
}),
branch: flags.string({
required: true,
default: 'master',
description: 'Git repository branch'
}),
deploy: flags.string({
required: false,
default: 'true',
description: 'Trigger a deployment of the module'
})
};

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

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

if (!fs.existsSync(flags.directory)) {
console.log('ERROR: Unable to access directory: ' + flags.directory);
exit();
}
if (!fs.existsSync(flags.directory)) {
console.log('ERROR: Unable to access directory: ' + flags.directory);
exit();
}

const buildModules = await buildModule(
flags.directory,
flags.id,
flags.branch,
flags.repository,
);
const buildModules = await buildModule(flags.directory, flags.id, flags.branch, flags.repository);

if (JSON.parse(flags.deploy)) {
for (const jahiaModule of buildModules) {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, jahiaModule);
}
}
if (JSON.parse(flags.deploy)) {
for (const jahiaModule of buildModules) {
// eslint-disable-next-line no-await-in-loop
await installModule(flags, jahiaModule, true);
}
}

const t1 = performance.now();
console.log(
'Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.',
);
}
const t1 = performance.now();
console.log('Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.');
}
}
2 changes: 1 addition & 1 deletion src/commands/modules/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class ModulesInstall extends Command {
const gClient = await graphqlClient(flags);
await waitAlive(gClient, 500000); // Wait for 500s by default

await installModule(flags, flags.file, flags.id, flags.force);
await installModule(flags, flags.file, flags.force, flags.id);

const t1 = performance.now();
console.log('Total Exceution time: ' + Math.round(t1 - t0) + ' milliseconds.');
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import installMod from '../utils/install-module';
const installModule = async (
flags: ConfigFlags,
moduleFilepath: string,
force: boolean,
moduleId?: string | undefined,
moduleVersion?: string | undefined,
force?: boolean | undefined
moduleVersion?: string | undefined
) => {
// ModuleId is undefined, we blindly push the module but don't check for proper installation
if (moduleId === undefined) {
Expand Down

0 comments on commit a6bdb64

Please sign in to comment.