Skip to content

Commit

Permalink
Preconfigure site settings and the database (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenaproxima authored Feb 6, 2025
1 parent 4f4e210 commit 7acfa13
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,20 @@ This project uses [static-php-cli](https://static-php.dev/) to create a statical

## How to try it
Go to the latest release (0.1.1 at the time of this writing) and download the appropriate file for your system. Extract the app and run it. If you're on Windows, you'll probably get some kind of security warning (that will go away when this app has the appropriate code signing, which is in progress).

## How to test

### Prerequisites
* Node (the JavaScript runtime, not the Drupal module 😉)
* PHP 8.3 or later, globally installed
* Composer, globally installed.

Clone this repository, then `cd` into it and run:
```shell
mkdir bin
ln -s -f $(which php) bin
ln -s -f $(which composer) bin/composer.phar
npm install
npm run start
```
To test the full app bundle, `npm run make` and then look for the final binary in the `out` directory.
2 changes: 1 addition & 1 deletion binaries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app } = require('electron');
const { app } = require( 'electron' );
const { execFileSync } = require( 'node:child_process' );
const { access } = require( 'node:fs/promises' );
const path = require( 'node:path' );
Expand Down
26 changes: 20 additions & 6 deletions drupal-cms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { execFile } = require( 'node:child_process' );
const { randomBytes } = require( 'node:crypto' );
const {
appendFile,
copyFile,
cp: mirror,
readFile,
writeFile,
Expand Down Expand Up @@ -28,15 +30,27 @@ module.exports = async ( dir, { php, composer }) => {
);
const webRoot = getWebRoot( dir );

// Ensure that Package Manager always uses our bundled copy of Composer.
const siteDir = path.join( webRoot, 'sites', 'default' );
// Create a local settings file so we can skip database set-up in the
// installer, which requires us to pre-generate the hash salt and the path
// of the config sync directory. We also explicitly configure Package
// Manager to use our bundled copy of Composer.
const localSettingsFile = path.join( siteDir, 'settings.local.php' );
await copyFile(
path.join( __dirname, 'settings.local.php' ),
localSettingsFile,
);
await appendFile(
path.join( siteDir, 'default.settings.php' ),
"if (PHP_SAPI === 'cli' || PHP_SAPI === 'cli-server') @include_once __DIR__ . '/settings.local.php';",
localSettingsFile,
`
$settings['hash_salt'] = '${ randomBytes( 32 ).toString( 'hex' ) }';
$settings['config_sync_directory'] = '${ path.join( dir, 'config' ) }';
$config['package_manager.settings']['executables']['composer'] = '${composer}';`,
);
await writeFile(
path.join( siteDir, 'settings.local.php' ),
`<?php\n$composer = '${composer}';\nif (file_exists($composer)) $config['package_manager.settings']['executables']['composer'] = $composer;`,
// Make sure we load the local settings if using the built-in web server.
await appendFile(
path.join( siteDir, 'default.settings.php' ),
`\nif (PHP_SAPI === 'cli' || PHP_SAPI === 'cli-server') @include_once __DIR__ . '/settings.local.php';\n`,
);

// Copy the `live_update` module into the code base and alter the install profile to include it.
Expand Down
4 changes: 2 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
const { FusesPlugin } = require( '@electron-forge/plugin-fuses' );
const { FuseV1Options, FuseVersion } = require( '@electron/fuses' );
const { APPLE_ID, APP_PASSWORD, APPLE_TEAM_ID } = process.env;

const packagerConfig = {
Expand Down
2 changes: 1 addition & 1 deletion preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron');
const { contextBridge, ipcRenderer } = require( 'electron' );

contextBridge.exposeInMainWorld( 'drupal', {
start: () => {
Expand Down
9 changes: 9 additions & 0 deletions settings.local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$databases['default']['default'] = array (
'prefix' => '',
'database' => 'sites/default/files/.ht.sqlite',
'driver' => 'sqlite',
'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
);

0 comments on commit 7acfa13

Please sign in to comment.