diff --git a/action.yml b/action.yml index e894dd3..1dc55cc 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ runs: main: 'dist/index.js' inputs: static_site_generator: - description: 'Optional static site generator to attempt to configure: "nuxt", "next", "gatsby", or "sveltekit"' + description: 'Optional static site generator to attempt to configure: "nuxt", "nuxt3", "next", "gatsby", or "sveltekit"' required: false generator_config_file: description: 'Optional file path to static site generator configuration file' diff --git a/src/blank-configurations/nuxt3.ts b/src/blank-configurations/nuxt3.ts new file mode 100644 index 0000000..a1162b1 --- /dev/null +++ b/src/blank-configurations/nuxt3.ts @@ -0,0 +1,3 @@ +// Default Pages configuration for Nuxt3 +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({}) diff --git a/src/fixtures/nuxt3/async.expected.ts b/src/fixtures/nuxt3/async.expected.ts new file mode 100644 index 0000000..c71491c --- /dev/null +++ b/src/fixtures/nuxt3/async.expected.ts @@ -0,0 +1,15 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +const getAllDynamicRoute = async function () { + const routes = await (async () => { + return ['/posts/hello-world', '/posts/hello-again'] + })() + return routes +} + +export default defineNuxtConfig({ + ssr: false, + app: { baseURL: '/docs/' }, + generate: { + routes: await getAllDynamicRoute() + }, +}) diff --git a/src/fixtures/nuxt3/async.ts b/src/fixtures/nuxt3/async.ts new file mode 100644 index 0000000..3faade7 --- /dev/null +++ b/src/fixtures/nuxt3/async.ts @@ -0,0 +1,13 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +const getAllDynamicRoute = async function () { + const routes = await (async () => { + return ['/posts/hello-world', '/posts/hello-again'] + })() + return routes +} + +export default defineNuxtConfig({ + generate: { + routes: await getAllDynamicRoute() + } +}) diff --git a/src/fixtures/nuxt3/default.expected.ts b/src/fixtures/nuxt3/default.expected.ts new file mode 100644 index 0000000..af26c3b --- /dev/null +++ b/src/fixtures/nuxt3/default.expected.ts @@ -0,0 +1,25 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + ssr: false, + app: { + baseURL: '/docs/' , + head: { + title: 'nuxt', + htmlAttrs: { + lang: 'en' + }, + meta: [ + { charset: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { key: 'description', name: 'description', content: '' }, + { name: 'format-detection', content: 'telephone=no' } + ], + link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }] + } + }, + css: [], + plugins: [], + components: true, + modules: [], + build: {} +}) diff --git a/src/fixtures/nuxt3/default.ts b/src/fixtures/nuxt3/default.ts new file mode 100644 index 0000000..896b5ed --- /dev/null +++ b/src/fixtures/nuxt3/default.ts @@ -0,0 +1,23 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + app: { + head: { + title: 'nuxt', + htmlAttrs: { + lang: 'en' + }, + meta: [ + { charset: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { key: 'description', name: 'description', content: '' }, + { name: 'format-detection', content: 'telephone=no' } + ], + link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }] + } + }, + css: [], + plugins: [], + components: true, + modules: [], + build: {} +}) diff --git a/src/set-pages-config.js b/src/set-pages-config.js index 2ec86a8..2e0f1bf 100644 --- a/src/set-pages-config.js +++ b/src/set-pages-config.js @@ -23,6 +23,19 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit target: 'static' } } + case 'nuxt3': + return { + configurationFile: generatorConfigFile || './nuxt.config.ts', + blankConfigurationFile: `${__dirname}/blank-configurations/nuxt3.ts`, + allowWrappingCall: true, + properties: { + // Configure a base path of the app + 'app.baseURL': path, + + // Set the target to static too + ssr: false + } + } case 'next': // Next does not want a trailing slash path = removeTrailingSlash(path) diff --git a/src/set-pages-config.test.js b/src/set-pages-config.test.js index dc3215e..383b40d 100644 --- a/src/set-pages-config.test.js +++ b/src/set-pages-config.test.js @@ -8,8 +8,8 @@ const { getTempFolder, compareFiles } = require('./test-helpers') // Get the temp folder const tempFolder = getTempFolder() -const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit'] -const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs'] +const SUPPORTED_GENERATORS = ['next', 'nuxt', 'nuxt3', 'gatsby', 'sveltekit'] +const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs', '.ts'] const IS_BLANK_CONFIG_FILE_REGEX = new RegExp( '^blank\\.(' + SUPPORTED_FILE_EXTENSIONS.map(ext => ext.slice(1)).join('|') + ')$' )