-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/implement magidoc.js for config and magidoc.config.js for sta…
…rters (#11) * bump deps * bump deps * fix typing * delete logo * fix header * fix graphql being external * patch * use magidoc.js instead of yaml * add magidoc config to starter and read from magidoc config to get allowed values * fix order of tasks * bump versions
- Loading branch information
1 parent
bb89bee
commit 9620aac
Showing
26 changed files
with
236 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
docs/ | ||
magidoc*.yml | ||
/magidoc*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import yaml from 'js-yaml' | ||
import { FileConfiguration, ZFileConfiguration } from './types' | ||
|
||
export function parseConfiguration(content: string): FileConfiguration { | ||
const response = yaml.load(content) | ||
const result = ZFileConfiguration.safeParse(response) | ||
|
||
export function parseConfiguration(content: unknown): FileConfiguration { | ||
const result = ZFileConfiguration.safeParse(content) | ||
if (result.success) { | ||
return result.data | ||
} | ||
|
||
const issues = result.error.issues | ||
const formattedIssues = issues.map( | ||
(issue) => | ||
` - ${issue.message} at path ${issue.path.reduce( | ||
(previous: string, current: string | number) => { | ||
if (typeof current === 'number') return previous + `[${current}]` | ||
return previous + String(current) | ||
}, | ||
'', | ||
)}`, | ||
) | ||
const formattedIssues = issues.map((issue) => { | ||
const path = formatErrorPath(issue.path) | ||
switch (issue.code) { | ||
case 'invalid_type': | ||
return ` - ${issue.message} '${issue.expected}' but received '${issue.received}' at path ${path}` | ||
default: | ||
return ` - ${issue.message} at path ${path}` | ||
} | ||
}) | ||
|
||
throw new Error( | ||
`${ | ||
issues.length | ||
} issues were found with the YAML configuration provided:\n${formattedIssues.join( | ||
} issues were found with the Magidoc configuration provided:\n${formattedIssues.join( | ||
'\n', | ||
)}}`, | ||
)}`, | ||
) | ||
} | ||
|
||
function formatErrorPath(path: (string | number)[]): string { | ||
return path.reduce((previous: string, current: string | number) => { | ||
if (typeof current === 'number') return previous + `[${current}]` | ||
if (previous === '') return String(current) | ||
return `${previous}.${String(current)}` | ||
}, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
import { newTask, Task } from '../task' | ||
import type { GenerationConfig } from '../config' | ||
import { newTask, Task, TaskContext } from '../task' | ||
|
||
export function buildTemplateTask(): Task { | ||
export function buildTemplateTask(config: GenerationConfig): Task { | ||
return newTask({ | ||
title: `Build template`, | ||
executor: async (ctx) => { | ||
await ctx.npmRunner.buildProject({ | ||
cwd: ctx.tmpDirectory.path, | ||
env: {}, // TODO | ||
env: buildEnv(ctx, config), | ||
}) | ||
}, | ||
}) | ||
} | ||
|
||
function buildEnv( | ||
ctx: TaskContext, | ||
config: GenerationConfig, | ||
): Record<string, string> { | ||
const newRecord: Record<string, string> = {} | ||
const nonExistingOptions: string[] = [] | ||
Object.keys(config.options).forEach((key) => { | ||
const variable = ctx.templateConfiguration.supportedOptions.find((option) => | ||
option.names.includes(key), | ||
) | ||
if (!variable) { | ||
nonExistingOptions.push(key) | ||
return | ||
} | ||
|
||
newRecord[variable.vite.key] = String(config.options[key]) | ||
}) | ||
|
||
if (nonExistingOptions.length > 0) { | ||
throw new Error( | ||
`Options ${nonExistingOptions.toString()} are not supported by template ${ | ||
config.template | ||
}... Supported option names are ${ | ||
(ctx.templateConfiguration.supportedOptions.flatMap( | ||
(value) => value.names, | ||
), | ||
toString()) | ||
}`, | ||
) | ||
} | ||
return newRecord | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/cli/src/commands/generate/tasks/loadGraphqlSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { GenerationConfig } from '../config' | ||
import { fetchSchema } from '@magidoc/rollup-plugin-fetch-gql-schema' | ||
import { newTask, Task } from '../task' | ||
|
||
export function loadGraphQLSchema(config: GenerationConfig): Task { | ||
return newTask({ | ||
title: `Load GraphQL Schema`, | ||
executor: async (ctx) => { | ||
await fetchSchema({ | ||
url: config.fetchConfig.url, | ||
method: config.fetchConfig.method, | ||
headers: config.fetchConfig.headers, | ||
target: ctx.templateConfiguration.schemaTargetLocation, | ||
}) | ||
}, | ||
}) | ||
} |
Oops, something went wrong.