From 7acfa1345dd7d6d43a644b35dc6375738b5281ee Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 5 Feb 2025 22:49:05 -0500 Subject: [PATCH] Preconfigure site settings and the database (#10) --- README.md | 17 +++++++++++++++++ binaries.js | 2 +- drupal-cms.js | 26 ++++++++++++++++++++------ forge.config.js | 4 ++-- preload.js | 2 +- settings.local.php | 9 +++++++++ 6 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 settings.local.php diff --git a/README.md b/README.md index f79b5d4..a33d4c1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/binaries.js b/binaries.js index 0540d6c..d0425a1 100644 --- a/binaries.js +++ b/binaries.js @@ -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' ); diff --git a/drupal-cms.js b/drupal-cms.js index 828aeca..5107a45 100644 --- a/drupal-cms.js +++ b/drupal-cms.js @@ -1,6 +1,8 @@ const { execFile } = require( 'node:child_process' ); +const { randomBytes } = require( 'node:crypto' ); const { appendFile, + copyFile, cp: mirror, readFile, writeFile, @@ -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' ), - ` { diff --git a/settings.local.php b/settings.local.php new file mode 100644 index 0000000..17f92d0 --- /dev/null +++ b/settings.local.php @@ -0,0 +1,9 @@ + '', + 'database' => 'sites/default/files/.ht.sqlite', + 'driver' => 'sqlite', + 'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite', + 'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/', +);