@caiquecamargo/vite-plugin-netlify-cms 0.0.15 → 0.0.17
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/dist/index.d.ts +74 -74
- package/dist/index.js +111 -78
- package/dist/index.js.map +1 -1
- package/package.json +29 -27
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
type Widgets =
|
|
4
|
-
interface
|
|
3
|
+
type Widgets = 'boolean' | 'code' | 'color' | 'datetime' | 'hidden' | 'file' | 'image' | 'list' | 'map' | 'number' | 'object' | 'relation' | 'select' | 'string' | 'text' | 'markdown';
|
|
4
|
+
interface Widget {
|
|
5
5
|
name: string;
|
|
6
6
|
label?: string;
|
|
7
7
|
widget: Widgets;
|
|
@@ -9,37 +9,37 @@ interface BaseCollectionField {
|
|
|
9
9
|
pattern?: string[];
|
|
10
10
|
comment?: string;
|
|
11
11
|
}
|
|
12
|
-
interface BooleanWidget extends
|
|
13
|
-
widget:
|
|
12
|
+
interface BooleanWidget extends Widget {
|
|
13
|
+
widget: 'boolean';
|
|
14
14
|
default?: boolean;
|
|
15
15
|
}
|
|
16
|
-
interface CodeWidget extends
|
|
17
|
-
widget:
|
|
16
|
+
interface CodeWidget extends Widget {
|
|
17
|
+
widget: 'code';
|
|
18
18
|
default_language?: string;
|
|
19
19
|
allow_language_selection?: boolean;
|
|
20
20
|
keys?: string;
|
|
21
21
|
output_code_only?: boolean;
|
|
22
22
|
}
|
|
23
|
-
interface ColorWidget extends
|
|
24
|
-
widget:
|
|
23
|
+
interface ColorWidget extends Widget {
|
|
24
|
+
widget: 'color';
|
|
25
25
|
default?: string;
|
|
26
26
|
allowInput?: boolean;
|
|
27
27
|
enableAlpha?: boolean;
|
|
28
28
|
}
|
|
29
|
-
interface DateTimeWidget extends
|
|
30
|
-
widget:
|
|
29
|
+
interface DateTimeWidget extends Widget {
|
|
30
|
+
widget: 'datetime';
|
|
31
31
|
default?: string;
|
|
32
32
|
format?: string;
|
|
33
33
|
date_format?: string | boolean;
|
|
34
34
|
time_format?: string | boolean;
|
|
35
35
|
picker_utc?: boolean;
|
|
36
36
|
}
|
|
37
|
-
interface HiddenWidget extends
|
|
38
|
-
widget:
|
|
37
|
+
interface HiddenWidget extends Widget {
|
|
38
|
+
widget: 'hidden';
|
|
39
39
|
default?: any;
|
|
40
40
|
}
|
|
41
|
-
interface FileWidget extends
|
|
42
|
-
widget:
|
|
41
|
+
interface FileWidget extends Widget {
|
|
42
|
+
widget: 'file';
|
|
43
43
|
default?: string;
|
|
44
44
|
media_library?: Record<string, unknown>;
|
|
45
45
|
allow_multiple?: boolean;
|
|
@@ -47,8 +47,8 @@ interface FileWidget extends BaseCollectionField {
|
|
|
47
47
|
media_folder?: string;
|
|
48
48
|
choose_url?: boolean;
|
|
49
49
|
}
|
|
50
|
-
interface ImageWidget extends
|
|
51
|
-
widget:
|
|
50
|
+
interface ImageWidget extends Widget {
|
|
51
|
+
widget: 'image';
|
|
52
52
|
default?: string;
|
|
53
53
|
media_library?: Record<string, unknown>;
|
|
54
54
|
allow_multiple?: boolean;
|
|
@@ -56,8 +56,8 @@ interface ImageWidget extends BaseCollectionField {
|
|
|
56
56
|
media_folder?: string;
|
|
57
57
|
choose_url?: boolean;
|
|
58
58
|
}
|
|
59
|
-
interface ListWidget extends
|
|
60
|
-
widget:
|
|
59
|
+
interface ListWidget extends Widget {
|
|
60
|
+
widget: 'list';
|
|
61
61
|
default?: string[] | CollectionField[];
|
|
62
62
|
allow_add?: boolean;
|
|
63
63
|
collapsed?: boolean;
|
|
@@ -71,29 +71,29 @@ interface ListWidget extends BaseCollectionField {
|
|
|
71
71
|
min?: number;
|
|
72
72
|
add_to_top?: boolean;
|
|
73
73
|
}
|
|
74
|
-
interface MapWidget extends
|
|
75
|
-
widget:
|
|
74
|
+
interface MapWidget extends Widget {
|
|
75
|
+
widget: 'map';
|
|
76
76
|
default?: string;
|
|
77
77
|
decimals?: number;
|
|
78
|
-
type?:
|
|
78
|
+
type?: 'Point' | 'LineString' | 'Polygon';
|
|
79
79
|
}
|
|
80
|
-
interface NumberWidget extends
|
|
81
|
-
widget:
|
|
80
|
+
interface NumberWidget extends Widget {
|
|
81
|
+
widget: 'number';
|
|
82
82
|
default?: string | number;
|
|
83
|
-
value_type?:
|
|
83
|
+
value_type?: 'int' | 'float';
|
|
84
84
|
min?: number;
|
|
85
85
|
max?: number;
|
|
86
86
|
step?: number;
|
|
87
87
|
}
|
|
88
|
-
interface ObjectWidget extends
|
|
89
|
-
widget:
|
|
88
|
+
interface ObjectWidget extends Widget {
|
|
89
|
+
widget: 'object';
|
|
90
90
|
default?: CollectionField[];
|
|
91
91
|
collapsed?: boolean;
|
|
92
92
|
summary?: string;
|
|
93
93
|
fields: CollectionField[];
|
|
94
94
|
}
|
|
95
|
-
interface RelationWidget extends
|
|
96
|
-
widget:
|
|
95
|
+
interface RelationWidget extends Widget {
|
|
96
|
+
widget: 'relation';
|
|
97
97
|
default?: any;
|
|
98
98
|
collection: string;
|
|
99
99
|
value_field: string;
|
|
@@ -105,8 +105,8 @@ interface RelationWidget extends BaseCollectionField {
|
|
|
105
105
|
max?: number;
|
|
106
106
|
options_length?: number;
|
|
107
107
|
}
|
|
108
|
-
interface SelectWidget extends
|
|
109
|
-
widget:
|
|
108
|
+
interface SelectWidget extends Widget {
|
|
109
|
+
widget: 'select';
|
|
110
110
|
default?: string | {
|
|
111
111
|
label: string;
|
|
112
112
|
value: string;
|
|
@@ -119,21 +119,21 @@ interface SelectWidget extends BaseCollectionField {
|
|
|
119
119
|
min?: number;
|
|
120
120
|
max?: number;
|
|
121
121
|
}
|
|
122
|
-
interface StringWidget extends
|
|
123
|
-
widget:
|
|
122
|
+
interface StringWidget extends Widget {
|
|
123
|
+
widget: 'string';
|
|
124
124
|
default?: string;
|
|
125
125
|
}
|
|
126
|
-
interface TextWidget extends
|
|
127
|
-
widget:
|
|
126
|
+
interface TextWidget extends Widget {
|
|
127
|
+
widget: 'text';
|
|
128
128
|
default?: string;
|
|
129
129
|
}
|
|
130
|
-
type MarkdownButtons =
|
|
131
|
-
interface MarkdownWidget extends
|
|
132
|
-
widget:
|
|
130
|
+
type MarkdownButtons = 'bold' | 'italic' | 'code' | 'link' | 'heading-one' | 'heading-two' | 'heading-three' | 'heading-four' | 'heading-five' | 'heading-six' | 'quote' | 'bulleted-list' | 'numbered-list';
|
|
131
|
+
interface MarkdownWidget extends Widget {
|
|
132
|
+
widget: 'markdown';
|
|
133
133
|
default?: string;
|
|
134
134
|
buttons?: MarkdownButtons[];
|
|
135
|
-
editor_components?: (
|
|
136
|
-
modes?: (
|
|
135
|
+
editor_components?: ('image' | 'code-block')[];
|
|
136
|
+
modes?: ('raw' | 'rich_text')[];
|
|
137
137
|
sanitize_preview?: boolean;
|
|
138
138
|
}
|
|
139
139
|
type CollectionField = BooleanWidget | CodeWidget | ColorWidget | DateTimeWidget | HiddenWidget | FileWidget | ImageWidget | ListWidget | MapWidget | NumberWidget | ObjectWidget | RelationWidget | SelectWidget | StringWidget | TextWidget | MarkdownWidget;
|
|
@@ -186,11 +186,11 @@ interface Collection {
|
|
|
186
186
|
/**
|
|
187
187
|
* These settings determine how collection files are parsed and saved.
|
|
188
188
|
*/
|
|
189
|
-
extension?:
|
|
189
|
+
extension?: 'yml' | 'yaml' | 'toml' | 'json' | 'md' | 'markdown' | 'html';
|
|
190
190
|
/**
|
|
191
191
|
* These settings determine how collection files are parsed and saved.
|
|
192
192
|
*/
|
|
193
|
-
format?:
|
|
193
|
+
format?: 'yml' | 'yaml' | 'toml' | 'json' | 'frontmatter' | 'yaml-frontmatter' | 'toml-frontmatter' | 'json-frontmatter';
|
|
194
194
|
frontmatter_delimiter?: string;
|
|
195
195
|
/**
|
|
196
196
|
* specifies a template for generating new filenames
|
|
@@ -258,9 +258,9 @@ interface FolderCollection extends Collection {
|
|
|
258
258
|
*/
|
|
259
259
|
create?: boolean;
|
|
260
260
|
}
|
|
261
|
-
type Locales =
|
|
261
|
+
type Locales = 'bg' | 'ca' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fa' | 'fr' | 'he' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nb_no' | 'nl' | 'nn_no' | 'pl' | 'pt' | 'ro' | 'ru' | 'sl' | 'sv' | 'th' | 'tr' | 'uk' | 'vi' | 'zh-Hans' | 'zh-Hant';
|
|
262
262
|
interface CloudinaryMediaLibrary {
|
|
263
|
-
name:
|
|
263
|
+
name: 'cloudinary';
|
|
264
264
|
config: {
|
|
265
265
|
[key: string]: unknown;
|
|
266
266
|
cloud_name: string;
|
|
@@ -292,7 +292,7 @@ interface CloudinaryMediaLibrary {
|
|
|
292
292
|
};
|
|
293
293
|
}
|
|
294
294
|
interface UploadcareMediaLibrary {
|
|
295
|
-
name:
|
|
295
|
+
name: 'uploadcare';
|
|
296
296
|
/** @see https://uploadcare.com/docs/uploads/file-uploader-options/ */
|
|
297
297
|
config: {
|
|
298
298
|
[key: string]: unknown;
|
|
@@ -300,7 +300,7 @@ interface UploadcareMediaLibrary {
|
|
|
300
300
|
* specify whether to add a filename to the end of the url
|
|
301
301
|
*
|
|
302
302
|
* @example http://ucarecdn.com/:uuid/filename.png
|
|
303
|
-
|
|
303
|
+
*/
|
|
304
304
|
autoFilename?: boolean;
|
|
305
305
|
/**
|
|
306
306
|
* specify a string added at the end of the url.
|
|
@@ -320,11 +320,11 @@ interface UploadcareMediaLibrary {
|
|
|
320
320
|
previewStep?: boolean;
|
|
321
321
|
imageShrink?: string;
|
|
322
322
|
inputAcceptTypes?: string;
|
|
323
|
-
locale?: Locales |
|
|
323
|
+
locale?: Locales | string;
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
type MediaLibrary = CloudinaryMediaLibrary | UploadcareMediaLibrary;
|
|
327
|
-
|
|
327
|
+
interface NetlifyCMSConfig {
|
|
328
328
|
/**
|
|
329
329
|
* Enable the local backend for testing
|
|
330
330
|
*
|
|
@@ -337,7 +337,7 @@ type NetlifyCMSConfig = {
|
|
|
337
337
|
/**
|
|
338
338
|
* The name of the backend to use.
|
|
339
339
|
*/
|
|
340
|
-
name:
|
|
340
|
+
name: 'git-gateway' | 'github' | 'gitlab' | 'bitbucket' | 'azure' | 'gitea';
|
|
341
341
|
/**
|
|
342
342
|
* [org-or-username]/[repo-name] Required for github, gitlab,
|
|
343
343
|
* bitbucket, azure, gitea and ignored by git-gateway.
|
|
@@ -402,7 +402,7 @@ type NetlifyCMSConfig = {
|
|
|
402
402
|
*
|
|
403
403
|
* @see https://decapcms.org/docs/configuration-options/#publish-mode
|
|
404
404
|
*/
|
|
405
|
-
publish_mode?:
|
|
405
|
+
publish_mode?: 'editorial_workflow';
|
|
406
406
|
/**
|
|
407
407
|
* The media_folder option specifies the folder path where
|
|
408
408
|
* uploaded files should be saved, relative to the base of the repo.
|
|
@@ -439,7 +439,7 @@ type NetlifyCMSConfig = {
|
|
|
439
439
|
*
|
|
440
440
|
* @default en
|
|
441
441
|
*/
|
|
442
|
-
locale?: Locales |
|
|
442
|
+
locale?: Locales | string;
|
|
443
443
|
show_preview_links?: boolean;
|
|
444
444
|
/**
|
|
445
445
|
* The search functionally requires loading all collection(s) entries,
|
|
@@ -450,34 +450,34 @@ type NetlifyCMSConfig = {
|
|
|
450
450
|
*/
|
|
451
451
|
search?: boolean;
|
|
452
452
|
slug?: {
|
|
453
|
-
encoding?:
|
|
453
|
+
encoding?: 'unicode' | 'ascii';
|
|
454
454
|
clean_accents?: boolean;
|
|
455
455
|
sanitize_replacement?: string;
|
|
456
456
|
};
|
|
457
457
|
collections: (FileCollection | FolderCollection)[];
|
|
458
|
-
}
|
|
458
|
+
}
|
|
459
459
|
|
|
460
|
-
declare
|
|
461
|
-
declare
|
|
460
|
+
declare function defineConfig(config: NetlifyCMSConfig): NetlifyCMSConfig;
|
|
461
|
+
declare function defineFolderCollection(collection: FolderCollection): FolderCollection;
|
|
462
462
|
declare const defineFileCollection: (collection: FileCollection) => FileCollection;
|
|
463
463
|
declare const defineFileCollectionEntry: (collection: FileCollectionEntry) => FileCollectionEntry;
|
|
464
|
-
declare
|
|
465
|
-
declare
|
|
466
|
-
declare
|
|
467
|
-
declare
|
|
468
|
-
declare
|
|
469
|
-
declare
|
|
470
|
-
declare
|
|
471
|
-
declare
|
|
472
|
-
declare
|
|
473
|
-
declare
|
|
474
|
-
declare
|
|
475
|
-
declare
|
|
476
|
-
declare
|
|
477
|
-
declare
|
|
478
|
-
declare
|
|
479
|
-
declare
|
|
480
|
-
|
|
464
|
+
declare function defineBooleanWidget(widget: Omit<BooleanWidget, 'widget'>): BooleanWidget;
|
|
465
|
+
declare function defineCodeWidget(widget: Omit<CodeWidget, 'widget'>): CodeWidget;
|
|
466
|
+
declare function defineColorWidget(widget: Omit<ColorWidget, 'widget'>): ColorWidget;
|
|
467
|
+
declare function defineDateTimeWidget(widget: Omit<DateTimeWidget, 'widget'>): DateTimeWidget;
|
|
468
|
+
declare function defineHiddenWidget(widget: Omit<HiddenWidget, 'widget'>): HiddenWidget;
|
|
469
|
+
declare function defineFileWidget(widget: Omit<FileWidget, 'widget'>): FileWidget;
|
|
470
|
+
declare function defineImageWidget(widget: Omit<ImageWidget, 'widget'>): ImageWidget;
|
|
471
|
+
declare function defineListWidget(widget: Omit<ListWidget, 'widget'>): ListWidget;
|
|
472
|
+
declare function defineMapWidget(widget: Omit<MapWidget, 'widget'>): MapWidget;
|
|
473
|
+
declare function defineNumberWidget(widget: Omit<NumberWidget, 'widget'>): NumberWidget;
|
|
474
|
+
declare function defineObjectWidget(widget: Omit<ObjectWidget, 'widget'>): ObjectWidget;
|
|
475
|
+
declare function defineRelationWidget(widget: Omit<RelationWidget, 'widget'>): RelationWidget;
|
|
476
|
+
declare function defineSelectWidget(widget: Omit<SelectWidget, 'widget'>): SelectWidget;
|
|
477
|
+
declare function defineStringWidget(widget: Omit<StringWidget, 'widget'>): StringWidget;
|
|
478
|
+
declare function defineTextWidget(widget: Omit<TextWidget, 'widget'>): TextWidget;
|
|
479
|
+
declare function defineMarkdownWidget(widget: Omit<MarkdownWidget, 'widget'>): MarkdownWidget;
|
|
480
|
+
interface NetlifyCMSEntry {
|
|
481
481
|
/**
|
|
482
482
|
* Name of config file
|
|
483
483
|
*
|
|
@@ -516,8 +516,8 @@ type NetlifyCMSEntry = {
|
|
|
516
516
|
* @default true
|
|
517
517
|
*/
|
|
518
518
|
useIdentityWidget?: boolean;
|
|
519
|
-
}
|
|
520
|
-
declare
|
|
519
|
+
}
|
|
520
|
+
declare function createConfig(root: string, entry?: NetlifyCMSEntry): Promise<void>;
|
|
521
521
|
declare function export_default(entry?: NetlifyCMSEntry): Promise<Plugin>;
|
|
522
522
|
|
|
523
|
-
export { type BooleanWidget, type CodeWidget, type Collection, type CollectionField, type ColorWidget, type DateTimeWidget, type FileCollection, type FileCollectionEntry, type FileWidget, type FolderCollection, type HiddenWidget, type ImageWidget, type ListWidget, type MapWidget, type MarkdownWidget, type NetlifyCMSConfig, type NetlifyCMSEntry, type NumberWidget, type ObjectWidget, type RelationWidget, type SelectWidget, type StringWidget, type TextWidget, createConfig, export_default as default, defineBooleanWidget, defineCodeWidget, defineColorWidget, defineConfig, defineDateTimeWidget, defineFileCollection, defineFileCollectionEntry, defineFileWidget, defineFolderCollection, defineHiddenWidget, defineImageWidget, defineListWidget, defineMapWidget, defineMarkdownWidget, defineNumberWidget, defineObjectWidget, defineRelationWidget, defineSelectWidget, defineStringWidget, defineTextWidget };
|
|
523
|
+
export { type BooleanWidget, type CodeWidget, type Collection, type CollectionField, type ColorWidget, type DateTimeWidget, type FileCollection, type FileCollectionEntry, type FileWidget, type FolderCollection, type HiddenWidget, type ImageWidget, type ListWidget, type MapWidget, type MarkdownWidget, type NetlifyCMSConfig, type NetlifyCMSEntry, type NumberWidget, type ObjectWidget, type RelationWidget, type SelectWidget, type StringWidget, type TextWidget, type Widget, createConfig, export_default as default, defineBooleanWidget, defineCodeWidget, defineColorWidget, defineConfig, defineDateTimeWidget, defineFileCollection, defineFileCollectionEntry, defineFileWidget, defineFolderCollection, defineHiddenWidget, defineImageWidget, defineListWidget, defineMapWidget, defineMarkdownWidget, defineNumberWidget, defineObjectWidget, defineRelationWidget, defineSelectWidget, defineStringWidget, defineTextWidget };
|
package/dist/index.js
CHANGED
|
@@ -21,88 +21,123 @@ var index_template_default = `<!DOCTYPE html>
|
|
|
21
21
|
</html>`;
|
|
22
22
|
|
|
23
23
|
// src/plugin.ts
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
function defineConfig(config) {
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
function defineFolderCollection(collection) {
|
|
28
|
+
return collection;
|
|
29
|
+
}
|
|
26
30
|
var defineFileCollection = (collection) => collection;
|
|
27
31
|
var defineFileCollectionEntry = (collection) => collection;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
...widget
|
|
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
|
-
|
|
32
|
+
function defineBooleanWidget(widget) {
|
|
33
|
+
return {
|
|
34
|
+
widget: "boolean",
|
|
35
|
+
...widget
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function defineCodeWidget(widget) {
|
|
39
|
+
return {
|
|
40
|
+
widget: "code",
|
|
41
|
+
...widget
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function defineColorWidget(widget) {
|
|
45
|
+
return {
|
|
46
|
+
widget: "color",
|
|
47
|
+
...widget
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function defineDateTimeWidget(widget) {
|
|
51
|
+
return { widget: "datetime", ...widget };
|
|
52
|
+
}
|
|
53
|
+
function defineHiddenWidget(widget) {
|
|
54
|
+
return {
|
|
55
|
+
widget: "hidden",
|
|
56
|
+
...widget
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function defineFileWidget(widget) {
|
|
60
|
+
return {
|
|
61
|
+
widget: "file",
|
|
62
|
+
...widget
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function defineImageWidget(widget) {
|
|
66
|
+
return {
|
|
67
|
+
widget: "image",
|
|
68
|
+
...widget
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function defineListWidget(widget) {
|
|
72
|
+
return {
|
|
73
|
+
widget: "list",
|
|
74
|
+
...widget
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function defineMapWidget(widget) {
|
|
78
|
+
return {
|
|
79
|
+
widget: "map",
|
|
80
|
+
...widget
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function defineNumberWidget(widget) {
|
|
84
|
+
return {
|
|
85
|
+
widget: "number",
|
|
86
|
+
...widget
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function defineObjectWidget(widget) {
|
|
90
|
+
return {
|
|
91
|
+
widget: "object",
|
|
92
|
+
...widget
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function defineRelationWidget(widget) {
|
|
96
|
+
return { widget: "relation", ...widget };
|
|
97
|
+
}
|
|
98
|
+
function defineSelectWidget(widget) {
|
|
99
|
+
return {
|
|
100
|
+
widget: "select",
|
|
101
|
+
...widget
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function defineStringWidget(widget) {
|
|
105
|
+
return {
|
|
106
|
+
widget: "string",
|
|
107
|
+
...widget
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function defineTextWidget(widget) {
|
|
111
|
+
return {
|
|
112
|
+
widget: "text",
|
|
113
|
+
...widget
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function defineMarkdownWidget(widget) {
|
|
117
|
+
return {
|
|
118
|
+
widget: "markdown",
|
|
119
|
+
...widget
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function createFolderIfNotExists(path2) {
|
|
87
123
|
try {
|
|
88
124
|
await readdir(path2);
|
|
89
125
|
} catch {
|
|
90
126
|
await mkdir(path2, { recursive: true });
|
|
91
127
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
128
|
+
}
|
|
129
|
+
async function saveConfig(document, pathTo) {
|
|
94
130
|
await writeFile(pathTo, document);
|
|
95
|
-
}
|
|
96
|
-
|
|
131
|
+
}
|
|
132
|
+
function resolveConfigFilePath(configFile) {
|
|
97
133
|
const _path = configFile.startsWith(".") ? configFile.slice(2) : configFile;
|
|
98
134
|
if (!_path)
|
|
99
135
|
return configFile;
|
|
100
|
-
if (["ts", "js", "cjs", "mjs"].some((ext) => _path.includes(ext)))
|
|
136
|
+
if (["ts", "js", "cjs", "mjs"].some((ext) => _path.includes(ext)))
|
|
101
137
|
return _path.split(".").slice(0, -1).join(".");
|
|
102
|
-
}
|
|
103
138
|
return _path;
|
|
104
|
-
}
|
|
105
|
-
|
|
139
|
+
}
|
|
140
|
+
async function getConfigFile(root, configFile) {
|
|
106
141
|
try {
|
|
107
142
|
const files = await readdir(root);
|
|
108
143
|
const configPath = resolveConfigFilePath(configFile);
|
|
@@ -111,28 +146,26 @@ var getConfigFile = async (root, configFile) => {
|
|
|
111
146
|
return await getConfigFile(path.join(root, folder), file2);
|
|
112
147
|
}
|
|
113
148
|
const file = files.find((file2) => file2.startsWith(configPath));
|
|
114
|
-
if (!file)
|
|
149
|
+
if (!file)
|
|
115
150
|
throw new Error(`Config file not found`);
|
|
116
|
-
}
|
|
117
151
|
const { config } = await loadConfigFromFile(
|
|
118
152
|
{ command: "build", mode: "" },
|
|
119
153
|
path.join(root, file)
|
|
120
154
|
) ?? {};
|
|
121
|
-
if (!config)
|
|
155
|
+
if (!config)
|
|
122
156
|
throw new Error(`Config file not found`);
|
|
123
|
-
}
|
|
124
157
|
return config;
|
|
125
158
|
} catch {
|
|
126
159
|
throw new Error(`Config file not found`);
|
|
127
160
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
161
|
+
}
|
|
162
|
+
function createIndex(title, iconUrl, useIdentityWidget) {
|
|
130
163
|
const icon = iconUrl ? `<link rel="icon" type="image/svg+xml" href="${iconUrl}" />` : "";
|
|
131
164
|
const identity = useIdentityWidget ? `<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>` : "";
|
|
132
165
|
const document = index_template_default.replace("{{ title }}", title).replace("{{ icon }}", icon).replace("{{ identity }}", identity);
|
|
133
166
|
return document;
|
|
134
|
-
}
|
|
135
|
-
|
|
167
|
+
}
|
|
168
|
+
async function createConfig(root, entry) {
|
|
136
169
|
const {
|
|
137
170
|
configFile = "cms.config",
|
|
138
171
|
config,
|
|
@@ -150,7 +183,7 @@ var createConfig = async (root, entry) => {
|
|
|
150
183
|
return;
|
|
151
184
|
const indexHTML = createIndex(title, iconUrl, useIdentityWidget);
|
|
152
185
|
await saveConfig(indexHTML, path.join(root, saveFolder, "index.html"));
|
|
153
|
-
}
|
|
186
|
+
}
|
|
154
187
|
async function plugin_default(entry) {
|
|
155
188
|
let root = "";
|
|
156
189
|
return {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts","../src/index.template.ts","../index.ts"],"sourcesContent":["import { mkdir, readdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Plugin, loadConfigFromFile } from \"vite\";\nimport YAML from \"yaml\";\nimport indexHTMLTemplate from \"./index.template\";\nimport {\n BooleanWidget,\n CodeWidget,\n ColorWidget,\n DateTimeWidget,\n FileCollection,\n FileCollectionEntry,\n FileWidget,\n FolderCollection,\n HiddenWidget,\n ImageWidget,\n ListWidget,\n MapWidget,\n MarkdownWidget,\n NetlifyCMSConfig,\n NumberWidget,\n ObjectWidget,\n RelationWidget,\n SelectWidget,\n StringWidget,\n TextWidget,\n} from \"./types\";\n\nexport const defineConfig = (config: NetlifyCMSConfig): NetlifyCMSConfig =>\n config;\nexport const defineFolderCollection = (collection: FolderCollection) =>\n collection;\nexport const defineFileCollection = (collection: FileCollection) => collection;\nexport const defineFileCollectionEntry = (collection: FileCollectionEntry) => collection;\nexport const defineBooleanWidget = (\n widget: Omit<BooleanWidget, \"widget\">\n): BooleanWidget => ({\n widget: \"boolean\",\n ...widget,\n});\nexport const defineCodeWidget = (\n widget: Omit<CodeWidget, \"widget\">\n): CodeWidget => ({\n widget: \"code\",\n ...widget,\n});\nexport const defineColorWidget = (\n widget: Omit<ColorWidget, \"widget\">\n): ColorWidget => ({\n widget: \"color\",\n ...widget,\n});\nexport const defineDateTimeWidget = (\n widget: Omit<DateTimeWidget, \"widget\">\n): DateTimeWidget => ({ widget: \"datetime\", ...widget });\nexport const defineHiddenWidget = (\n widget: Omit<HiddenWidget, \"widget\">\n): HiddenWidget => ({\n widget: \"hidden\",\n ...widget,\n});\nexport const defineFileWidget = (\n widget: Omit<FileWidget, \"widget\">\n): FileWidget => ({\n widget: \"file\",\n ...widget,\n});\nexport const defineImageWidget = (\n widget: Omit<ImageWidget, \"widget\">\n): ImageWidget => ({\n widget: \"image\",\n ...widget,\n});\nexport const defineListWidget = (\n widget: Omit<ListWidget, \"widget\">\n): ListWidget => ({\n widget: \"list\",\n ...widget,\n});\nexport const defineMapWidget = (\n widget: Omit<MapWidget, \"widget\">\n): MapWidget => ({\n widget: \"map\",\n ...widget,\n});\nexport const defineNumberWidget = (\n widget: Omit<NumberWidget, \"widget\">\n): NumberWidget => ({\n widget: \"number\",\n ...widget,\n});\nexport const defineObjectWidget = (\n widget: Omit<ObjectWidget, \"widget\">\n): ObjectWidget => ({\n widget: \"object\",\n ...widget,\n});\nexport const defineRelationWidget = (\n widget: Omit<RelationWidget, \"widget\">\n): RelationWidget => ({ widget: \"relation\", ...widget });\nexport const defineSelectWidget = (\n widget: Omit<SelectWidget, \"widget\">\n): SelectWidget => ({\n widget: \"select\",\n ...widget,\n});\nexport const defineStringWidget = (\n widget: Omit<StringWidget, \"widget\">\n): StringWidget => ({\n widget: \"string\",\n ...widget,\n});\nexport const defineTextWidget = (\n widget: Omit<TextWidget, \"widget\">\n): TextWidget => ({\n widget: \"text\",\n ...widget,\n});\nexport const defineMarkdownWidget = (\n widget: Omit<MarkdownWidget, \"widget\">\n): MarkdownWidget => ({\n widget: \"markdown\",\n ...widget,\n});\n\nexport type NetlifyCMSEntry = {\n /**\n * Name of config file\n * \n * @default cms.config\n */\n configFile?: string;\n\n /**\n * Netlify CMS config object\n */\n config?: NetlifyCMSConfig;\n\n /**\n * Folder to save config file\n * \n * @default ./public/admin\n */\n saveFolder?: string;\n\n /**\n * If has to create index.html file in the save folder\n */\n createIndexHTML?: boolean;\n\n /**\n * Title of the admin page\n * \n * @default Admin\n */\n title?: string;\n\n /**\n * Icon URL of the admin page\n * \n * @default https://decapcms.org/img/decap-logo.svg\n */\n iconUrl?: string;\n\n /**\n * If has to use identity widget\n * \n * @default true\n */\n useIdentityWidget?: boolean;\n};\n\nconst createFolderIfNotExists = async (path: string) => {\n try {\n await readdir(path);\n } catch {\n await mkdir(path, { recursive: true });\n }\n};\n\nconst saveConfig = async (document: string, pathTo: string) => {\n await writeFile(pathTo, document);\n};\n\nconst resolveConfigFilePath = (configFile: string) => {\n const _path = configFile.startsWith(\".\") ? configFile.slice(2) : configFile;\n\n if (!_path) return configFile;\n if ([\"ts\", \"js\", \"cjs\", \"mjs\"].some((ext) => _path.includes(ext))) {\n return _path.split(\".\").slice(0, -1).join(\".\");\n }\n\n return _path;\n};\n\nconst getConfigFile = async (\n root: string,\n configFile: string\n): Promise<NetlifyCMSConfig> => {\n try {\n const files = await readdir(root);\n const configPath = resolveConfigFilePath(configFile);\n\n if (configPath.includes(\"/\")) {\n const [folder, file] = configPath.split(\"/\");\n return await getConfigFile(path.join(root, folder), file);\n }\n\n const file = files.find((file) => file.startsWith(configPath));\n\n if (!file) {\n throw new Error(`Config file not found`);\n }\n\n const { config } =\n (await loadConfigFromFile(\n { command: \"build\", mode: \"\" },\n path.join(root, file)\n )) ?? {};\n\n if (!config) {\n throw new Error(`Config file not found`);\n }\n\n return config as NetlifyCMSConfig;\n } catch {\n throw new Error(`Config file not found`);\n }\n};\n\nconst createIndex = (title: string, iconUrl: string, useIdentityWidget: boolean) => {\n const icon = iconUrl ? `<link rel=\"icon\" type=\"image/svg+xml\" href=\"${iconUrl}\" />` : \"\";\n const identity = useIdentityWidget ? `<script src=\"https://identity.netlify.com/v1/netlify-identity-widget.js\"></script>` : \"\";\n\n const document = indexHTMLTemplate\n .replace(\"{{ title }}\", title)\n .replace(\"{{ icon }}\", icon)\n .replace(\"{{ identity }}\", identity);\n\n return document;\n}\n\nexport const createConfig = async (root: string, entry?: NetlifyCMSEntry) => {\n const {\n configFile = \"cms.config\",\n config,\n saveFolder = \"./public/admin\",\n createIndexHTML = true,\n title = \"Admin\",\n iconUrl = \"https://decapcms.org/img/decap-logo.svg\",\n useIdentityWidget = true,\n } = entry ?? {};\n\n const resolvedConfig = config ?? (await getConfigFile(root, configFile));\n await createFolderIfNotExists(path.join(root, saveFolder));\n\n const document = YAML.stringify(resolvedConfig);\n await saveConfig(document, path.join(root, saveFolder, \"config.yml\"));\n\n if (!createIndexHTML) return;\n\n const indexHTML = createIndex(title, iconUrl, useIdentityWidget);\n await saveConfig(indexHTML, path.join(root, saveFolder, \"index.html\"));\n};\n\nexport default async function (entry?: NetlifyCMSEntry): Promise<Plugin> {\n let root = \"\";\n\n return {\n name: \"vite-plugin-netlify-cms\",\n configResolved: (config) => {\n root = config.root;\n },\n buildStart: async () => {\n try {\n await createConfig(root, entry);\n } catch (error) {\n console.log(error);\n }\n },\n handleHotUpdate: async ({ file }) => {\n if (file.includes(entry?.configFile ?? \"cms.config\")) {\n try {\n await createConfig(root, entry);\n } catch (error) {\n console.log(error);\n }\n }\n },\n };\n}\n","export default `<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>{{ title }}</title>\n {{ icon }}\n {{ identity }}\n </head>\n <body>\n <!-- Include the script that builds the page and powers Decap CMS -->\n <script src=\"https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js\"></script>\n </body>\n</html>`\n","export * from \"./src/plugin.js\";\nexport * from \"./src/types.js\";\nimport plugin from \"./src/plugin.js\";\n\nexport default plugin;\n"],"mappings":";AAAA,SAAS,OAAO,SAAS,iBAAiB;AAC1C,OAAO,UAAU;AACjB,SAAiB,0BAA0B;AAC3C,OAAO,UAAU;;;ACHjB,IAAO,yBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AD4BR,IAAM,eAAe,CAAC,WAC3B;AACK,IAAM,yBAAyB,CAAC,eACrC;AACK,IAAM,uBAAuB,CAAC,eAA+B;AAC7D,IAAM,4BAA4B,CAAC,eAAoC;AACvE,IAAM,sBAAsB,CACjC,YACmB;AAAA,EACnB,QAAQ;AAAA,EACR,GAAG;AACL;AACO,IAAM,mBAAmB,CAC9B,YACgB;AAAA,EAChB,QAAQ;AAAA,EACR,GAAG;AACL;AACO,IAAM,oBAAoB,C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Q,kBAAkB,QAAQ;AAErC,SAAO;AACT;AAEO,IAAM,eAAe,OAAO,MAAc,UAA4B;AAC3E,QAAM;AAAA,IACJ,aAAa;AAAA,IACb;AAAA,IACA,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,oBAAoB;AAAA,EACtB,IAAI,SAAS,CAAC;AAEd,QAAM,iBAAiB,UAAW,MAAM,cAAc,MAAM,UAAU;AACtE,QAAM,wBAAwB,KAAK,KAAK,MAAM,UAAU,CAAC;AAEzD,QAAM,WAAW,KAAK,UAAU,cAAc;AAC9C,QAAM,WAAW,UAAU,KAAK,KAAK,MAAM,YAAY,YAAY,CAAC;AAEpE,MAAI,CAAC;AAAiB;AAEtB,QAAM,YAAY,YAAY,OAAO,SAAS,iBAAiB;AAC/D,QAAM,WAAW,WAAW,KAAK,KAAK,MAAM,YAAY,YAAY,CAAC;AACvE;AAEA,eAAO,eAAwB,OAA0C;AACvE,MAAI,OAAO;AAEX,SAAO;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB,CAAC,WAAW;AAC1B,aAAO,OAAO;AAAA,IAChB;AAAA,IACA,YAAY,YAAY;AACtB,UAAI;AACF,cAAM,aAAa,MAAM,KAAK;AAAA,MAChC,SAAS,OAAO;AACd,gBAAQ,IAAI,KAAK;AAAA,MACnB;AAAA,IACF;AAAA,IACA,iBAAiB,OAAO,EAAE,KAAK,MAAM;AACnC,UAAI,KAAK,SAAS,OAAO,cAAc,YAAY,GAAG;AACpD,YAAI;AACF,gBAAM,aAAa,MAAM,KAAK;AAAA,QAChC,SAAS,OAAO;AACd,kBAAQ,IAAI,KAAK;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AE9RA,IAAO,kCAAQ;","names":["path","file"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/index.template.ts","../index.ts"],"sourcesContent":["import { mkdir, readdir, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport type { Plugin } from 'vite';\nimport { loadConfigFromFile } from 'vite';\nimport YAML from 'yaml';\nimport indexHTMLTemplate from './index.template';\nimport type {\n BooleanWidget,\n CodeWidget,\n ColorWidget,\n DateTimeWidget,\n FileCollection,\n FileCollectionEntry,\n FileWidget,\n FolderCollection,\n HiddenWidget,\n ImageWidget,\n ListWidget,\n MapWidget,\n MarkdownWidget,\n NetlifyCMSConfig,\n NumberWidget,\n ObjectWidget,\n RelationWidget,\n SelectWidget,\n StringWidget,\n TextWidget,\n} from './types';\n\nexport function defineConfig(config: NetlifyCMSConfig): NetlifyCMSConfig {\n return config;\n}\nexport function defineFolderCollection(collection: FolderCollection) {\n return collection;\n}\nexport const defineFileCollection = (collection: FileCollection) => collection;\nexport const defineFileCollectionEntry = (collection: FileCollectionEntry) => collection;\nexport function defineBooleanWidget(widget: Omit<BooleanWidget, 'widget'>): BooleanWidget {\n return {\n widget: 'boolean',\n ...widget,\n };\n}\nexport function defineCodeWidget(widget: Omit<CodeWidget, 'widget'>): CodeWidget {\n return {\n widget: 'code',\n ...widget,\n };\n}\nexport function defineColorWidget(widget: Omit<ColorWidget, 'widget'>): ColorWidget {\n return {\n widget: 'color',\n ...widget,\n };\n}\nexport function defineDateTimeWidget(widget: Omit<DateTimeWidget, 'widget'>): DateTimeWidget {\n return { widget: 'datetime', ...widget };\n}\nexport function defineHiddenWidget(widget: Omit<HiddenWidget, 'widget'>): HiddenWidget {\n return {\n widget: 'hidden',\n ...widget,\n };\n}\nexport function defineFileWidget(widget: Omit<FileWidget, 'widget'>): FileWidget {\n return {\n widget: 'file',\n ...widget,\n };\n}\nexport function defineImageWidget(widget: Omit<ImageWidget, 'widget'>): ImageWidget {\n return {\n widget: 'image',\n ...widget,\n };\n}\nexport function defineListWidget(widget: Omit<ListWidget, 'widget'>): ListWidget {\n return {\n widget: 'list',\n ...widget,\n };\n}\nexport function defineMapWidget(widget: Omit<MapWidget, 'widget'>): MapWidget {\n return {\n widget: 'map',\n ...widget,\n };\n}\nexport function defineNumberWidget(widget: Omit<NumberWidget, 'widget'>): NumberWidget {\n return {\n widget: 'number',\n ...widget,\n };\n}\nexport function defineObjectWidget(widget: Omit<ObjectWidget, 'widget'>): ObjectWidget {\n return {\n widget: 'object',\n ...widget,\n };\n}\nexport function defineRelationWidget(widget: Omit<RelationWidget, 'widget'>): RelationWidget {\n return { widget: 'relation', ...widget };\n}\nexport function defineSelectWidget(widget: Omit<SelectWidget, 'widget'>): SelectWidget {\n return {\n widget: 'select',\n ...widget,\n };\n}\nexport function defineStringWidget(widget: Omit<StringWidget, 'widget'>): StringWidget {\n return {\n widget: 'string',\n ...widget,\n };\n}\nexport function defineTextWidget(widget: Omit<TextWidget, 'widget'>): TextWidget {\n return {\n widget: 'text',\n ...widget,\n };\n}\nexport function defineMarkdownWidget(widget: Omit<MarkdownWidget, 'widget'>): MarkdownWidget {\n return {\n widget: 'markdown',\n ...widget,\n };\n}\n\nexport interface NetlifyCMSEntry {\n /**\n * Name of config file\n *\n * @default cms.config\n */\n configFile?: string;\n\n /**\n * Netlify CMS config object\n */\n config?: NetlifyCMSConfig;\n\n /**\n * Folder to save config file\n *\n * @default ./public/admin\n */\n saveFolder?: string;\n\n /**\n * If has to create index.html file in the save folder\n */\n createIndexHTML?: boolean;\n\n /**\n * Title of the admin page\n *\n * @default Admin\n */\n title?: string;\n\n /**\n * Icon URL of the admin page\n *\n * @default https://decapcms.org/img/decap-logo.svg\n */\n iconUrl?: string;\n\n /**\n * If has to use identity widget\n *\n * @default true\n */\n useIdentityWidget?: boolean;\n}\n\nasync function createFolderIfNotExists(path: string) {\n try {\n await readdir(path);\n }\n catch {\n await mkdir(path, { recursive: true });\n }\n}\n\nasync function saveConfig(document: string, pathTo: string) {\n await writeFile(pathTo, document);\n}\n\nfunction resolveConfigFilePath(configFile: string) {\n const _path = configFile.startsWith('.') ? configFile.slice(2) : configFile;\n\n if (!_path)\n return configFile;\n if (['ts', 'js', 'cjs', 'mjs'].some(ext => _path.includes(ext)))\n return _path.split('.').slice(0, -1).join('.');\n\n return _path;\n}\n\nasync function getConfigFile(root: string, configFile: string): Promise<NetlifyCMSConfig> {\n try {\n const files = await readdir(root);\n const configPath = resolveConfigFilePath(configFile);\n\n if (configPath.includes('/')) {\n const [folder, file] = configPath.split('/');\n return await getConfigFile(path.join(root, folder), file);\n }\n\n const file = files.find(file => file.startsWith(configPath));\n\n if (!file)\n throw new Error(`Config file not found`);\n\n const { config }\n = (await loadConfigFromFile(\n { command: 'build', mode: '' },\n path.join(root, file),\n )) ?? {};\n\n if (!config)\n throw new Error(`Config file not found`);\n\n return config as NetlifyCMSConfig;\n }\n catch {\n throw new Error(`Config file not found`);\n }\n}\n\nfunction createIndex(title: string, iconUrl: string, useIdentityWidget: boolean) {\n const icon = iconUrl ? `<link rel=\"icon\" type=\"image/svg+xml\" href=\"${iconUrl}\" />` : '';\n const identity = useIdentityWidget ? `<script src=\"https://identity.netlify.com/v1/netlify-identity-widget.js\"></script>` : '';\n\n const document = indexHTMLTemplate\n .replace('{{ title }}', title)\n .replace('{{ icon }}', icon)\n .replace('{{ identity }}', identity);\n\n return document;\n}\n\nexport async function createConfig(root: string, entry?: NetlifyCMSEntry) {\n const {\n configFile = 'cms.config',\n config,\n saveFolder = './public/admin',\n createIndexHTML = true,\n title = 'Admin',\n iconUrl = 'https://decapcms.org/img/decap-logo.svg',\n useIdentityWidget = true,\n } = entry ?? {};\n\n const resolvedConfig = config ?? (await getConfigFile(root, configFile));\n await createFolderIfNotExists(path.join(root, saveFolder));\n\n const document = YAML.stringify(resolvedConfig);\n await saveConfig(document, path.join(root, saveFolder, 'config.yml'));\n\n if (!createIndexHTML)\n return;\n\n const indexHTML = createIndex(title, iconUrl, useIdentityWidget);\n await saveConfig(indexHTML, path.join(root, saveFolder, 'index.html'));\n}\n\nexport default async function (entry?: NetlifyCMSEntry): Promise<Plugin> {\n let root = '';\n\n return {\n name: 'vite-plugin-netlify-cms',\n configResolved: (config) => {\n root = config.root;\n },\n buildStart: async () => {\n try {\n await createConfig(root, entry);\n }\n catch (error) {\n console.log(error);\n }\n },\n handleHotUpdate: async ({ file }) => {\n if (file.includes(entry?.configFile ?? 'cms.config')) {\n try {\n await createConfig(root, entry);\n }\n catch (error) {\n console.log(error);\n }\n }\n },\n };\n}\n","export default `<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>{{ title }}</title>\n {{ icon }}\n {{ identity }}\n </head>\n <body>\n <!-- Include the script that builds the page and powers Decap CMS -->\n <script src=\"https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js\"></script>\n </body>\n</html>`\n","export * from \"./src/plugin.js\";\nexport * from \"./src/types.js\";\nimport plugin from \"./src/plugin.js\";\n\nexport default plugin;\n"],"mappings":";AAAA,SAAS,OAAO,SAAS,iBAAiB;AAC1C,OAAO,UAAU;AAEjB,SAAS,0BAA0B;AACnC,OAAO,UAAU;;;ACJjB,IAAO,yBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AD6BR,SAAS,aAAa,QAA4C;AACvE,SAAO;AACT;AACO,SAAS,uBAAuB,YAA8B;AACnE,SAAO;AACT;AACO,IAAM,uBAAuB,CAAC,eAA+B;AAC7D,IAAM,4BAA4B,CAAC,eAAoC;AACvE,SAAS,oBAAoB,QAAsD;AACxF,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;AACO,SAAS,iBAAiB,QAAgD;AAC/E,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;AACO,SAAS,kBAAkB,QAAkD;AAClF,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;AACO,SAAS,qBAAqB,QAAwD;AAC3F,SAAO,EAAE,QAAQ,YAAY,GAAG,OAAO;AACzC;AACO,SAAS,mBAAmB,QA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;AAEA,eAAsB,aAAa,MAAc,OAAyB;AACxE,QAAM;AAAA,IACJ,aAAa;AAAA,IACb;AAAA,IACA,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,oBAAoB;AAAA,EACtB,IAAI,SAAS,CAAC;AAEd,QAAM,iBAAiB,UAAW,MAAM,cAAc,MAAM,UAAU;AACtE,QAAM,wBAAwB,KAAK,KAAK,MAAM,UAAU,CAAC;AAEzD,QAAM,WAAW,KAAK,UAAU,cAAc;AAC9C,QAAM,WAAW,UAAU,KAAK,KAAK,MAAM,YAAY,YAAY,CAAC;AAEpE,MAAI,CAAC;AACH;AAEF,QAAM,YAAY,YAAY,OAAO,SAAS,iBAAiB;AAC/D,QAAM,WAAW,WAAW,KAAK,KAAK,MAAM,YAAY,YAAY,CAAC;AACvE;AAEA,eAAO,eAAwB,OAA0C;AACvE,MAAI,OAAO;AAEX,SAAO;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB,CAAC,WAAW;AAC1B,aAAO,OAAO;AAAA,IAChB;AAAA,IACA,YAAY,YAAY;AACtB,UAAI;AACF,cAAM,aAAa,MAAM,KAAK;AAAA,MAChC,SACO,OAAO;AACZ,gBAAQ,IAAI,KAAK;AAAA,MACnB;AAAA,IACF;AAAA,IACA,iBAAiB,OAAO,EAAE,KAAK,MAAM;AACnC,UAAI,KAAK,SAAS,OAAO,cAAc,YAAY,GAAG;AACpD,YAAI;AACF,gBAAM,aAAa,MAAM,KAAK;AAAA,QAChC,SACO,OAAO;AACZ,kBAAQ,IAAI,KAAK;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AEjSA,IAAO,kCAAQ;","names":["path","file"]}
|
package/package.json
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
+
"name": "@caiquecamargo/vite-plugin-netlify-cms",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.17",
|
|
2
5
|
"author": "Caique de Camargo",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
},
|
|
8
|
-
"dependencies": {
|
|
9
|
-
"yaml": "^2.3.4"
|
|
10
|
-
},
|
|
11
|
-
"peerDependencies": {
|
|
12
|
-
"vite": "^4.0.0 || ^5.0.0"
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/caiquecamargo/vite-plugin-netlify-cms.git"
|
|
13
10
|
},
|
|
11
|
+
"keywords": [],
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
|
-
"
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
17
15
|
"import": "./dist/index.js",
|
|
18
|
-
"
|
|
16
|
+
"default": "./dist/index.js"
|
|
19
17
|
}
|
|
20
18
|
},
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
21
22
|
"files": [
|
|
22
23
|
"dist"
|
|
23
24
|
],
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"vite": "^4.0.0 || ^5.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"yaml": "^2.3.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@antfu/eslint-config": "^2.12.1",
|
|
33
|
+
"@types/node": "^20.10.5",
|
|
34
|
+
"eslint": "^8.57.0",
|
|
35
|
+
"tsup": "^8.0.1",
|
|
36
|
+
"typescript": "^5.3.3"
|
|
37
|
+
},
|
|
29
38
|
"publishConfig": {
|
|
30
39
|
"access": "public",
|
|
31
40
|
"registry": "https://registry.npmjs.org/"
|
|
32
41
|
},
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "https://github.com/caiquecamargo/vite-plugin-netlify-cms.git"
|
|
36
|
-
},
|
|
37
|
-
"type": "module",
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
|
-
"version": "0.0.15",
|
|
40
42
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev:watch": "
|
|
43
|
-
"dev": "
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"dev:watch": "tsup --watch",
|
|
45
|
+
"dev": "tsup",
|
|
44
46
|
"package": "pnpm build",
|
|
45
47
|
"pub": "pnpm publish"
|
|
46
48
|
}
|