@valbuild/init 0.60.18 → 0.60.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main/dist/valbuild-init-main.cjs.dev.js +214 -20
- package/main/dist/valbuild-init-main.cjs.prod.js +214 -20
- package/main/dist/valbuild-init-main.esm.js +214 -20
- package/package.json +1 -1
- package/src/init.ts +196 -6
- package/src/logger.ts +3 -3
- package/src/templates.ts +135 -0
package/src/templates.ts
CHANGED
|
@@ -75,3 +75,138 @@ export default function Val() {
|
|
|
75
75
|
return <ValApp config={config} />;
|
|
76
76
|
}
|
|
77
77
|
`;
|
|
78
|
+
|
|
79
|
+
export const BASIC_EXAMPLE = (
|
|
80
|
+
moduleId: string,
|
|
81
|
+
configImportPath: string,
|
|
82
|
+
isJavaScript: boolean
|
|
83
|
+
) => `${isJavaScript ? "// @ts-check\n" : ""}/**
|
|
84
|
+
* Val example file - generated by @valbuild/init
|
|
85
|
+
**/
|
|
86
|
+
|
|
87
|
+
import {
|
|
88
|
+
s /* s = schema */,
|
|
89
|
+
c /* c = content */,${isJavaScript ? "" : "\n type t /* t = type */,"}
|
|
90
|
+
} from "${configImportPath}";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* This is the schema for the content. It defines the structure of the content and the types of each field.
|
|
94
|
+
*
|
|
95
|
+
* @docs https://val.build/docs/api-reference
|
|
96
|
+
*/
|
|
97
|
+
export const testSchema = s.object({
|
|
98
|
+
/**
|
|
99
|
+
* Basic text field
|
|
100
|
+
*/
|
|
101
|
+
text: s.string(),
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Optional fields are marked with \`.optional()\`
|
|
105
|
+
*/
|
|
106
|
+
optionals: s.string().optional(),
|
|
107
|
+
|
|
108
|
+
arrays: s.array(s.string()),
|
|
109
|
+
/**
|
|
110
|
+
* Records are objects where entries can be added. Useful for array-like structures where you would use a key to uniquely identify each entry.
|
|
111
|
+
*/
|
|
112
|
+
records: s.record(s.string()),
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Rich text can be used for multiline text, but also for more complex text editing capabilities like links, images, lists, etc.
|
|
116
|
+
*
|
|
117
|
+
* @docs https://val.build/docs/api-reference/schema-types/richtext
|
|
118
|
+
*
|
|
119
|
+
* @see ValRichText will render rich text
|
|
120
|
+
*/
|
|
121
|
+
richText: s.richtext({
|
|
122
|
+
// All features enabled:
|
|
123
|
+
bold: true,
|
|
124
|
+
italic: true,
|
|
125
|
+
lineThrough: true,
|
|
126
|
+
headings: ["h1", "h2", "h3", "h4", "h5", "h6"],
|
|
127
|
+
a: true,
|
|
128
|
+
img: true,
|
|
129
|
+
ul: true,
|
|
130
|
+
ol: true,
|
|
131
|
+
}),
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Images in Val are stored as files in the public folder.
|
|
135
|
+
*
|
|
136
|
+
* @docs https://val.build/docs/api-reference/schema-types/image
|
|
137
|
+
*
|
|
138
|
+
* When defining content use the following syntax:
|
|
139
|
+
* @example c.file('/public/myimage.png') // path to the image file, use the VS Code plugin or the \`@valbuild/cli validate --fix\` command to add metadata
|
|
140
|
+
*
|
|
141
|
+
* @see ValImage component to see how to render this in your app
|
|
142
|
+
*/
|
|
143
|
+
image: s.image().optional(),
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* String enums: presents as a dropdown in the UI
|
|
147
|
+
*/
|
|
148
|
+
stringEnum: s.union(s.literal("lit-0"), s.literal("lit-1")),
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Raw strings disables the stega (steganography) feature that automatically tags content when using the overlay.
|
|
152
|
+
* It is useful for slugs and other data that might be processed in code (parsed or matching for equality...)
|
|
153
|
+
*/
|
|
154
|
+
slug: s.string().raw(),
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Object unions: presents as a dropdown in the UI and the different fields
|
|
158
|
+
*
|
|
159
|
+
* @docs https://val.build/docs/api-reference/schema-types/union
|
|
160
|
+
*/
|
|
161
|
+
objectUnions: s.union(
|
|
162
|
+
"type",
|
|
163
|
+
s.object({
|
|
164
|
+
type: s.literal("page-type-1"),
|
|
165
|
+
value: s.number(),
|
|
166
|
+
}),
|
|
167
|
+
s.object({
|
|
168
|
+
type: s.literal("page-type-2"),
|
|
169
|
+
text: s.string(),
|
|
170
|
+
})
|
|
171
|
+
),
|
|
172
|
+
});
|
|
173
|
+
${
|
|
174
|
+
isJavaScript
|
|
175
|
+
? ""
|
|
176
|
+
: `
|
|
177
|
+
/**
|
|
178
|
+
* t.inferSchema returns the type of the content.
|
|
179
|
+
* This pattern is useful to type props of components that use this content (partially or whole)
|
|
180
|
+
*/
|
|
181
|
+
export type TestContent = t.inferSchema<typeof testSchema>;
|
|
182
|
+
`
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* This is the content definition. Add your content below.
|
|
187
|
+
*
|
|
188
|
+
* NOTE: the first argument, module id, must match the path of the file.
|
|
189
|
+
*/
|
|
190
|
+
export default c.define("${moduleId}", testSchema, {
|
|
191
|
+
text: "Basic text content",
|
|
192
|
+
optionals: null,
|
|
193
|
+
arrays: ["A string"],
|
|
194
|
+
records: {
|
|
195
|
+
"unique-key-1": "A string",
|
|
196
|
+
},
|
|
197
|
+
richText: c.richtext\`# Title 1
|
|
198
|
+
|
|
199
|
+
\${c.rt.link("Val docs", { href: "https://val.build/docs" })}
|
|
200
|
+
|
|
201
|
+
- List item 1
|
|
202
|
+
- List item 2
|
|
203
|
+
\`,
|
|
204
|
+
image: null,
|
|
205
|
+
slug: "test",
|
|
206
|
+
objectUnions: {
|
|
207
|
+
type: "page-type-2",
|
|
208
|
+
text: "String value",
|
|
209
|
+
},
|
|
210
|
+
stringEnum: "lit-1",
|
|
211
|
+
});
|
|
212
|
+
`;
|