@tinacms/app 0.0.22 → 0.0.24
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/appFiles/package.json +19 -0
- package/appFiles/src/App.tsx +63 -0
- package/appFiles/src/assets/react.svg +1 -0
- package/appFiles/src/index.css +3 -0
- package/appFiles/src/lib/formify/index.ts +314 -0
- package/appFiles/src/lib/machines/document-machine.ts +348 -0
- package/appFiles/src/lib/machines/query-machine.ts +630 -0
- package/appFiles/src/lib/machines/util.ts +205 -0
- package/appFiles/src/main.tsx +24 -0
- package/appFiles/src/preview.tsx +114 -0
- package/appFiles/src/vite-env.d.ts +14 -0
- package/dist/index.js +123 -96
- package/package.json +21 -24
- package/dist/assets/out.es.js +0 -109825
- package/dist/assets/style.css +0 -651
- package/dist/index.dev.html +0 -26
- package/dist/index.html +0 -13
- package/dist/prebuild.d.ts +0 -1
- package/dist/prebuild.js +0 -308
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
import { DocumentBlueprint } from '../formify/types'
|
|
14
|
+
|
|
15
|
+
type Location = number[] | null
|
|
16
|
+
|
|
17
|
+
export const getBlueprintValues = (
|
|
18
|
+
data: object,
|
|
19
|
+
path: string,
|
|
20
|
+
index: number = 0
|
|
21
|
+
): string[] | undefined => {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
const pathArray = path.split('.')
|
|
26
|
+
const next = pathArray[index]
|
|
27
|
+
if (next === '[]') {
|
|
28
|
+
if (Array.isArray(data)) {
|
|
29
|
+
const values: string[] = []
|
|
30
|
+
data.forEach((item) => {
|
|
31
|
+
const res = getBlueprintValues(item, path, index + 1)
|
|
32
|
+
if (res) {
|
|
33
|
+
res.forEach((item) => {
|
|
34
|
+
values.push(item)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
return values
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
const value = data[next]
|
|
42
|
+
// Is last item
|
|
43
|
+
if (pathArray.length === index + 1) {
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value
|
|
46
|
+
} else {
|
|
47
|
+
return [value]
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return getBlueprintValues(value, path)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const getAllIn = (
|
|
56
|
+
data: object | object[] | null,
|
|
57
|
+
path: string,
|
|
58
|
+
index: number = 0,
|
|
59
|
+
location: Location = null
|
|
60
|
+
): { value: { id: string }; location: Location }[] | undefined => {
|
|
61
|
+
if (!data) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const pathArray = path.split('.')
|
|
65
|
+
const next = pathArray[index]
|
|
66
|
+
if (next === '[]') {
|
|
67
|
+
if (Array.isArray(data)) {
|
|
68
|
+
const values: { value: { id: string }; location: Location }[] = []
|
|
69
|
+
data.forEach((item, dataIndex) => {
|
|
70
|
+
const res = getAllIn(item, path, index + 1, [
|
|
71
|
+
...(location || []),
|
|
72
|
+
dataIndex,
|
|
73
|
+
])
|
|
74
|
+
if (res) {
|
|
75
|
+
res.forEach((item) => {
|
|
76
|
+
values.push(item)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
return values
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
const value = data[next]
|
|
84
|
+
// Is last item
|
|
85
|
+
if (pathArray.length === index + 1) {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
const v = value.map((item, index) => ({
|
|
88
|
+
value: item,
|
|
89
|
+
location: [...(location || []), index],
|
|
90
|
+
}))
|
|
91
|
+
return v
|
|
92
|
+
} else {
|
|
93
|
+
if (typeof value === 'string') {
|
|
94
|
+
const v = [{ value: { id: value }, location }]
|
|
95
|
+
return v
|
|
96
|
+
} else {
|
|
97
|
+
// FIXME: this should always be `_internalSys.path` but we're not populating the
|
|
98
|
+
// data properly on resolveData yet. But even when we are, will need to keep that out
|
|
99
|
+
// of the user-provided payload (maybe not?)
|
|
100
|
+
const id = value?._internalSys?.path || value?.id
|
|
101
|
+
if (id) {
|
|
102
|
+
const v = [{ value: { id, ...value }, location }]
|
|
103
|
+
return v
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const v = getAllIn(value, path, index + 1, location)
|
|
109
|
+
return v
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export const getAllInBlueprint = (
|
|
114
|
+
data: object | object[] | null,
|
|
115
|
+
path: string,
|
|
116
|
+
index: number = 0,
|
|
117
|
+
location: Location = null
|
|
118
|
+
):
|
|
119
|
+
| { value: { _internalSys: { path: string } }; location: Location }[]
|
|
120
|
+
| undefined => {
|
|
121
|
+
if (!data) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
const pathArray = path.split('.')
|
|
125
|
+
const next = pathArray[index]
|
|
126
|
+
if (next === '[]') {
|
|
127
|
+
if (Array.isArray(data)) {
|
|
128
|
+
const values: {
|
|
129
|
+
value: { _internalSys: { path: string } }
|
|
130
|
+
location: Location
|
|
131
|
+
}[] = []
|
|
132
|
+
data.forEach((item, dataIndex) => {
|
|
133
|
+
const res = getAllInBlueprint(item, path, index + 1, [
|
|
134
|
+
...(location || []),
|
|
135
|
+
dataIndex,
|
|
136
|
+
])
|
|
137
|
+
if (res) {
|
|
138
|
+
res.forEach((item) => {
|
|
139
|
+
values.push(item)
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
return values
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
const value = data[next]
|
|
147
|
+
// Is last item
|
|
148
|
+
if (pathArray.length === index + 1) {
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
throw new Error(`Unexpected array value for getAllInBlueprint`)
|
|
151
|
+
} else {
|
|
152
|
+
if (typeof value === 'string') {
|
|
153
|
+
throw new Error(`Unexpected string value for getAllInBlueprint`)
|
|
154
|
+
} else {
|
|
155
|
+
const id = value?._internalSys?.path || value?.id
|
|
156
|
+
if (id) {
|
|
157
|
+
const v = [
|
|
158
|
+
{ value: { _internalSys: value._internalSys }, location },
|
|
159
|
+
]
|
|
160
|
+
return v
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
const v = getAllInBlueprint(value, path, index + 1, location)
|
|
166
|
+
return v
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const getBlueprintFromLocation = (
|
|
172
|
+
location: string,
|
|
173
|
+
blueprints: DocumentBlueprint[]
|
|
174
|
+
) => {
|
|
175
|
+
const blueprintString = location
|
|
176
|
+
.split('.')
|
|
177
|
+
.map((item) => (isNaN(Number(item)) ? item : '[]'))
|
|
178
|
+
.join('.')
|
|
179
|
+
const blueprint = blueprints.find(({ id }) => id === blueprintString)
|
|
180
|
+
if (!blueprint) {
|
|
181
|
+
throw new Error(`Unable to find blueprint at ${blueprintString}`)
|
|
182
|
+
}
|
|
183
|
+
return blueprint
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// FIXME: this assumes children are in order (which they
|
|
187
|
+
// are AFAIK but shouldn't be relied on)
|
|
188
|
+
export const getBlueprintChildren = (
|
|
189
|
+
blueprint: DocumentBlueprint,
|
|
190
|
+
blueprints: DocumentBlueprint[]
|
|
191
|
+
) => {
|
|
192
|
+
const foundChildren: DocumentBlueprint[] = []
|
|
193
|
+
blueprints.forEach((otherBlueprint) => {
|
|
194
|
+
if (foundChildren.find(({ id }) => otherBlueprint.id.startsWith(id))) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
if (
|
|
198
|
+
otherBlueprint.id.startsWith(blueprint.id) &&
|
|
199
|
+
otherBlueprint.id !== blueprint.id
|
|
200
|
+
) {
|
|
201
|
+
foundChildren.push(otherBlueprint)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
return foundChildren
|
|
205
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import React from 'react'
|
|
15
|
+
import ReactDOM from 'react-dom'
|
|
16
|
+
import App from './App'
|
|
17
|
+
import './index.css'
|
|
18
|
+
|
|
19
|
+
ReactDOM.render(
|
|
20
|
+
<React.StrictMode>
|
|
21
|
+
<App />
|
|
22
|
+
</React.StrictMode>,
|
|
23
|
+
document.getElementById('root')
|
|
24
|
+
)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
import React from 'react'
|
|
14
|
+
import { useMachine } from '@xstate/react'
|
|
15
|
+
import { queryMachine, initialContext } from './lib/machines/query-machine'
|
|
16
|
+
import { useCMS, defineStaticConfig } from 'tinacms'
|
|
17
|
+
|
|
18
|
+
type Config = Parameters<typeof defineStaticConfig>[0]
|
|
19
|
+
|
|
20
|
+
type PostMessage = {
|
|
21
|
+
type: 'open' | 'close'
|
|
22
|
+
id: string
|
|
23
|
+
data: object
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Preview = (
|
|
27
|
+
props: Config & {
|
|
28
|
+
url: string
|
|
29
|
+
iframeRef: React.MutableRefObject<HTMLIFrameElement>
|
|
30
|
+
}
|
|
31
|
+
) => {
|
|
32
|
+
const [activeQuery, setActiveQuery] = React.useState<PostMessage | null>(null)
|
|
33
|
+
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (props.iframeRef.current) {
|
|
36
|
+
window.addEventListener('message', (event: MessageEvent<PostMessage>) => {
|
|
37
|
+
if (event.data.type === 'open') {
|
|
38
|
+
setActiveQuery(event.data)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}, [props.iframeRef.current])
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="tina-tailwind">
|
|
46
|
+
{activeQuery && (
|
|
47
|
+
<QueryMachine
|
|
48
|
+
key={activeQuery.id}
|
|
49
|
+
payload={activeQuery}
|
|
50
|
+
iframeRef={props.iframeRef}
|
|
51
|
+
/>
|
|
52
|
+
)}
|
|
53
|
+
<div className="h-full overflow-scroll">
|
|
54
|
+
<div className="">
|
|
55
|
+
<div className="col-span-5 ">
|
|
56
|
+
<div className="h-screen flex flex-col">
|
|
57
|
+
<div className="relative flex-1 bg-gray-300 col-span-2 overflow-scroll flex items-center justify-center">
|
|
58
|
+
<iframe
|
|
59
|
+
ref={props.iframeRef}
|
|
60
|
+
className="h-full w-full bg-white"
|
|
61
|
+
src={props.url}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const QueryMachine = (props: {
|
|
73
|
+
payload: PostMessage
|
|
74
|
+
iframeRef: React.MutableRefObject<HTMLIFrameElement>
|
|
75
|
+
}) => {
|
|
76
|
+
const cms = useCMS()
|
|
77
|
+
|
|
78
|
+
const machine = React.useMemo(
|
|
79
|
+
() =>
|
|
80
|
+
queryMachine.withContext({
|
|
81
|
+
...initialContext,
|
|
82
|
+
cms,
|
|
83
|
+
// @ts-ignore FIXME: add formifyCallback args to Config type
|
|
84
|
+
formifyCallback: props.formifyCallback,
|
|
85
|
+
}),
|
|
86
|
+
[]
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const [state, send] = useMachine(machine)
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
if (state.matches('pipeline.ready')) {
|
|
92
|
+
cms.events.dispatch({ type: 'forms:register', value: 'complete' })
|
|
93
|
+
} else if (state.matches('pipeline.initializing')) {
|
|
94
|
+
cms.events.dispatch({ type: 'forms:register', value: 'start' })
|
|
95
|
+
}
|
|
96
|
+
}, [JSON.stringify(state.value)])
|
|
97
|
+
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
if (props.iframeRef.current) {
|
|
100
|
+
send({ type: 'IFRAME_MOUNTED', value: props.iframeRef.current })
|
|
101
|
+
if (props.payload.type === 'open') {
|
|
102
|
+
send({ type: 'ADD_QUERY', value: props.payload })
|
|
103
|
+
}
|
|
104
|
+
window.addEventListener('message', (event: MessageEvent<PostMessage>) => {
|
|
105
|
+
// useTinaHook cleans itself up when the component unmounts by sending a close message
|
|
106
|
+
if (event.data.type === 'close') {
|
|
107
|
+
send({ type: 'REMOVE_QUERY' })
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}, [props.iframeRef.current])
|
|
112
|
+
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/// <reference types="vite/client" />
|
package/dist/index.js
CHANGED
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
8
|
var __export = (target, all) => {
|
|
23
9
|
__markAsModule(target);
|
|
@@ -40,10 +26,10 @@ var __toModule = (module2) => {
|
|
|
40
26
|
__export(exports, {
|
|
41
27
|
viteBuild: () => viteBuild
|
|
42
28
|
});
|
|
43
|
-
var import_plugin_react = __toModule(require("@vitejs/plugin-react"));
|
|
44
29
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
45
|
-
var import_vite = __toModule(require("vite"));
|
|
46
30
|
var import_path2 = __toModule(require("path"));
|
|
31
|
+
var import_vite = __toModule(require("vite"));
|
|
32
|
+
var import_plugin_react = __toModule(require("@vitejs/plugin-react"));
|
|
47
33
|
|
|
48
34
|
// src/tailwind.ts
|
|
49
35
|
var import_tailwindcss = __toModule(require("tailwindcss"));
|
|
@@ -296,122 +282,163 @@ var viteTina = () => {
|
|
|
296
282
|
};
|
|
297
283
|
};
|
|
298
284
|
|
|
285
|
+
// src/html.ts
|
|
286
|
+
var devHTML = `<!DOCTYPE html>
|
|
287
|
+
<html lang="en">
|
|
288
|
+
<head>
|
|
289
|
+
<meta charset="UTF-8" />
|
|
290
|
+
<link rel="icon" type="image/svg+xml" href="/tina.svg" />
|
|
291
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
292
|
+
<title>TinaCMS</title>
|
|
293
|
+
</head>
|
|
294
|
+
|
|
295
|
+
<!-- if development -->
|
|
296
|
+
<script type="module">
|
|
297
|
+
import RefreshRuntime from 'http://localhost:5173/@react-refresh'
|
|
298
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
|
299
|
+
window.$RefreshReg$ = () => {}
|
|
300
|
+
window.$RefreshSig$ = () => (type) => type
|
|
301
|
+
window.__vite_plugin_react_preamble_installed__ = true
|
|
302
|
+
<\/script>
|
|
303
|
+
<script type="module" src="http://localhost:5173/@vite/client"><\/script>
|
|
304
|
+
<script
|
|
305
|
+
type="module"
|
|
306
|
+
src="http://localhost:5173/INSERT_OUTPUT_FOLDER_NAME/src/main.tsx"
|
|
307
|
+
><\/script>
|
|
308
|
+
<body class="tina-tailwind">
|
|
309
|
+
<div id="root"></div>
|
|
310
|
+
</body>
|
|
311
|
+
</html>`;
|
|
312
|
+
var prodHTML = `<!DOCTYPE html>
|
|
313
|
+
<html lang="en">
|
|
314
|
+
<head>
|
|
315
|
+
<meta charset="UTF-8" />
|
|
316
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
317
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
318
|
+
<title>TinaCMS</title>
|
|
319
|
+
</head>
|
|
320
|
+
<body>
|
|
321
|
+
<div id="root"></div>
|
|
322
|
+
<script type="module" src="/src/main.tsx"><\/script>
|
|
323
|
+
</body>
|
|
324
|
+
</html>
|
|
325
|
+
`;
|
|
326
|
+
|
|
299
327
|
// src/index.ts
|
|
300
|
-
var import_esbuild = __toModule(require("esbuild"));
|
|
301
328
|
var server;
|
|
302
329
|
var viteBuild = async ({
|
|
303
330
|
rootPath,
|
|
304
331
|
outputFolder,
|
|
305
332
|
publicFolder,
|
|
306
|
-
local,
|
|
333
|
+
local: l,
|
|
307
334
|
apiUrl
|
|
308
335
|
}) => {
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
const local = l;
|
|
337
|
+
const localBuild = l;
|
|
338
|
+
const node_env = JSON.stringify(process.env.NODE_ENV);
|
|
339
|
+
const generatedPath = import_path2.default.join(rootPath, ".tina/__generated__");
|
|
340
|
+
const outputPath = import_path2.default.join(rootPath, publicFolder, outputFolder);
|
|
341
|
+
const appCopyPath = import_path2.default.join(__dirname, "..", "appFiles");
|
|
342
|
+
const appRootPath = import_path2.default.join(generatedPath, "app");
|
|
343
|
+
const devHTMLPath = import_path2.default.join(outputPath, "index.html");
|
|
344
|
+
const prodHTMLPath = import_path2.default.join(appRootPath, "index.html");
|
|
345
|
+
const configPath = import_path2.default.join(rootPath, ".tina", "config");
|
|
346
|
+
const configPrebuildPath = import_path2.default.join(generatedPath, "prebuild", "config.js");
|
|
347
|
+
const prebuildConfig = {
|
|
348
|
+
root: import_path2.default.join(generatedPath, "prebuild"),
|
|
349
|
+
esbuild: {
|
|
350
|
+
target: "es2020"
|
|
351
|
+
},
|
|
352
|
+
mode: local ? "development" : "production",
|
|
353
|
+
build: {
|
|
354
|
+
outDir: import_path2.default.join(generatedPath, "prebuild"),
|
|
355
|
+
lib: {
|
|
356
|
+
entry: configPath,
|
|
357
|
+
fileName: () => {
|
|
358
|
+
return "config.js";
|
|
359
|
+
},
|
|
360
|
+
formats: ["es"]
|
|
361
|
+
},
|
|
362
|
+
rollupOptions: {
|
|
363
|
+
external: ["react", "react-dom", "tinacms", "next"]
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
logLevel: "silent"
|
|
367
|
+
};
|
|
368
|
+
await (0, import_vite.build)(prebuildConfig);
|
|
369
|
+
const alias = {
|
|
370
|
+
TINA_IMPORT: configPrebuildPath
|
|
371
|
+
};
|
|
340
372
|
const config = {
|
|
341
|
-
root,
|
|
342
|
-
base
|
|
373
|
+
root: appRootPath,
|
|
374
|
+
base: `/${outputFolder}/`,
|
|
343
375
|
mode: local ? "development" : "production",
|
|
344
|
-
plugins: [(0, import_plugin_react.default)(), viteTina()],
|
|
376
|
+
plugins: [(0, import_vite.splitVendorChunkPlugin)(), (0, import_plugin_react.default)(), viteTina()],
|
|
345
377
|
define: {
|
|
346
|
-
"process.env":
|
|
378
|
+
"process.env": "new Object()",
|
|
347
379
|
__API_URL__: `"${apiUrl}"`
|
|
348
380
|
},
|
|
381
|
+
esbuild: {
|
|
382
|
+
target: "es2020"
|
|
383
|
+
},
|
|
349
384
|
server: {
|
|
350
|
-
strictPort: true,
|
|
351
385
|
port: 5173,
|
|
352
386
|
fs: {
|
|
353
387
|
strict: false
|
|
354
388
|
}
|
|
355
389
|
},
|
|
356
390
|
resolve: {
|
|
357
|
-
alias
|
|
358
|
-
|
|
359
|
-
}
|
|
391
|
+
alias,
|
|
392
|
+
dedupe: ["graphql"]
|
|
360
393
|
},
|
|
361
394
|
build: {
|
|
362
395
|
sourcemap: true,
|
|
363
|
-
outDir,
|
|
396
|
+
outDir: outputPath,
|
|
364
397
|
emptyOutDir: false
|
|
365
398
|
},
|
|
366
399
|
logLevel: "silent"
|
|
367
400
|
};
|
|
368
|
-
if (
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
401
|
+
if (true) {
|
|
402
|
+
await import_fs_extra.default.copy(appCopyPath, appRootPath);
|
|
403
|
+
} else {
|
|
404
|
+
await import_fs_extra.default.createSymlink(import_path2.default.join(appCopyPath, "src"), import_path2.default.join(appRootPath, "src"), "dir");
|
|
405
|
+
await import_fs_extra.default.createSymlink(import_path2.default.join(appCopyPath, "package.json"), import_path2.default.join(appRootPath, "package.json"), "file");
|
|
406
|
+
}
|
|
407
|
+
await execShellCommand(`npm --prefix ${appRootPath} i --legacy-peer-deps --omit=dev --no-package-lock`);
|
|
408
|
+
await import_fs_extra.default.outputFile(import_path2.default.join(outputPath, ".gitignore"), `index.html
|
|
409
|
+
assets/`);
|
|
410
|
+
if (localBuild) {
|
|
411
|
+
const replaceAll = (string, target, value) => {
|
|
412
|
+
const regex = new RegExp(target, "g");
|
|
413
|
+
return string.valueOf().replace(regex, value);
|
|
414
|
+
};
|
|
415
|
+
await import_fs_extra.default.outputFile(devHTMLPath, replaceAll(devHTML, "INSERT_OUTPUT_FOLDER_NAME", outputFolder));
|
|
377
416
|
if (server) {
|
|
378
417
|
await server.close();
|
|
379
418
|
}
|
|
380
419
|
server = await (0, import_vite.createServer)(config);
|
|
381
420
|
await server.listen();
|
|
382
|
-
await server.printUrls();
|
|
383
421
|
} else {
|
|
384
|
-
await import_fs_extra.default.
|
|
385
|
-
await import_fs_extra.default.copySync(prebuildPath, import_path2.default.join(outDir, "assets"));
|
|
422
|
+
await import_fs_extra.default.outputFile(prodHTMLPath, prodHTML);
|
|
386
423
|
await (0, import_vite.build)(config);
|
|
387
|
-
|
|
424
|
+
}
|
|
425
|
+
if (!node_env) {
|
|
426
|
+
delete process.env.NODE_ENV;
|
|
427
|
+
} else {
|
|
428
|
+
process.env.NODE_ENV = node_env;
|
|
388
429
|
}
|
|
389
430
|
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
".ogg": "file",
|
|
402
|
-
".otf": "file",
|
|
403
|
-
".png": "file",
|
|
404
|
-
".svg": "file",
|
|
405
|
-
".ttf": "file",
|
|
406
|
-
".wav": "file",
|
|
407
|
-
".webm": "file",
|
|
408
|
-
".webp": "file",
|
|
409
|
-
".woff": "file",
|
|
410
|
-
".woff2": "file",
|
|
411
|
-
".js": "jsx",
|
|
412
|
-
".jsx": "jsx",
|
|
413
|
-
".tsx": "tsx"
|
|
414
|
-
};
|
|
431
|
+
function execShellCommand(cmd) {
|
|
432
|
+
const exec = require("child_process").exec;
|
|
433
|
+
return new Promise((resolve, reject) => {
|
|
434
|
+
exec(cmd, (error, stdout, stderr) => {
|
|
435
|
+
if (error) {
|
|
436
|
+
reject(error);
|
|
437
|
+
}
|
|
438
|
+
resolve(stdout ? stdout : stderr);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}
|
|
415
442
|
// Annotate the CommonJS export names for ESM import in node:
|
|
416
443
|
0 && (module.exports = {
|
|
417
444
|
viteBuild
|