-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebsite.js
More file actions
102 lines (92 loc) · 2.86 KB
/
website.js
File metadata and controls
102 lines (92 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// builtin
import * as pathUtil from 'node:path'
// local
import { pwd } from './data.js'
import { parse } from './fs.js'
/**
* Get the Vercel project name from configuration
* @param {object} vercelConfig - Vercel configuration object
* @returns {string|null} The project name or null if not found
*/
export function getVercelName(vercelConfig) {
return vercelConfig.name || null
}
/**
* Parse alias string or array into an array of aliases
* @param {string|string[]} alias - Alias string (comma/space separated) or array
* @returns {string[]|null} Array of aliases or null if none provided
*/
export function parseVercelAliases(alias) {
if (alias) {
return Array.isArray(alias) ? alias : alias.split(/[,\s]+/)
}
return null
}
/**
* Get Vercel aliases from configuration
* @param {object} vercelConfig - Vercel configuration object
* @returns {string[]} Array of alias strings
*/
export function getVercelAliases(vercelConfig) {
return parseVercelAliases(vercelConfig.alias) || []
}
/**
* Read website configuration from files
* @param {object} state - Application state to update with website configuration
* @returns {Promise<void>} Promise that resolves when website config is read
*/
export async function readWebsite(state) {
const { packageData } = state
state.vercelConfig = Object.assign(
{},
packageData.now || {},
packageData.vercel || {},
(await parse(pathUtil.resolve(pwd, 'now.json'))) || {},
(await parse(pathUtil.resolve(pwd, 'vercel.json'))) || {},
)
}
/**
* Update website configuration based on user answers
* @param {object} state - Application state containing answers and vercel configuration
* @returns {Promise<void>} Promise that resolves when website config is updated
*/
export async function updateWebsite(state) {
const { answers, vercelConfig } = state
if (!vercelConfig) {
throw new Error('updateWebsite was called before readWebsite')
}
// add website deployment strategies
if (answers.vercelWebsite) {
// trim version 1 fields
if (vercelConfig.version !== 2) {
delete vercelConfig.type
delete vercelConfig.public
delete vercelConfig.files
delete vercelConfig.static
}
// add the versions we know
vercelConfig.version = 2
vercelConfig.name = answers.vercelName
vercelConfig.alias = parseVercelAliases(answers.vercelAliases)
// next.js builder
if (answers.website.includes('next')) {
// remove old routes as they are no longer needed due to public directory now existing
if (vercelConfig.routes) {
vercelConfig.routes = vercelConfig.routes.filter(
(route) =>
['/favicon.ico', '/robots.txt'].includes(route.src) === false,
)
}
// delete old format
delete vercelConfig.build
}
// static builder
if (answers.staticWebsite) {
if (!vercelConfig.builds) {
vercelConfig.builds = [
{ src: `${answers.staticDirectory}/**`, use: '@vercel/static' },
]
}
}
}
}