-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jerboa88/2-rewrite-in-typescript
2 rewrite in typescript
- Loading branch information
Showing
18 changed files
with
10,822 additions
and
2,102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports.biome": "explicit" | ||
} | ||
} |
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,33 +1,2 @@ | ||
const { setReporter, info } = require('./src/logger'); | ||
const { | ||
setGatsbyCreatePageFunction, | ||
setDefaultOptions, | ||
} = require('./src/config'); | ||
const { generateImages } = require('./src/generator'); | ||
const { setJoi, getPluginOptionsSchema } = require('./src/validator'); | ||
const { prettify } = require('./src/utilities'); | ||
|
||
// Save the reporter and createPage function for later use | ||
exports.onPluginInit = async ({ reporter, actions: { createPage } }) => { | ||
setReporter(reporter); | ||
setGatsbyCreatePageFunction(createPage); | ||
}; | ||
|
||
// Save Joi for later and return the schema for plugin options validation by Gatsby | ||
exports.pluginOptionsSchema = ({ Joi }) => { | ||
setJoi(Joi); | ||
|
||
return getPluginOptionsSchema(); | ||
}; | ||
|
||
// Get plugin options from gatsby-config.js and set default options | ||
exports.onPreBootstrap = async (_, pluginOptions) => { | ||
const defaultOptions = setDefaultOptions(pluginOptions); | ||
|
||
info(`Default options set to:\n${prettify(defaultOptions)}`); | ||
}; | ||
|
||
// Generate images after pages have been built | ||
exports.onPostBuild = async () => { | ||
await generateImages(); | ||
}; | ||
// Proxy to the dist/gatsby-node.js file | ||
module.exports = require('./dist/gatsby-node'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Actions } from 'gatsby'; | ||
import type { DefaultOptions, JobOptions } from './types'; | ||
import { validateDefaultOptions } from './validator'; | ||
|
||
const jobQueue: JobOptions[] = []; | ||
|
||
let gatsbyCreatePageFunction: Actions['createPage']; | ||
let defaultOptions: DefaultOptions = { | ||
verbose: false, | ||
component: undefined, | ||
context: {}, | ||
size: { | ||
width: 1200, | ||
height: 630, | ||
}, | ||
type: 'png', | ||
quality: undefined, | ||
optimizeForSpeed: false, | ||
}; | ||
|
||
export function getDefaultOptions() { | ||
return defaultOptions; | ||
} | ||
|
||
export function setDefaultOptions( | ||
newDefaultOptions: Partial<DefaultOptions>, | ||
): DefaultOptions { | ||
defaultOptions = validateDefaultOptions(newDefaultOptions, defaultOptions); | ||
|
||
return defaultOptions; | ||
} | ||
|
||
export function addJob(job: JobOptions) { | ||
jobQueue.push(job); | ||
} | ||
|
||
export function getAllJobs() { | ||
return jobQueue; | ||
} | ||
|
||
// Store the Gatsby createPage function to use later | ||
export function setGatsbyCreatePageFunction( | ||
newGatsbyCreatePageFunction: Actions['createPage'], | ||
) { | ||
gatsbyCreatePageFunction = newGatsbyCreatePageFunction; | ||
} | ||
|
||
// Call the Gatsby createPage function | ||
export function createPage(...args: Parameters<Actions['createPage']>) { | ||
return gatsbyCreatePageFunction(...args); | ||
} |
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,43 @@ | ||
import type { GatsbyNode } from 'gatsby'; | ||
import { setDefaultOptions, setGatsbyCreatePageFunction } from './config'; | ||
import { generateImages } from './generator'; | ||
import { info, setReporter } from './logger'; | ||
import type { DefaultOptions } from './types'; | ||
import { prettify } from './utilities'; | ||
import { getPluginOptionsSchema, setJoi } from './validator'; | ||
|
||
// Save the reporter and createPage function for later use | ||
export const onPluginInit: GatsbyNode['onPluginInit'] = async ({ | ||
reporter, | ||
actions: { createPage }, | ||
}) => { | ||
setReporter(reporter); | ||
setGatsbyCreatePageFunction(createPage); | ||
}; | ||
|
||
// Save Joi for later and return the schema for plugin options validation by Gatsby | ||
export const pluginOptionsSchema: GatsbyNode['pluginOptionsSchema'] = ({ | ||
Joi, | ||
}) => { | ||
setJoi(Joi); | ||
|
||
return getPluginOptionsSchema(); | ||
}; | ||
|
||
// Get plugin options from gatsby-config.js and set default options | ||
export const onPreBootstrap: GatsbyNode['onPreBootstrap'] = async ( | ||
_, | ||
pluginOptions, | ||
) => { | ||
// PluginOptions should be a superset of DefaultOptions | ||
const defaultOptions = setDefaultOptions( | ||
pluginOptions as unknown as Partial<DefaultOptions>, | ||
); | ||
|
||
info(`Default options set to:\n${prettify(defaultOptions)}`); | ||
}; | ||
|
||
// Generate images after pages have been built | ||
export const onPostBuild: GatsbyNode['onPostBuild'] = async () => { | ||
await generateImages(); | ||
}; |
Oops, something went wrong.