Skip to content

Commit

Permalink
Merge branch 'master' into website
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvishnusankar committed Jul 1, 2023
2 parents b8cfd99 + dd3a619 commit 8cb1b54
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 24 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
550 changes: 550 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-version.cjs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions .yarn/versions/506b1fcd.yml
@@ -0,0 +1,12 @@
undecided:
- next-sitemap-workspace
- with-next-sitemap-amp
- with-next-app-dir
- basic
- commonjs
- custom-config-file
- with-custom-overrides
- with-custom-robots-txt-transformer
- with-no-index-sitemaps
- static-export
- with-next-sitemap-i18n
18 changes: 11 additions & 7 deletions .yarnrc.yml
Expand Up @@ -6,16 +6,15 @@ nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
spec: '@yarnpkg/plugin-compat'
spec: "@yarnpkg/plugin-compat"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"

supportedArchitectures:
os:
- current
- darwin
- linux
- win32
cpu:
- current
- x64
Expand All @@ -24,3 +23,8 @@ supportedArchitectures:
- current
- glibc
- musl
os:
- current
- darwin
- linux
- win32
2 changes: 1 addition & 1 deletion azure-pipeline.yml
Expand Up @@ -34,7 +34,7 @@ steps:
displayName: 'Set Version'
inputs:
targetType: 'inline'
script: 'npm version --no-git-tag-version $BUILD_BUILDNUMBER --ws'
script: yarn workspaces foreach version $BUILD_BUILDNUMBER
# failOnStderr: true

# Install
Expand Down
12 changes: 6 additions & 6 deletions packages/next-sitemap/src/cli.ts
Expand Up @@ -13,16 +13,16 @@ export class CLI {
*/
async main() {
// Load config from `next-sitemap.config.js` along with runtimePaths info
const { config, runtimePaths } = await new ConfigParser().loadConfig()
const configParser = new ConfigParser()
const { config, runtimePaths } = await configParser.loadConfig()

// Load next.js manifest
const manifest = await new ManifestParser().loadManifest(
config,
runtimePaths
)
const manifestParser = new ManifestParser(config, runtimePaths)
const manifest = await manifestParser.loadManifest()

// Generate url set
const urlSet = await new UrlSetBuilder(config, manifest).createUrlSet()
const urlSetBuilder = new UrlSetBuilder(config, manifest)
const urlSet = await urlSetBuilder.createUrlSet()

// Split sitemap into multiple files
const chunks = toChunks(urlSet, config.sitemapSize!)
Expand Down
15 changes: 15 additions & 0 deletions packages/next-sitemap/src/parsers/config-parser.ts
Expand Up @@ -76,6 +76,18 @@ export class ConfigParser {
return withDefaultConfig(baseConfig.default)
}

/**
* Basic validation
* @param config
*/
async validateConfig(config: IConfig) {
if (!config?.siteUrl) {
throw new Error('Validation error: Missing siteUrl')
}

return config
}

/**
* Load full config
* @returns
Expand All @@ -90,6 +102,9 @@ export class ConfigParser {
// Update base config with runtime config
const config = await this.withRuntimeConfig(baseConfig, runtimePaths)

// Validate config
await this.validateConfig(config)

// Return full result
return {
config,
Expand Down
24 changes: 14 additions & 10 deletions packages/next-sitemap/src/parsers/manifest-parser.ts
Expand Up @@ -12,6 +12,13 @@ import { loadJSON } from '../utils/file.js'
import fg from 'fast-glob'

export class ManifestParser {
config: IConfig
runtimePaths: IRuntimePaths

constructor(config: IConfig, runtimePaths: IRuntimePaths) {
this.config = config
this.runtimePaths = runtimePaths
}
/**
* Return paths of html files if config.output = "export"
* @param exportFolder
Expand All @@ -36,34 +43,31 @@ export class ManifestParser {
)
}

async loadManifest(
config: IConfig,
runtimePaths: IRuntimePaths
): Promise<INextManifest> {
async loadManifest(): Promise<INextManifest> {
// Load build manifest
const buildManifest = await loadJSON<IBuildManifest>(
runtimePaths.BUILD_MANIFEST
this.runtimePaths.BUILD_MANIFEST
)!

// Throw error if no build manifest exist
if (config?.output !== 'export' && !buildManifest) {
if (this.config?.output !== 'export' && !buildManifest) {
throw Logger.noBuildManifest()
}

// Load pre-render manifest
const preRenderManifest = await loadJSON<IPreRenderManifest>(
runtimePaths.PRERENDER_MANIFEST
this.runtimePaths.PRERENDER_MANIFEST
)

// Load routes manifest
const routesManifest = await loadJSON<IRoutesManifest>(
runtimePaths.ROUTES_MANIFEST
this.runtimePaths.ROUTES_MANIFEST
)

// Get static export path when output is set as "export"
const staticExportPages = await this.getStaticExportPages(
config,
runtimePaths.STATIC_EXPORT_ROOT
this.config,
this.runtimePaths.STATIC_EXPORT_ROOT
)

return {
Expand Down

0 comments on commit 8cb1b54

Please sign in to comment.