Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions src/main/Drupal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export class Drupal

],

update: [],
update: [
// Enable the site template helper plugin, which was added in Drupal CMS 2.0.1.
[
['config', 'allow-plugins.drupal/site_template_helper', 'true'],
],
],

}

Expand All @@ -61,7 +66,7 @@ export class Drupal
this.commands.install.splice(
this.commands.install.findIndex(command => command[0] === 'install'),
0,
['config', '--merge', '--json', 'extra.drupal-launcher', `{"version": ${this.commands.update.length + 1}}`]
['config', 'extra.drupal-launcher.version', String(this.commands.update.length + 1), '--json'],
);

if (fixture) {
Expand All @@ -72,6 +77,48 @@ export class Drupal
}
}

public async update (progress?: MessagePortMain): Promise<void>
{
const version: number = await this.version();

// Find the subset of updates that need to be done (if any).
const updates: string[][][] = this.commands.update.slice(version - 1);
if (updates.length === 0) {
return;
}
// Always add a final "update" to increment to stored version number.
updates.push([
['config', 'extra.drupal-launcher.version', String(version + 1), '--json'],
]);

let done: number = 0;
const total: number = updates.reduce((sum: number, commands: string[][]): number => sum + commands.length, 0);
progress?.postMessage({ done, total });

for (const commands of updates) {
for (const command of commands) {
await new ComposerCommand(...command).inDirectory(this.root).run();
done++;
progress?.postMessage({ done, total });
}
}
}

private async version (): Promise<number>
{
try {
const { stdout } = await new ComposerCommand('config', 'extra.drupal-launcher.version')
.inDirectory(this.root)
.run();

// If the version returned by Composer parses to NaN, default to 1.
return parseInt(stdout.toString().trim()) || 1;
}
catch {
return 1;
}
}

public async install (archive?: string | false, port?: MessagePortMain): Promise<void>
{
try {
Expand Down Expand Up @@ -260,7 +307,7 @@ export class Drupal
const checkForServerStart = (line: string, _: any, server: ChildProcess): void => {
if (line.includes(`(${url}) started`)) {
clearTimeout(timeoutId);
logger.debug(`Server started!`);
logger.debug(`Server started.`);

app.on('will-quit', () => this.stop());
this.server = server;
Expand Down
2 changes: 2 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ ipcMain.handle('drupal:start', async ({ sender: win }): Promise<string | null> =
settings.set('useArchive', false);
logger.debug('Permanently disabled pre-built archive.');

await drupal.update(progress);

if (argv.server) {
// Let the renderer know that we're going to start the server.
progress.postMessage({ server: true });
Expand Down
Loading