-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathrender-createsite-plan.js
More file actions
102 lines (93 loc) · 2.42 KB
/
Copy pathrender-createsite-plan.js
File metadata and controls
102 lines (93 loc) · 2.42 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
#!/usr/bin/env node
/**
* render-createsite-plan.js — Renders the create-site implementation plan HTML.
*
* Usage (inline JSON):
* node render-createsite-plan.js --output <path> --data-inline '<json>'
*
* Usage (file-based):
* node render-createsite-plan.js --output <path> --data <json-file>
*
* Required keys in the data:
* SITE_NAME, PLAN_TITLE, FRAMEWORK, AESTHETIC, MOOD, SUMMARY,
* TYPOGRAPHY_DATA, PALETTE_DATA, MOTION_DATA, BACKGROUNDS_DATA,
* PAGES_DATA, COMPONENTS_DATA, ROUTES_DATA, REVIEW_DATA, DEPLOYMENT_DATA
*/
const path = require('path');
const fs = require('fs');
const { renderTemplate, parseArgs } = require('./lib/render-template');
const args = parseArgs(process.argv);
if (!args.output || (!args['data-inline'] && !args.data)) {
console.error(
'Usage: node render-createsite-plan.js --output <path> --data-inline \'<json>\'\n' +
' node render-createsite-plan.js --output <path> --data <json-file>'
);
process.exit(1);
}
const templatePath = path.join(
__dirname,
'..',
'skills',
'create-site',
'assets',
'create-site-plan.html'
);
const requiredKeys = [
'SITE_NAME',
'PLAN_TITLE',
'FRAMEWORK',
'AESTHETIC',
'MOOD',
'SUMMARY',
'TYPOGRAPHY_DATA',
'PALETTE_DATA',
'MOTION_DATA',
'BACKGROUNDS_DATA',
'PAGES_DATA',
'COMPONENTS_DATA',
'ROUTES_DATA',
'REVIEW_DATA',
'DEPLOYMENT_DATA',
];
function withDerivedTemplateData(dataObject) {
return {
...dataObject,
SUMMARY_DATA: { text: String(dataObject.SUMMARY ?? '') },
};
}
if (args['data-inline']) {
let dataObject;
try {
dataObject = JSON.parse(args['data-inline']);
} catch {
console.error('Error: --data-inline value is not valid JSON');
process.exit(1);
}
renderTemplate({
templatePath,
outputPath: path.resolve(args.output),
dataObject: withDerivedTemplateData(dataObject),
requiredKeys,
escapeStringValues: true,
});
} else {
const dataPath = path.resolve(args.data);
if (!fs.existsSync(dataPath)) {
console.error(`Data file not found: ${dataPath}`);
process.exit(1);
}
let dataObject;
try {
dataObject = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
} catch {
console.error('Error: --data file is not valid JSON');
process.exit(1);
}
renderTemplate({
templatePath,
outputPath: path.resolve(args.output),
dataObject: withDerivedTemplateData(dataObject),
requiredKeys,
escapeStringValues: true,
});
}