-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e1f4f6
commit 14a4323
Showing
11 changed files
with
170 additions
and
7 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
19 changes: 19 additions & 0 deletions
19
packages/qwik-nx/src/generators/setup-ssg/files/adapters/static/vite.config.ts__template__
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,19 @@ | ||
import { staticAdapter } from '@builder.io/qwik-city/adapters/static/vite'; | ||
import { extendConfig } from '@builder.io/qwik-city/vite'; | ||
import baseConfig from '../../vite.config'; | ||
|
||
export default extendConfig(baseConfig, () => { | ||
return { | ||
build: { | ||
ssr: true, | ||
rollupOptions: { | ||
input: ['@qwik-city-plan'], | ||
}, | ||
}, | ||
plugins: [ | ||
staticAdapter({ | ||
origin: 'https://yoursite.qwik.dev', | ||
}), | ||
], | ||
}; | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/qwik-nx/src/generators/setup-ssg/generator.spec.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,20 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { Tree, readProjectConfiguration } from '@nrwl/devkit'; | ||
|
||
import generator from './generator'; | ||
import { SetupSsgGeneratorSchema } from './schema'; | ||
|
||
describe('setup-ssg generator', () => { | ||
let appTree: Tree; | ||
const options: SetupSsgGeneratorSchema = { name: 'test' }; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should run successfully', async () => { | ||
await generator(appTree, options); | ||
const config = readProjectConfiguration(appTree, 'test'); | ||
expect(config).toBeDefined(); | ||
}); | ||
}); |
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,68 @@ | ||
import { | ||
formatFiles, | ||
joinPathFragments, | ||
logger, | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { addSsgFiles } from './lib/add-ssg-files'; | ||
import { NormalizedSchema, SetupSsgGeneratorSchema } from './schema'; | ||
|
||
function normalizeOptions( | ||
tree: Tree, | ||
options: SetupSsgGeneratorSchema | ||
): NormalizedSchema { | ||
const project = readProjectConfiguration(tree, options.project); | ||
const projectRoot = project.root; | ||
|
||
return { | ||
...options, | ||
projectRoot, | ||
}; | ||
} | ||
|
||
export async function setupSsgGenerator( | ||
tree: Tree, | ||
options: SetupSsgGeneratorSchema | ||
) { | ||
const normalizedOptions = normalizeOptions(tree, options); | ||
|
||
const { projectRoot } = normalizedOptions; | ||
|
||
const ssgConfigPath = joinPathFragments( | ||
projectRoot, | ||
'adapters', | ||
'static', | ||
'vite.config.ts' | ||
); | ||
|
||
if (tree.exists(ssgConfigPath)) { | ||
logger.info( | ||
`Skipping setup since there is an existing static adapter configuration. For more configuration, see https://qwik.builder.io/qwikcity/guides/static-site-generation/.` | ||
); | ||
return; | ||
} | ||
|
||
const projectConfig = readProjectConfiguration(tree, options.project); | ||
|
||
addSsgFiles(tree, normalizedOptions); | ||
|
||
updateProjectConfiguration(tree, options.project, { | ||
...projectConfig, | ||
targets: { | ||
...projectConfig.targets, | ||
'build-server': { | ||
executor: '@nrwl/vite:build', | ||
options: { | ||
outputPath: 'dist/docs', | ||
configFile: ssgConfigPath, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default setupSsgGenerator; |
17 changes: 17 additions & 0 deletions
17
packages/qwik-nx/src/generators/setup-ssg/lib/add-ssg-files.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 { generateFiles, offsetFromRoot, Tree } from '@nrwl/devkit'; | ||
import * as path from 'path'; | ||
import { NormalizedSchema } from '../schema'; | ||
|
||
export function addSsgFiles(tree: Tree, options: NormalizedSchema) { | ||
const templateOptions = { | ||
...options, | ||
offsetFromRoot: offsetFromRoot(options.projectRoot), | ||
template: '', | ||
}; | ||
generateFiles( | ||
tree, | ||
path.join(__dirname, '..', 'files'), | ||
options.projectRoot, | ||
templateOptions | ||
); | ||
} |
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,7 @@ | ||
export interface SetupSsgGeneratorSchema { | ||
project: string; | ||
} | ||
|
||
interface NormalizedSchema extends SetupSsgGeneratorSchema { | ||
projectRoot: string; | ||
} |
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,22 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"$id": "SetupSsg", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "The name of the project to add the SSG setup for.", | ||
"alias": "p", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-dropdown": "projects", | ||
"x-prompt": "What project would you like to add the SSG setup?" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["project"] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.