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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,15 @@ export namespace V2Schema {
type ContentDefinition =
| ({
type: 'mysql-dump';
source: DataSources.DataReference | DataSources.DataReference[];
source:
| DataSources.FileDataReference
| DataSources.FileDataReference[];
} & URLMappingConfig)
| ({
type: 'posts';
source:
| DataSources.DataReference
| DataSources.DataReference[]
| DataSources.FileDataReference
| DataSources.FileDataReference[]
| WordPressPost
| WordPressPost[];
} & URLMappingConfig)
Expand Down Expand Up @@ -483,7 +485,7 @@ export namespace V2Schema {
*/
| ({
type: 'wxr';
source: DataSources.DataReference;
source: DataSources.FileDataReference;

/**
* Static assets handling.
Expand Down Expand Up @@ -552,9 +554,9 @@ export namespace V2Schema {
} & URLMappingConfig);

type MediaDefinition =
| DataSources.DataReference
| DataSources.FileDataReference
| {
source: DataSources.DataReference;
source: DataSources.FileDataReference;
title?: string;
description?: string;
alt?: string;
Expand Down Expand Up @@ -1523,7 +1525,7 @@ export namespace V2Schema {
/**
* The PHP file to execute.
*/
code: DataSources.DataReference;
code: DataSources.FileDataReference;
/**
* Environment variables to set for this run.
*/
Expand All @@ -1532,7 +1534,7 @@ export namespace V2Schema {

type RunSQLStep = {
step: 'runSQL';
source: DataSources.DataReference;
source: DataSources.FileDataReference;
};

/**
Expand Down Expand Up @@ -1564,7 +1566,7 @@ export namespace V2Schema {
/**
* The zip file resource to extract.
*/
zipFile: DataSources.DataReference;
zipFile: DataSources.FileDataReference;
/**
* The path to extract the zip file to inside the virtual filesystem.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export namespace DataSources {
| InlineDirectory
| GitPath;

/**
* A data reference that must resolve to a single file.
*/
Comment on lines +114 to +116
export type FileDataReference =
| URLReference
| ExecutionContextPath
| InlineFile;
Comment on lines +117 to +120

/**
* }}}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import type { BlueprintV2Declaration } from '../../lib/v2/blueprint-v2-declaration';

describe('Blueprint v2 declaration types', () => {
it('accepts file data references for file-only fields', () => {
const blueprint = {
version: 2,
content: [
{
type: 'mysql-dump',
source: './dump.sql',
},
{
type: 'posts',
source: {
filename: 'posts.json',
content: '[]',
},
},
{
type: 'wxr',
source: './content.wxr',
},
],
media: [
'./image.jpg',
{
source: {
filename: 'image.jpg',
content: 'image',
},
title: 'Image',
},
],
additionalStepsAfterExecution: [
{
step: 'runPHP',
code: {
filename: 'script.php',
content: '<?php echo "Hello";',
},
},
{
step: 'runSQL',
source: './dump.sql',
},
{
step: 'unzip',
zipFile: './archive.zip',
extractToPath: '/tmp/archive',
},
],
} satisfies BlueprintV2Declaration;

expect(blueprint.version).toBe(2);
});
});

const blueprintWithDirectoryAsRunPHPCode = {
version: 2,
additionalStepsAfterExecution: [
{
step: 'runPHP',
code: {
// @ts-expect-error runPHP code must resolve to a single file.
directoryName: 'scripts',
files: {
'index.php': '<?php echo "Hello";',
},
},
},
],
} satisfies BlueprintV2Declaration;

const blueprintWithDirectoryAsMediaSource = {
version: 2,
media: [
{
source: {
// @ts-expect-error media source must resolve to a single file.
directoryName: 'images',
files: {
'image.jpg': 'image',
},
},
},
],
} satisfies BlueprintV2Declaration;

void blueprintWithDirectoryAsRunPHPCode;
void blueprintWithDirectoryAsMediaSource;
Loading