-
Notifications
You must be signed in to change notification settings - Fork 36
/
generate.js
executable file
·68 lines (64 loc) · 1.94 KB
/
generate.js
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
#!/usr/bin/env node
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const path = require('path')
const fs = require('fs')
const mkdirp = require('mkdirp')
const inquirer = require('inquirer')
inquirer
.prompt([
{
type: 'confirm',
name: 'useBudget',
message: 'Would you like to set a performance budget?',
default: true,
},
{
type: 'number',
name: 'budget',
message:
'What would you like the maximum javascript on first load to be (in kb)?',
default: 350,
when: (answers) => answers.useBudget,
},
{
type: 'number',
name: 'redIndicatorPercentage',
message:
'If you exceed this percentage of the budget or filesize, it will be highlighted in red',
default: 20,
},
{
type: 'number',
name: 'minimumChangeThreshold',
message: `If a page's size change is below this threshold (in bytes), it will be considered unchanged`,
default: 0,
},
])
.then((answers) => {
// write the config values to package.json
const packageJsonPath = path.join(process.cwd(), 'package.json')
const packageJsonContent = require(packageJsonPath)
packageJsonContent.nextBundleAnalysis = {
budget: answers.budget * 1024,
budgetPercentIncreaseRed: answers.redIndicatorPercentage,
minimumChangeThreshold: answers.minimumChangeThreshold,
showDetails: true, // add a default "showDetails" argument
}
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJsonContent, null, 2)
)
// mkdir -p the .workflows directory
const workflowsPath = path.join(process.cwd(), '.github/workflows')
mkdirp.sync(workflowsPath)
// copy the template to it
const templatePath = path.join(__dirname, 'template.yml')
const destinationPath = path.join(
workflowsPath,
'nextjs_bundle_analysis.yml'
)
fs.copyFileSync(templatePath, destinationPath)
})