feat: add Drupal application module
This commit is contained in:
@@ -132,9 +132,9 @@ async function renderCompose(c: AuroraConfig): Promise<string> {
|
||||
async function writePhpDockerfile(root: string, xdebug = false): Promise<void> {
|
||||
await writeFile(phpDockerfilePath(root), `ARG PHP_VERSION=8.4
|
||||
FROM php:${'${PHP_VERSION}'}-fpm-alpine
|
||||
RUN apk add --no-cache icu-dev libzip-dev libpng-dev libjpeg-turbo-dev freetype-dev oniguruma-dev postgresql-dev \
|
||||
RUN apk add --no-cache icu-dev libzip-dev libpng-dev libjpeg-turbo-dev freetype-dev oniguruma-dev postgresql-dev curl-dev libxml2-dev \
|
||||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||
&& docker-php-ext-install -j2 mysqli pdo_mysql pdo_pgsql intl zip gd mbstring
|
||||
&& docker-php-ext-install -j2 mysqli pdo_mysql pdo_pgsql intl zip gd mbstring curl dom opcache
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
||||
${xdebug ? 'RUN apk add --no-cache $PHPIZE_DEPS linux-headers && pecl install xdebug && docker-php-ext-enable xdebug' : ''}
|
||||
`)
|
||||
@@ -211,7 +211,9 @@ export async function createProject(root: string, name: string, type: string, do
|
||||
if (stack?.adminer !== false) modules.push('adminer')
|
||||
if (stack?.redis) modules.push('redis')
|
||||
if (stack?.mailpit) modules.push('mailpit')
|
||||
const config: AuroraConfig = { name, type: normalizedType, docroot: defaultDocroot, php: stack?.phpVersion || '8.4', node: stack?.nodeVersion || '24', webserver: stack?.webServer || 'nginx', database: stack?.database || 'mariadb', databaseVersion: stack?.databaseVersion || '11.8', modules, moduleSettings: {}, primaryProtocol: 'https', xdebug: stack?.xdebug === true }
|
||||
const phpVersion = stack?.phpVersion || application.creation?.phpVersions?.[0] || '8.4'
|
||||
if (application.creation?.phpVersions?.length && !application.creation.phpVersions.includes(phpVersion)) throw new Error(`${application.name} does not support PHP ${phpVersion}`)
|
||||
const config: AuroraConfig = { name, type: normalizedType, docroot: defaultDocroot, php: phpVersion, node: stack?.nodeVersion || '24', webserver: stack?.webServer || 'nginx', database: stack?.database || 'mariadb', databaseVersion: stack?.databaseVersion || '11.8', modules, moduleSettings: {}, primaryProtocol: 'https', xdebug: stack?.xdebug === true }
|
||||
await writeConfig(root, config); await writeWebServerConfig(root, config); await writePhpDockerfile(root, config.xdebug)
|
||||
const reg = await loadRegistry(); reg.projects[name] = root; await saveRegistry(reg)
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ describe('external module registry', () => {
|
||||
expect(() => validateModuleManifest({ ...manifest, main: '../outside.cjs' })).toThrow(/may not leave/)
|
||||
expect(() => validateModuleManifest({ ...manifest, dependencies: ['../escape'] })).toThrow(/module id array/)
|
||||
expect(() => validateModuleManifest({ ...manifest, project: { adminPath: 'admin' } })).toThrow(/must start with/)
|
||||
expect(() => validateModuleManifest({ ...manifest, creation: { phpVersions: ['latest'] } })).toThrow(/PHP minor versions/)
|
||||
})
|
||||
it('rejects symbolic links in package paths', async () => {
|
||||
const userData = await temp('aurora-user-'); const source = await packageDir(); await mkdir(join(source, 'main')); await symlink('/tmp', join(source, 'main', 'escape'))
|
||||
@@ -135,4 +136,14 @@ describe('external module registry', () => {
|
||||
expect((await installModulePackage(archive, userData)).manifest.id).toBe('wordpress')
|
||||
expect((await getModuleRegistry(userData)).map((item) => item.id)).toEqual(['wordpress'])
|
||||
})
|
||||
|
||||
it('accepts and packages the Drupal application module contract', async () => {
|
||||
const packageRoot = resolve(process.cwd(), 'packages/aurora-module-drupal')
|
||||
const actual = JSON.parse(await readFile(join(packageRoot, 'manifest.json'), 'utf8'))
|
||||
expect(validateModuleManifest(actual)).toMatchObject({ id: 'drupal', defaults: { docroot: 'web' } })
|
||||
const archive = join(await temp('aurora-pac-'), 'drupal.pac')
|
||||
await execFileAsync('zip', ['-qr', archive, '.'], { cwd: packageRoot })
|
||||
const userData = await temp('aurora-user-')
|
||||
expect((await installModulePackage(archive, userData)).manifest.id).toBe('drupal')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -51,7 +51,11 @@ export function validateModuleManifest(value: unknown): AuroraModuleManifest {
|
||||
if (!compatible(aurora.core, CORE_VERSION)) throw new Error(`Module requires Aurora Core '${aurora.core}', running '${CORE_VERSION}'`)
|
||||
if (!compatible(aurora.moduleApi, MODULE_API_VERSION)) throw new Error(`Module API '${aurora.moduleApi}' is incompatible with '${MODULE_API_VERSION}'`)
|
||||
if (m.main !== undefined) validateRelativePackagePath(m.main, 'main')
|
||||
if (m.creation && typeof m.creation === 'object') validateSettings((m.creation as Record<string, unknown>).setup ?? [], 'creation.setup')
|
||||
if (m.creation && typeof m.creation === 'object') {
|
||||
const creation = m.creation as Record<string, unknown>
|
||||
validateSettings(creation.setup ?? [], 'creation.setup')
|
||||
if (creation.phpVersions !== undefined && (!Array.isArray(creation.phpVersions) || !creation.phpVersions.every((version) => typeof version === 'string' && /^\d+\.\d+$/.test(version)))) throw new Error('creation.phpVersions must contain PHP minor versions')
|
||||
}
|
||||
if (m.project !== undefined) {
|
||||
if (!m.project || typeof m.project !== 'object' || Array.isArray(m.project)) throw new Error('project must be an object')
|
||||
const project = m.project as Record<string, unknown>
|
||||
|
||||
@@ -35,6 +35,7 @@ export async function runModuleLifecycleHook(moduleId: string, hook: AuroraModul
|
||||
if (typeof handler !== 'function') return false
|
||||
const directory = options.directory
|
||||
const urls = options.projectName ? projectUrls(options.projectName) : undefined
|
||||
const projectConfig = directory ? await getProjectConfig(directory) : undefined
|
||||
const run = async (label: string, command: string, args: string[]): Promise<void> => {
|
||||
if (options.sender && options.operationId) {
|
||||
if (!options.sender.isDestroyed()) options.sender.send('terminal:data', { operationId: options.operationId, stream: 'stdout', chunk: `\n[${manifest.name}] ${label}\n` })
|
||||
@@ -49,6 +50,7 @@ export async function runModuleLifecycleHook(moduleId: string, hook: AuroraModul
|
||||
projectName: options.projectName,
|
||||
toolId: options.toolId,
|
||||
settings: Object.freeze({ ...(options.settings ?? {}) }),
|
||||
environment: projectConfig ? Object.freeze({ php: projectConfig.php, node: projectConfig.node, webserver: projectConfig.webserver, database: projectConfig.database, databaseVersion: projectConfig.databaseVersion, docroot: projectConfig.docroot }) : undefined,
|
||||
urls: urls ? Object.freeze(urls) : undefined,
|
||||
run,
|
||||
ensureRouter,
|
||||
|
||||
@@ -224,7 +224,7 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }): React.
|
||||
<div>
|
||||
<label className={labelClass}>Project type</label>
|
||||
<div className="grid gap-2 sm:grid-cols-2">
|
||||
{applicationModules.map((module) => ({ value: module.id, label: module.name, defaults: module.defaults })).map((t) => {
|
||||
{applicationModules.map((module) => ({ value: module.id, label: module.name, defaults: module.defaults, creation: module.creation })).map((t) => {
|
||||
const Icon = TYPE_ICONS[t.value] ?? Boxes
|
||||
const isSelected = projectType === t.value
|
||||
|
||||
@@ -234,6 +234,7 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }): React.
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setProjectType(t.value)
|
||||
setPhpVersion(t.creation?.phpVersions?.[0] ?? '8.4')
|
||||
if (!docroot.trim() && t.defaults?.docroot) setDocroot(t.defaults.docroot)
|
||||
}}
|
||||
className={clsx(
|
||||
@@ -272,7 +273,7 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }): React.
|
||||
<p className="mt-0.5 text-xs text-neutral-500 dark:text-neutral-400">Aurora core owns the runtime; the application is a module layered on top.</p>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div><label className={labelClass}>PHP</label><select className={fieldClass} value={phpVersion} onChange={(e)=>setPhpVersion(e.target.value)}>{['8.2','8.3','8.4','8.5'].map(v=><option key={v}>{v}</option>)}</select></div>
|
||||
<div><label className={labelClass}>PHP</label><select className={fieldClass} value={phpVersion} onChange={(e)=>setPhpVersion(e.target.value)}>{(selectedModule?.creation?.phpVersions ?? ['8.2','8.3','8.4','8.5']).map(v=><option key={v}>{v}</option>)}</select></div>
|
||||
<div><label className={labelClass}>Node.js</label><select className={fieldClass} value={nodeVersion} onChange={(e)=>setNodeVersion(e.target.value)}>{['20','22','24'].map(v=><option key={v}>{v}</option>)}</select></div>
|
||||
<div><label className={labelClass}>Web server</label><select className={fieldClass} value={webServer} onChange={(e)=>setWebServer(e.target.value as 'nginx'|'apache')}><option value="nginx">nginx</option><option value="apache">Apache</option></select></div>
|
||||
<div><label className={labelClass}>Database</label><select className={fieldClass} value={`${database}:${databaseVersion}`} onChange={(e)=>{const [kind,version]=e.target.value.split(':');setDatabase(kind as 'mariadb'|'mysql'|'postgres');setDatabaseVersion(version)}}>{selectedModule?.creation?.databases?.includes('mariadb') !== false && <><option value="mariadb:11.8">MariaDB 11.8</option><option value="mariadb:10.11">MariaDB 10.11</option></>}{selectedModule?.creation?.databases?.includes('mysql') !== false && <><option value="mysql:8.4">MySQL 8.4</option><option value="mysql:8.0">MySQL 8.0</option></>}{selectedModule?.creation?.databases?.includes('postgres') !== false && <><option value="postgres:17">PostgreSQL 17</option><option value="postgres:16">PostgreSQL 16</option></>}</select></div>
|
||||
|
||||
@@ -162,10 +162,10 @@ export function ProjectDetail({ name }: { name: string }): React.JSX.Element {
|
||||
const services = Object.values(project.services)
|
||||
const runningServices = services.filter((service) => service.status === 'running').length
|
||||
|
||||
const phpVersions =
|
||||
project.php_version && !PHP_VERSIONS.includes(project.php_version)
|
||||
? [project.php_version, ...PHP_VERSIONS]
|
||||
: PHP_VERSIONS
|
||||
const supportedPhpVersions = applicationManifest?.creation?.phpVersions ?? PHP_VERSIONS
|
||||
const phpVersions = project.php_version && !supportedPhpVersions.includes(project.php_version)
|
||||
? [project.php_version, ...supportedPhpVersions]
|
||||
: supportedPhpVersions
|
||||
|
||||
const currentDatabase = `${project.dbinfo.database_type}:${project.dbinfo.database_version}`
|
||||
const projectContribution = applicationManifest?.project
|
||||
|
||||
@@ -143,6 +143,7 @@ export interface AuroraModuleManifest {
|
||||
aurora: { core: string; moduleApi: string }
|
||||
creation?: {
|
||||
databases?: Array<'mariadb' | 'mysql' | 'postgres'>
|
||||
phpVersions?: string[]
|
||||
setup?: AuroraModuleSetting[]
|
||||
intro?: { title: string; description: string; icon?: string }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user