@alloy-js/core 0.19.0-dev.12 → 0.19.0-dev.3
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/src/components/index.d.ts +0 -4
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +0 -4
- package/dist/src/components/stc/index.d.ts +0 -4
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +0 -4
- package/dist/src/context/source-directory.d.ts +3 -3
- package/dist/src/context/source-directory.d.ts.map +1 -1
- package/dist/src/context/source-file.d.ts +0 -4
- package/dist/src/context/source-file.d.ts.map +1 -1
- package/dist/src/debug.d.ts.map +1 -1
- package/dist/src/debug.js +1 -4
- package/dist/src/index.browser.d.ts +1 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.browser.js +2 -2
- package/dist/src/render.d.ts +2 -10
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +1 -20
- package/dist/src/scheduler.d.ts +0 -6
- package/dist/src/scheduler.d.ts.map +1 -1
- package/dist/src/scheduler.js +0 -36
- package/dist/src/write-output.browser.d.ts +2 -0
- package/dist/src/write-output.browser.d.ts.map +1 -0
- package/dist/src/write-output.browser.js +4 -0
- package/dist/src/write-output.d.ts +1 -1
- package/dist/src/write-output.d.ts.map +1 -1
- package/dist/src/write-output.js +21 -40
- package/dist/test/components/source-file.test.d.ts.map +1 -1
- package/dist/test/rendering/formatting.test.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +54 -60
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/index.tsx +0 -4
- package/src/components/stc/index.ts +0 -4
- package/src/context/source-directory.ts +3 -5
- package/src/context/source-file.ts +0 -5
- package/src/debug.ts +1 -4
- package/src/index.browser.ts +1 -1
- package/src/render.ts +5 -44
- package/src/scheduler.ts +0 -39
- package/src/write-output.browser.ts +4 -0
- package/src/write-output.ts +19 -49
- package/temp/api.json +423 -1886
- package/test/components/source-file.test.tsx +2 -5
- package/test/rendering/formatting.test.tsx +3 -9
- package/testing/extend-expect.ts +58 -74
- package/testing/vitest.d.ts +0 -4
- package/dist/src/components/AppendFile.d.ts +0 -90
- package/dist/src/components/AppendFile.d.ts.map +0 -1
- package/dist/src/components/AppendFile.js +0 -226
- package/dist/src/components/CopyFile.d.ts +0 -12
- package/dist/src/components/CopyFile.d.ts.map +0 -1
- package/dist/src/components/CopyFile.js +0 -15
- package/dist/src/components/TemplateFile.d.ts +0 -84
- package/dist/src/components/TemplateFile.d.ts.map +0 -1
- package/dist/src/components/TemplateFile.js +0 -133
- package/dist/src/components/UpdateFile.d.ts +0 -34
- package/dist/src/components/UpdateFile.d.ts.map +0 -1
- package/dist/src/components/UpdateFile.js +0 -66
- package/dist/src/host/alloy-host.browser.d.ts +0 -11
- package/dist/src/host/alloy-host.browser.d.ts.map +0 -1
- package/dist/src/host/alloy-host.browser.js +0 -31
- package/dist/src/host/alloy-host.d.ts +0 -11
- package/dist/src/host/alloy-host.d.ts.map +0 -1
- package/dist/src/host/alloy-host.js +0 -143
- package/dist/src/host/interface.d.ts +0 -144
- package/dist/src/host/interface.d.ts.map +0 -1
- package/dist/src/host/interface.js +0 -1
- package/dist/src/resource.d.ts +0 -80
- package/dist/src/resource.d.ts.map +0 -1
- package/dist/src/resource.js +0 -118
- package/dist/test/components/append-file.test.d.ts +0 -2
- package/dist/test/components/append-file.test.d.ts.map +0 -1
- package/dist/test/components/append-file.test.js +0 -281
- package/dist/test/components/copy-file.test.d.ts +0 -2
- package/dist/test/components/copy-file.test.d.ts.map +0 -1
- package/dist/test/components/copy-file.test.js +0 -94
- package/dist/test/components/template-file.test.d.ts +0 -2
- package/dist/test/components/template-file.test.d.ts.map +0 -1
- package/dist/test/components/template-file.test.js +0 -133
- package/dist/test/components/update-file.test.d.ts +0 -2
- package/dist/test/components/update-file.test.d.ts.map +0 -1
- package/dist/test/components/update-file.test.js +0 -169
- package/src/components/AppendFile.tsx +0 -294
- package/src/components/CopyFile.tsx +0 -29
- package/src/components/TemplateFile.tsx +0 -193
- package/src/components/UpdateFile.tsx +0 -86
- package/src/host/alloy-host.browser.ts +0 -56
- package/src/host/alloy-host.ts +0 -160
- package/src/host/interface.ts +0 -153
- package/src/resource.ts +0 -152
- package/test/components/append-file.test.tsx +0 -275
- package/test/components/copy-file.test.tsx +0 -98
- package/test/components/template-file.test.tsx +0 -127
- package/test/components/update-file.test.tsx +0 -214
package/dist/src/resource.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { isRef, reactive } from "@vue/reactivity";
|
|
2
|
-
import { AlloyHost } from "./host/alloy-host.js";
|
|
3
|
-
import { effect } from "./reactivity.js";
|
|
4
|
-
import { trackPromise } from "./scheduler.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents an external resource fetched asynchronously.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create a resource that fetches data asynchronously.
|
|
12
|
-
*
|
|
13
|
-
* This function has two overloads:
|
|
14
|
-
* 1. Simple fetcher - fetches data once when the resource is created
|
|
15
|
-
* 2. Reactive fetcher - fetches data when a reactive source changes
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* // Simple usage - fetches data once when created
|
|
20
|
-
* const userResource = createResource(async () => {
|
|
21
|
-
* const response = await fetch('/api/user');
|
|
22
|
-
* return response.json();
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Access the resource state
|
|
26
|
-
* console.log(userResource.loading); // true initially
|
|
27
|
-
* console.log(userResource.data); // null initially
|
|
28
|
-
* console.log(userResource.error); // null initially
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // Reactive usage - fetches data when the ref changes
|
|
34
|
-
* const userId = ref(1);
|
|
35
|
-
*
|
|
36
|
-
* const userResource = createResource(userId, async (id) => {
|
|
37
|
-
* const response = await fetch(`/api/user/${id}`);
|
|
38
|
-
* return response.json();
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* // The fetcher will be called automatically when userId changes
|
|
42
|
-
* userId.value = 2; // This triggers a new fetch with id=2
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Create a resource that fetches data asynchronously based on a reactive source.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export function createResource(fetcherOrSource, maybeFetcher) {
|
|
51
|
-
let getter = null;
|
|
52
|
-
let fetcher;
|
|
53
|
-
if (arguments.length === 1) {
|
|
54
|
-
fetcher = fetcherOrSource;
|
|
55
|
-
} else {
|
|
56
|
-
getter = fetcherOrSource;
|
|
57
|
-
fetcher = maybeFetcher;
|
|
58
|
-
}
|
|
59
|
-
const resource = reactive({
|
|
60
|
-
data: null,
|
|
61
|
-
loading: true,
|
|
62
|
-
error: null
|
|
63
|
-
});
|
|
64
|
-
if (!getter) {
|
|
65
|
-
const promise = fetcher();
|
|
66
|
-
trackPromise(promise.then(result => {
|
|
67
|
-
resource.data = result;
|
|
68
|
-
resource.loading = false;
|
|
69
|
-
}).catch(error => {
|
|
70
|
-
resource.error = error;
|
|
71
|
-
resource.loading = false;
|
|
72
|
-
}));
|
|
73
|
-
} else {
|
|
74
|
-
effect(() => {
|
|
75
|
-
let input;
|
|
76
|
-
if (isRef(getter)) {
|
|
77
|
-
input = getter.value;
|
|
78
|
-
} else {
|
|
79
|
-
input = getter();
|
|
80
|
-
}
|
|
81
|
-
const promise = fetcher(input);
|
|
82
|
-
trackPromise(promise);
|
|
83
|
-
promise.then(result => {
|
|
84
|
-
resource.data = result;
|
|
85
|
-
resource.loading = false;
|
|
86
|
-
}, error => {
|
|
87
|
-
resource.error = error;
|
|
88
|
-
resource.loading = false;
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return resource;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Create a resource that reads a file from the file system.
|
|
97
|
-
*
|
|
98
|
-
* This is a convenience function that creates a resource for reading file content
|
|
99
|
-
* using the AlloyHost file system API. The file is read as text when the resource
|
|
100
|
-
* is created.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* // Read a configuration file
|
|
105
|
-
* const configResource = createFileResource('./config.json');
|
|
106
|
-
*
|
|
107
|
-
* // Access the file content
|
|
108
|
-
* if (!configResource.loading && !configResource.error) {
|
|
109
|
-
* const configText = configResource.data; // string content of the file
|
|
110
|
-
* const config = JSON.parse(configText);
|
|
111
|
-
* }
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
export function createFileResource(path) {
|
|
115
|
-
return createResource(() => {
|
|
116
|
-
return AlloyHost.read(path).text();
|
|
117
|
-
});
|
|
118
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"append-file.test.d.ts","sourceRoot":"","sources":["../../../test/components/append-file.test.tsx"],"names":[],"mappings":"AAMA,OAAO,gCAAgC,CAAC"}
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { existsSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
-
import { tmpdir } from "os";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import { AppendFile, AppendRegion } from "../../src/components/AppendFile.js";
|
|
7
|
-
import { render, renderAsync } from "../../src/render.js";
|
|
8
|
-
import "../../testing/extend-expect.js";
|
|
9
|
-
import { d } from "../../testing/render.js";
|
|
10
|
-
describe("AppendFile", () => {
|
|
11
|
-
let testFilePath;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
// Create a unique temporary file path for each test
|
|
14
|
-
testFilePath = join(tmpdir(), `test-append-file-${Date.now()}.txt`);
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
// Clean up test file after each test
|
|
18
|
-
if (existsSync(testFilePath)) {
|
|
19
|
-
unlinkSync(testFilePath);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
it("should append content to end of file when no sigils present", async () => {
|
|
23
|
-
// Create initial file content
|
|
24
|
-
writeFileSync(testFilePath, "Initial content", "utf-8");
|
|
25
|
-
const result = _$createComponent(AppendFile, {
|
|
26
|
-
path: testFilePath,
|
|
27
|
-
get children() {
|
|
28
|
-
return _$createComponent(AppendRegion, {
|
|
29
|
-
id: "append",
|
|
30
|
-
children: "New content"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
await expect(result).toRenderToAsync("Initial content\nNew content");
|
|
35
|
-
});
|
|
36
|
-
it("should append content to end of file when no sigils present with no explicit append region", async () => {
|
|
37
|
-
// Create initial file content
|
|
38
|
-
writeFileSync(testFilePath, "Initial content", "utf-8");
|
|
39
|
-
const result = _$createComponent(AppendFile, {
|
|
40
|
-
path: testFilePath,
|
|
41
|
-
children: "New content"
|
|
42
|
-
});
|
|
43
|
-
await expect(result).toRenderToAsync("Initial content\nNew content");
|
|
44
|
-
});
|
|
45
|
-
it("should append content within region sigils", async () => {
|
|
46
|
-
const initialContent = d`
|
|
47
|
-
Header content
|
|
48
|
-
<!-- alloy-main-start -->
|
|
49
|
-
<!-- alloy-main-end -->
|
|
50
|
-
Footer content
|
|
51
|
-
`;
|
|
52
|
-
writeFileSync(testFilePath, initialContent, "utf-8");
|
|
53
|
-
const result = _$createComponent(AppendFile, {
|
|
54
|
-
path: testFilePath,
|
|
55
|
-
regions: ["main"],
|
|
56
|
-
get children() {
|
|
57
|
-
return _$createComponent(AppendRegion, {
|
|
58
|
-
id: "main",
|
|
59
|
-
children: "New main content"
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
await expect(result).toRenderToAsync(d`
|
|
64
|
-
Header content
|
|
65
|
-
<!-- alloy-main-start -->
|
|
66
|
-
New main content
|
|
67
|
-
<!-- alloy-main-end -->
|
|
68
|
-
Footer content
|
|
69
|
-
`);
|
|
70
|
-
});
|
|
71
|
-
it("should handle multiple regions", async () => {
|
|
72
|
-
const initialContent = d`
|
|
73
|
-
<!-- alloy-header-start -->
|
|
74
|
-
<!-- alloy-header-end -->
|
|
75
|
-
Main content
|
|
76
|
-
<!-- alloy-footer-start -->
|
|
77
|
-
<!-- alloy-footer-end -->
|
|
78
|
-
`;
|
|
79
|
-
writeFileSync(testFilePath, initialContent, "utf-8");
|
|
80
|
-
const result = _$createComponent(AppendFile, {
|
|
81
|
-
path: testFilePath,
|
|
82
|
-
regions: ["header", "footer"],
|
|
83
|
-
get children() {
|
|
84
|
-
return [_$createComponent(AppendRegion, {
|
|
85
|
-
id: "header",
|
|
86
|
-
children: "Header text"
|
|
87
|
-
}), _$createComponent(AppendRegion, {
|
|
88
|
-
id: "footer",
|
|
89
|
-
children: "Footer text"
|
|
90
|
-
})];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
await expect(result).toRenderToAsync(d`
|
|
94
|
-
<!-- alloy-header-start -->
|
|
95
|
-
Header text
|
|
96
|
-
<!-- alloy-header-end -->
|
|
97
|
-
Main content
|
|
98
|
-
<!-- alloy-footer-start -->
|
|
99
|
-
Footer text
|
|
100
|
-
<!-- alloy-footer-end -->
|
|
101
|
-
`);
|
|
102
|
-
});
|
|
103
|
-
it("should preserve existing content and append new content", async () => {
|
|
104
|
-
const initialContent = d`
|
|
105
|
-
Header
|
|
106
|
-
<!-- alloy-main-start -->
|
|
107
|
-
Existing content
|
|
108
|
-
<!-- alloy-main-end -->
|
|
109
|
-
Footer
|
|
110
|
-
`;
|
|
111
|
-
writeFileSync(testFilePath, initialContent, "utf-8");
|
|
112
|
-
const result = _$createComponent(AppendFile, {
|
|
113
|
-
path: testFilePath,
|
|
114
|
-
regions: ["main"],
|
|
115
|
-
get children() {
|
|
116
|
-
return _$createComponent(AppendRegion, {
|
|
117
|
-
id: "main",
|
|
118
|
-
children: "New appended content"
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
await expect(result).toRenderToAsync(d`
|
|
123
|
-
Header
|
|
124
|
-
<!-- alloy-main-start -->
|
|
125
|
-
Existing content
|
|
126
|
-
New appended content
|
|
127
|
-
<!-- alloy-main-end -->
|
|
128
|
-
Footer
|
|
129
|
-
`);
|
|
130
|
-
});
|
|
131
|
-
it("should use content prop instead of children", async () => {
|
|
132
|
-
writeFileSync(testFilePath, "Start ", "utf-8");
|
|
133
|
-
const result = _$createComponent(AppendFile, {
|
|
134
|
-
path: testFilePath,
|
|
135
|
-
get children() {
|
|
136
|
-
return _$createComponent(AppendRegion, {
|
|
137
|
-
id: "append",
|
|
138
|
-
content: "End"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
await expect(result).toRenderToAsync("Start\nEnd");
|
|
143
|
-
});
|
|
144
|
-
it("should default to 'append' region when no regions specified", async () => {
|
|
145
|
-
writeFileSync(testFilePath, "Content", "utf-8");
|
|
146
|
-
const result = _$createComponent(AppendFile, {
|
|
147
|
-
path: testFilePath,
|
|
148
|
-
get children() {
|
|
149
|
-
return _$createComponent(AppendRegion, {
|
|
150
|
-
id: "append",
|
|
151
|
-
children: "default region"
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
await expect(result).toRenderToAsync("Content\ndefault region");
|
|
156
|
-
});
|
|
157
|
-
it("should throw error when region is missing corresponding AppendRegion", async () => {
|
|
158
|
-
writeFileSync(testFilePath, "content", "utf-8");
|
|
159
|
-
expect(() => render(_$createComponent(AppendFile, {
|
|
160
|
-
path: testFilePath,
|
|
161
|
-
regions: ["missing"],
|
|
162
|
-
get children() {
|
|
163
|
-
return _$createComponent(AppendRegion, {
|
|
164
|
-
id: "append",
|
|
165
|
-
children: "content"
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}))).toThrow('Region "missing" specified but no corresponding AppendRegion child found');
|
|
169
|
-
});
|
|
170
|
-
it("should throw error when AppendRegion has neither children nor content", async () => {
|
|
171
|
-
writeFileSync(testFilePath, "content", "utf-8");
|
|
172
|
-
expect(() => render(_$createComponent(AppendFile, {
|
|
173
|
-
path: testFilePath,
|
|
174
|
-
get children() {
|
|
175
|
-
return _$createComponent(AppendRegion, {
|
|
176
|
-
id: "append"
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}))).toThrow('AppendRegion "append" must have either children or content');
|
|
180
|
-
});
|
|
181
|
-
it("should throw error when region has missing start sigil", async () => {
|
|
182
|
-
const contentWithOnlyEnd = d`
|
|
183
|
-
Content
|
|
184
|
-
<!-- alloy-incomplete-end -->
|
|
185
|
-
`;
|
|
186
|
-
writeFileSync(testFilePath, contentWithOnlyEnd, "utf-8");
|
|
187
|
-
const result = _$createComponent(AppendFile, {
|
|
188
|
-
path: testFilePath,
|
|
189
|
-
regions: ["incomplete"],
|
|
190
|
-
get children() {
|
|
191
|
-
return _$createComponent(AppendRegion, {
|
|
192
|
-
id: "incomplete",
|
|
193
|
-
children: "content"
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// Should insert before the end sigil
|
|
199
|
-
await expect(result).toRenderToAsync(d`
|
|
200
|
-
Content
|
|
201
|
-
content
|
|
202
|
-
<!-- alloy-incomplete-end -->
|
|
203
|
-
`);
|
|
204
|
-
});
|
|
205
|
-
it("should throw error when region has missing end sigil", async () => {
|
|
206
|
-
const contentWithOnlyStart = d`
|
|
207
|
-
Content
|
|
208
|
-
<!-- alloy-incomplete-start -->
|
|
209
|
-
`;
|
|
210
|
-
writeFileSync(testFilePath, contentWithOnlyStart, "utf-8");
|
|
211
|
-
await expect(async () => renderAsync(_$createComponent(AppendFile, {
|
|
212
|
-
path: testFilePath,
|
|
213
|
-
regions: ["incomplete"],
|
|
214
|
-
get children() {
|
|
215
|
-
return _$createComponent(AppendRegion, {
|
|
216
|
-
id: "incomplete",
|
|
217
|
-
children: "content"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}))).rejects.toThrow('Region "incomplete" has start sigil but no corresponding end sigil');
|
|
221
|
-
});
|
|
222
|
-
it("should handle complex nested content", async () => {
|
|
223
|
-
const initialContent = d`
|
|
224
|
-
<!-- alloy-config-start -->
|
|
225
|
-
<!-- alloy-config-end -->
|
|
226
|
-
`;
|
|
227
|
-
writeFileSync(testFilePath, initialContent, "utf-8");
|
|
228
|
-
const jsonContent = d`
|
|
229
|
-
{
|
|
230
|
-
"newProperty": "value",
|
|
231
|
-
"nested": {
|
|
232
|
-
"key": "data"
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
`;
|
|
236
|
-
const result = _$createComponent(AppendFile, {
|
|
237
|
-
path: testFilePath,
|
|
238
|
-
regions: ["config"],
|
|
239
|
-
get children() {
|
|
240
|
-
return _$createComponent(AppendRegion, {
|
|
241
|
-
id: "config",
|
|
242
|
-
children: jsonContent
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
await expect(result).toRenderToAsync(d`
|
|
247
|
-
<!-- alloy-config-start -->
|
|
248
|
-
{
|
|
249
|
-
"newProperty": "value",
|
|
250
|
-
"nested": {
|
|
251
|
-
"key": "data"
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
<!-- alloy-config-end -->
|
|
255
|
-
`);
|
|
256
|
-
});
|
|
257
|
-
it("should preserve indentation level of the end sigil", async () => {
|
|
258
|
-
const initialContent = d`
|
|
259
|
-
base
|
|
260
|
-
<!-- alloy-indented-start -->
|
|
261
|
-
<!-- alloy-indented-end -->
|
|
262
|
-
`;
|
|
263
|
-
writeFileSync(testFilePath, initialContent, "utf-8");
|
|
264
|
-
const result = _$createComponent(AppendFile, {
|
|
265
|
-
path: testFilePath,
|
|
266
|
-
regions: ["indented"],
|
|
267
|
-
get children() {
|
|
268
|
-
return _$createComponent(AppendRegion, {
|
|
269
|
-
id: "indented",
|
|
270
|
-
children: "new content"
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
await expect(result).toRenderToAsync(d`
|
|
275
|
-
base
|
|
276
|
-
<!-- alloy-indented-start -->
|
|
277
|
-
new content
|
|
278
|
-
<!-- alloy-indented-end -->
|
|
279
|
-
`);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"copy-file.test.d.ts","sourceRoot":"","sources":["../../../test/components/copy-file.test.tsx"],"names":[],"mappings":"AAQA,OAAO,gCAAgC,CAAC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
-
import { tmpdir } from "os";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import { CopyFile } from "../../src/components/CopyFile.js";
|
|
7
|
-
import { SourceDirectory } from "../../src/components/SourceDirectory.js";
|
|
8
|
-
import { render } from "../../src/render.js";
|
|
9
|
-
import { writeOutput } from "../../src/write-output.js";
|
|
10
|
-
import "../../testing/extend-expect.js";
|
|
11
|
-
describe("CopyFile", () => {
|
|
12
|
-
let testDir;
|
|
13
|
-
let sourceFile;
|
|
14
|
-
let targetFile;
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
// Create unique temporary paths for each test
|
|
17
|
-
testDir = tmpdir();
|
|
18
|
-
sourceFile = join(testDir, "source.txt");
|
|
19
|
-
targetFile = join(testDir, "target.txt");
|
|
20
|
-
});
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
// Clean up test files after each test
|
|
23
|
-
if (existsSync(sourceFile)) {
|
|
24
|
-
unlinkSync(sourceFile);
|
|
25
|
-
}
|
|
26
|
-
if (existsSync(targetFile)) {
|
|
27
|
-
unlinkSync(targetFile);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
it("should create copy file context with correct paths", async () => {
|
|
31
|
-
writeFileSync(sourceFile, "Hello, World!", "utf-8");
|
|
32
|
-
const result = _$createComponent(SourceDirectory, {
|
|
33
|
-
path: testDir,
|
|
34
|
-
get children() {
|
|
35
|
-
return _$createComponent(CopyFile, {
|
|
36
|
-
src: sourceFile,
|
|
37
|
-
path: "target.txt"
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const output = render(result);
|
|
42
|
-
await writeOutput(output);
|
|
43
|
-
expect(output.contents).toHaveLength(1);
|
|
44
|
-
const copyFileOutput = output.contents[0];
|
|
45
|
-
expect(copyFileOutput.kind).toBe("file");
|
|
46
|
-
expect(copyFileOutput.sourcePath).toBe(sourceFile);
|
|
47
|
-
expect(copyFileOutput.path).toBe(join(testDir, "target.txt"));
|
|
48
|
-
expect(existsSync(targetFile)).toBe(true);
|
|
49
|
-
const targetContent = readFileSync(targetFile, "utf-8");
|
|
50
|
-
expect(targetContent).toBe("Hello, World!");
|
|
51
|
-
});
|
|
52
|
-
it("should handle relative paths correctly", async () => {
|
|
53
|
-
// Create source file
|
|
54
|
-
writeFileSync(sourceFile, "Relative path test", "utf-8");
|
|
55
|
-
const result = _$createComponent(SourceDirectory, {
|
|
56
|
-
path: testDir,
|
|
57
|
-
get children() {
|
|
58
|
-
return _$createComponent(SourceDirectory, {
|
|
59
|
-
path: "subdir",
|
|
60
|
-
get children() {
|
|
61
|
-
return _$createComponent(CopyFile, {
|
|
62
|
-
src: sourceFile,
|
|
63
|
-
path: "nested-target.txt"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
const output = render(result);
|
|
70
|
-
|
|
71
|
-
// Find the copy file in the nested directory
|
|
72
|
-
const subdir = output.contents.find(item => item.kind === "directory" && item.path === join(testDir, "subdir"));
|
|
73
|
-
expect(subdir).toBeDefined();
|
|
74
|
-
if (subdir && subdir.kind === "directory") {
|
|
75
|
-
expect(subdir.contents).toHaveLength(1);
|
|
76
|
-
const copyFile = subdir.contents[0];
|
|
77
|
-
expect(copyFile.kind).toBe("file");
|
|
78
|
-
if (copyFile.kind === "file" && "sourcePath" in copyFile) {
|
|
79
|
-
expect(copyFile.sourcePath).toBe(sourceFile);
|
|
80
|
-
expect(copyFile.path).toBe(join(testDir, "subdir", "nested-target.txt"));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
it("should throw error when used without SourceDirectory context", () => {
|
|
85
|
-
// Create source file
|
|
86
|
-
writeFileSync(sourceFile, "Error test", "utf-8");
|
|
87
|
-
expect(() => {
|
|
88
|
-
render(_$createComponent(CopyFile, {
|
|
89
|
-
src: sourceFile,
|
|
90
|
-
path: "target.txt"
|
|
91
|
-
}));
|
|
92
|
-
}).toThrow("Copy file doesn't have parent directory");
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template-file.test.d.ts","sourceRoot":"","sources":["../../../test/components/template-file.test.tsx"],"names":[],"mappings":"AASA,OAAO,gCAAgC,CAAC"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { writeFileSync } from "fs";
|
|
3
|
-
import { tmpdir } from "os";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { TemplateFile, TemplateVariable } from "../../src/components/TemplateFile.js";
|
|
7
|
-
import { renderAsync } from "../../src/render.js";
|
|
8
|
-
import "../../testing/extend-expect.js";
|
|
9
|
-
import { d } from "../../testing/render.js";
|
|
10
|
-
describe("TemplateFile", () => {
|
|
11
|
-
it("should replace template variables with values", async () => {
|
|
12
|
-
// Create a temporary template file
|
|
13
|
-
const templatePath = join(tmpdir(), "test-template.txt");
|
|
14
|
-
const templateContent = "Hello {{ name }}! You are {{ age }} years old.";
|
|
15
|
-
writeFileSync(templatePath, templateContent);
|
|
16
|
-
const result = _$createComponent(TemplateFile, {
|
|
17
|
-
src: templatePath,
|
|
18
|
-
path: "output.txt",
|
|
19
|
-
get children() {
|
|
20
|
-
return [_$createComponent(TemplateVariable, {
|
|
21
|
-
name: "name",
|
|
22
|
-
value: "John"
|
|
23
|
-
}), _$createComponent(TemplateVariable, {
|
|
24
|
-
name: "age",
|
|
25
|
-
value: "25"
|
|
26
|
-
})];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
await expect(result).toRenderToAsync("Hello John! You are 25 years old.");
|
|
30
|
-
});
|
|
31
|
-
it("should handle template variables with children", async () => {
|
|
32
|
-
const templatePath = join(tmpdir(), "test-template-children.txt");
|
|
33
|
-
const templateContent = "Welcome {{ greeting }}!";
|
|
34
|
-
writeFileSync(templatePath, templateContent);
|
|
35
|
-
const result = _$createComponent(TemplateFile, {
|
|
36
|
-
src: templatePath,
|
|
37
|
-
path: "output.txt",
|
|
38
|
-
get children() {
|
|
39
|
-
return _$createComponent(TemplateVariable, {
|
|
40
|
-
name: "greeting",
|
|
41
|
-
children: "Hello World"
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
await expect(result).toRenderToAsync("Welcome Hello World!");
|
|
46
|
-
});
|
|
47
|
-
it("should handle complex templates with multiple variables", async () => {
|
|
48
|
-
const templatePath = join(tmpdir(), "test-complex-template.txt");
|
|
49
|
-
const templateContent = d`
|
|
50
|
-
Name: {{ name }}
|
|
51
|
-
Age: {{ age }}
|
|
52
|
-
Location: {{ location }}
|
|
53
|
-
Status: {{ status }}
|
|
54
|
-
`;
|
|
55
|
-
writeFileSync(templatePath, templateContent);
|
|
56
|
-
const result = _$createComponent(TemplateFile, {
|
|
57
|
-
src: templatePath,
|
|
58
|
-
path: "output.txt",
|
|
59
|
-
get children() {
|
|
60
|
-
return [_$createComponent(TemplateVariable, {
|
|
61
|
-
name: "name",
|
|
62
|
-
value: "Alice"
|
|
63
|
-
}), _$createComponent(TemplateVariable, {
|
|
64
|
-
name: "age",
|
|
65
|
-
children: "30"
|
|
66
|
-
}), _$createComponent(TemplateVariable, {
|
|
67
|
-
name: "location",
|
|
68
|
-
value: "New York"
|
|
69
|
-
}), _$createComponent(TemplateVariable, {
|
|
70
|
-
name: "status",
|
|
71
|
-
value: "Active"
|
|
72
|
-
})];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
await expect(result).toRenderToAsync(d`
|
|
76
|
-
Name: Alice
|
|
77
|
-
Age: 30
|
|
78
|
-
Location: New York
|
|
79
|
-
Status: Active
|
|
80
|
-
`);
|
|
81
|
-
});
|
|
82
|
-
it("should handle templates with whitespace around variable names", async () => {
|
|
83
|
-
const templatePath = join(tmpdir(), "test-whitespace-template.txt");
|
|
84
|
-
const templateContent = "Hello {{ name }}!";
|
|
85
|
-
writeFileSync(templatePath, templateContent);
|
|
86
|
-
const result = _$createComponent(TemplateFile, {
|
|
87
|
-
src: templatePath,
|
|
88
|
-
path: "output.txt",
|
|
89
|
-
get children() {
|
|
90
|
-
return _$createComponent(TemplateVariable, {
|
|
91
|
-
name: "name",
|
|
92
|
-
value: "Bob"
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
await expect(result).toRenderToAsync("Hello Bob!");
|
|
97
|
-
});
|
|
98
|
-
it("should throw error for missing template variables", async () => {
|
|
99
|
-
const templatePath = join(tmpdir(), "test-missing-var-template.txt");
|
|
100
|
-
const templateContent = "Hello {{ name }}! Your age is {{ age }}.";
|
|
101
|
-
writeFileSync(templatePath, templateContent);
|
|
102
|
-
await expect(async () => await renderAsync(_$createComponent(TemplateFile, {
|
|
103
|
-
src: templatePath,
|
|
104
|
-
path: "output.txt",
|
|
105
|
-
get children() {
|
|
106
|
-
return _$createComponent(TemplateVariable, {
|
|
107
|
-
name: "name",
|
|
108
|
-
value: "Charlie"
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}))).rejects.toThrow('Template variable "age" not found in TemplateVariable children');
|
|
112
|
-
});
|
|
113
|
-
it("should handle template with no variables", async () => {
|
|
114
|
-
const templatePath = join(tmpdir(), "test-no-vars-template.txt");
|
|
115
|
-
const templateContent = "This is just plain text with no variables.";
|
|
116
|
-
writeFileSync(templatePath, templateContent);
|
|
117
|
-
const result = _$createComponent(TemplateFile, {
|
|
118
|
-
src: templatePath,
|
|
119
|
-
path: "output.txt"
|
|
120
|
-
});
|
|
121
|
-
await expect(result).toRenderToAsync("This is just plain text with no variables.");
|
|
122
|
-
});
|
|
123
|
-
it("should handle empty template", async () => {
|
|
124
|
-
const templatePath = join(tmpdir(), "test-empty-template.txt");
|
|
125
|
-
const templateContent = "";
|
|
126
|
-
writeFileSync(templatePath, templateContent);
|
|
127
|
-
const result = _$createComponent(TemplateFile, {
|
|
128
|
-
src: templatePath,
|
|
129
|
-
path: "output.txt"
|
|
130
|
-
});
|
|
131
|
-
await expect(result).toRenderToAsync("");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update-file.test.d.ts","sourceRoot":"","sources":["../../../test/components/update-file.test.tsx"],"names":[],"mappings":"AAMA,OAAO,gCAAgC,CAAC"}
|