File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export async function readAndValidateYamlFromFile(
23
23
file : string ,
24
24
schema : Schema ,
25
25
errorMessage : string ,
26
+ defaultContents ?: string ,
26
27
) : Promise < unknown > {
27
28
if ( ! existsSync ( file ) ) {
28
29
throw new Error ( `YAML file ${ file } not found.` ) ;
@@ -33,8 +34,13 @@ export async function readAndValidateYamlFromFile(
33
34
shortFileName = relative ( Deno . cwd ( ) , shortFileName ) ;
34
35
}
35
36
37
+ let fileContents = Deno . readTextFileSync ( file ) . trimEnd ( ) ;
38
+ if ( ( fileContents . trim ( ) . length === 0 ) && defaultContents ) {
39
+ fileContents = defaultContents ;
40
+ }
41
+
36
42
const contents = asMappedString (
37
- Deno . readTextFileSync ( file ) . trimEnd ( ) ,
43
+ fileContents ,
38
44
shortFileName ,
39
45
) ;
40
46
const {
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ import { readAndValidateYamlFromFile } from "../core/schema/validated-yaml.ts";
76
76
77
77
import { getProjectConfigSchema } from "../core/lib/yaml-schema/project-config.ts" ;
78
78
import { getFrontMatterSchema } from "../core/lib/yaml-schema/front-matter.ts" ;
79
+ import { kDefaultProjectFileContents } from "./types/project-default.ts" ;
79
80
80
81
export function deleteProjectMetadata ( metadata : Metadata ) {
81
82
// see if the active project type wants to filter the config printed
@@ -123,6 +124,7 @@ export async function projectContext(
123
124
configFile ,
124
125
configSchema ,
125
126
errMsg ,
127
+ kDefaultProjectFileContents ,
126
128
) ) as ProjectConfig ;
127
129
projectConfig . project = projectConfig . project || { } ;
128
130
const includedMeta = await includedMetadata (
Original file line number Diff line number Diff line change @@ -27,12 +27,13 @@ import { fileExecutionEngine } from "../execute/engine.ts";
27
27
import { projectConfigFile , projectOutputDir } from "./project-shared.ts" ;
28
28
import { projectScratchPath } from "./project-scratch.ts" ;
29
29
import { parsePandocTitle } from "../core/pandoc/pandoc-partition.ts" ;
30
- import { readYaml } from "../core/yaml.ts" ;
30
+ import { readYamlFromString } from "../core/yaml.ts" ;
31
31
import { formatKeys } from "../config/metadata.ts" ;
32
32
import {
33
33
formatsPreferHtml ,
34
34
normalizeWebsiteFormat ,
35
35
} from "./types/website/website-config.ts" ;
36
+ import { kDefaultProjectFileContents } from "./types/project-default.ts" ;
36
37
37
38
export interface InputTargetIndex extends Metadata {
38
39
title ?: string ;
@@ -119,7 +120,11 @@ export function readInputTargetIndex(
119
120
const formats = Object . keys ( index . formats ) ;
120
121
const projConfigFile = projectConfigFile ( projectDir ) ;
121
122
if ( projConfigFile ) {
122
- const config = readYaml ( projConfigFile ) as Metadata ;
123
+ let contents = Deno . readTextFileSync ( projConfigFile ) ;
124
+ if ( contents . trim ( ) . length === 0 ) {
125
+ contents = kDefaultProjectFileContents ;
126
+ }
127
+ const config = readYamlFromString ( contents ) as Metadata ;
123
128
const projFormats = formatKeys ( config ) ;
124
129
if ( ld . isEqual ( formats , projFormats ) ) {
125
130
return index ;
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import { kJupyterEngine } from "../../execute/types.ts";
12
12
13
13
import { ProjectCreate , ProjectScaffoldFile , ProjectType } from "./types.ts" ;
14
14
15
+ export const kDefaultProjectFileContents = "{ project: { type: 'default' } }" ;
16
+
15
17
export const defaultProjectType : ProjectType = {
16
18
type : "default" ,
17
19
You can’t perform that action at this time.
0 commit comments