pastoria 1.0.15 → 1.2.0
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/build_command.d.ts +2 -0
- package/dist/build_command.d.ts.map +1 -0
- package/dist/build_command.js +13 -0
- package/dist/build_command.js.map +1 -0
- package/dist/devserver.d.ts.map +1 -1
- package/dist/devserver.js +1 -3
- package/dist/devserver.js.map +1 -1
- package/dist/filesystem.d.ts +188 -0
- package/dist/filesystem.d.ts.map +1 -0
- package/dist/filesystem.js +358 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/gen.d.ts +2 -0
- package/dist/gen.d.ts.map +1 -0
- package/dist/gen.js +19 -0
- package/dist/gen.js.map +1 -0
- package/dist/generate.d.ts +47 -50
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +747 -450
- package/dist/generate.js.map +1 -1
- package/dist/index.js +74 -10
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +6 -1
- package/dist/logger.js.map +1 -1
- package/dist/vite_plugin.js +1 -1
- package/dist/vite_plugin.js.map +1 -1
- package/package.json +8 -5
- package/templates/js_resource.ts +7 -1
- package/templates/router.tsx +187 -44
- package/CHANGELOG.md +0 -98
- package/src/build.ts +0 -306
- package/src/devserver.ts +0 -58
- package/src/generate.ts +0 -918
- package/src/index.ts +0 -40
- package/src/logger.ts +0 -12
- package/src/vite_plugin.ts +0 -109
- package/tsconfig.json +0 -21
package/src/build.ts
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import ParcelWatcher, {getEventsSince, writeSnapshot} from '@parcel/watcher';
|
|
2
|
-
import {spawn} from 'node:child_process';
|
|
3
|
-
import {access, readFile} from 'node:fs/promises';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import {IndentationText, Project} from 'ts-morph';
|
|
6
|
-
import {build} from 'vite';
|
|
7
|
-
import {
|
|
8
|
-
generatePastoriaArtifacts,
|
|
9
|
-
generatePastoriaExports,
|
|
10
|
-
PASTORIA_TAG_REGEX,
|
|
11
|
-
PastoriaMetadata,
|
|
12
|
-
} from './generate.js';
|
|
13
|
-
import {logger, logInfo} from './logger.js';
|
|
14
|
-
import {CLIENT_BUILD, createBuildConfig, SERVER_BUILD} from './vite_plugin.js';
|
|
15
|
-
|
|
16
|
-
enum PastoriaMakePhase {
|
|
17
|
-
PASTORIA_EXPORTS,
|
|
18
|
-
PASTORIA_ARTIFACTS,
|
|
19
|
-
RELAY,
|
|
20
|
-
GRATS,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const ALL_MAKE_PHASES = new Set([
|
|
24
|
-
PastoriaMakePhase.PASTORIA_EXPORTS,
|
|
25
|
-
PastoriaMakePhase.PASTORIA_ARTIFACTS,
|
|
26
|
-
PastoriaMakePhase.RELAY,
|
|
27
|
-
PastoriaMakePhase.GRATS,
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
const SNAPSHOT_PATH = '.pastoriainfo';
|
|
31
|
-
|
|
32
|
-
async function runCommand(command: string, args: string[]): Promise<void> {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const child = spawn(command, args, {
|
|
35
|
-
cwd: process.cwd(),
|
|
36
|
-
stdio: 'inherit', // Stream output to terminal
|
|
37
|
-
shell: true,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
child.on('exit', (code) => {
|
|
41
|
-
if (code === 0) {
|
|
42
|
-
resolve();
|
|
43
|
-
} else {
|
|
44
|
-
reject(new Error(`Command failed with exit code ${code}`));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
child.on('error', reject);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function runGratsCompiler(): Promise<void> {
|
|
53
|
-
const gratsPath = path.join(process.cwd(), 'node_modules', '.bin', 'grats');
|
|
54
|
-
await runCommand(gratsPath, []);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function runRelayCompiler(): Promise<void> {
|
|
58
|
-
const relayPath = path.join(
|
|
59
|
-
process.cwd(),
|
|
60
|
-
'node_modules',
|
|
61
|
-
'.bin',
|
|
62
|
-
'relay-compiler',
|
|
63
|
-
);
|
|
64
|
-
await runCommand(relayPath, ['--repersist']);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function fileMatchesPastoriaTags(filePath: string, content: string): boolean {
|
|
68
|
-
// Skip generated files
|
|
69
|
-
if (filePath.includes('__generated__')) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return PASTORIA_TAG_REGEX.test(content);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function fileMatchesGratsTags(filePath: string, content: string): boolean {
|
|
76
|
-
// Skip generated files
|
|
77
|
-
if (filePath.includes('__generated__')) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
// Match any Grats JSDoc tag
|
|
81
|
-
return /@gql\w+/.test(content);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function fileMatchesRelayImports(filePath: string, content: string): boolean {
|
|
85
|
-
// Skip generated files
|
|
86
|
-
if (filePath.includes('__generated__')) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
return (
|
|
90
|
-
/import\s+.*\s+from\s+['"]react-relay['"]/.test(content) ||
|
|
91
|
-
/import\s+.*\s+from\s+['"]relay-runtime['"]/.test(content)
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async function requiredMakePhasesForChanges(
|
|
96
|
-
events: Array<{type: string; path: string}>,
|
|
97
|
-
): Promise<Set<PastoriaMakePhase>> {
|
|
98
|
-
let makePhases = new Set<PastoriaMakePhase>();
|
|
99
|
-
|
|
100
|
-
await Promise.all(
|
|
101
|
-
events.map(async (event) => {
|
|
102
|
-
const filePath = event.path;
|
|
103
|
-
|
|
104
|
-
// Skip non-TypeScript/TSX files
|
|
105
|
-
if (!filePath.match(/\.(ts|tsx)$/)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// For delete events, we can't read content, so assume it might affect all pipelines
|
|
110
|
-
if (event.type === 'delete') {
|
|
111
|
-
makePhases = ALL_MAKE_PHASES;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Read file content for create/update events
|
|
116
|
-
try {
|
|
117
|
-
const content = await readFile(filePath, 'utf-8');
|
|
118
|
-
|
|
119
|
-
if (fileMatchesPastoriaTags(filePath, content)) {
|
|
120
|
-
makePhases.add(PastoriaMakePhase.PASTORIA_EXPORTS);
|
|
121
|
-
makePhases.add(PastoriaMakePhase.PASTORIA_ARTIFACTS);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (fileMatchesGratsTags(filePath, content)) {
|
|
125
|
-
makePhases.add(PastoriaMakePhase.GRATS);
|
|
126
|
-
makePhases.add(PastoriaMakePhase.RELAY); // Relay depends on Grats schema
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (fileMatchesRelayImports(filePath, content)) {
|
|
130
|
-
makePhases.add(PastoriaMakePhase.RELAY);
|
|
131
|
-
}
|
|
132
|
-
} catch {
|
|
133
|
-
// If we can't read the file, assume it might affect all pipelines
|
|
134
|
-
makePhases = ALL_MAKE_PHASES;
|
|
135
|
-
}
|
|
136
|
-
}),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
return makePhases;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function requiredMakePhasesForArgs(steps: string[]): Set<PastoriaMakePhase> {
|
|
143
|
-
const validSteps = new Set(['schema', 'relay', 'router']);
|
|
144
|
-
const needs = new Set<PastoriaMakePhase>();
|
|
145
|
-
|
|
146
|
-
for (const step of steps) {
|
|
147
|
-
if (!validSteps.has(step)) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Invalid build step: ${step}. Valid steps are: schema, relay, router`,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
switch (step) {
|
|
154
|
-
case 'schema':
|
|
155
|
-
needs.add(PastoriaMakePhase.GRATS);
|
|
156
|
-
break;
|
|
157
|
-
case 'relay':
|
|
158
|
-
needs.add(PastoriaMakePhase.RELAY);
|
|
159
|
-
|
|
160
|
-
break;
|
|
161
|
-
case 'router':
|
|
162
|
-
needs.add(PastoriaMakePhase.PASTORIA_EXPORTS);
|
|
163
|
-
needs.add(PastoriaMakePhase.PASTORIA_ARTIFACTS);
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return needs;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async function executeBuildSteps(
|
|
172
|
-
project: Project,
|
|
173
|
-
needs: Set<PastoriaMakePhase>,
|
|
174
|
-
): Promise<boolean> {
|
|
175
|
-
let rebuiltAnything = false;
|
|
176
|
-
let cachedMetadata: PastoriaMetadata | undefined = undefined;
|
|
177
|
-
|
|
178
|
-
if (needs.has(PastoriaMakePhase.PASTORIA_EXPORTS)) {
|
|
179
|
-
logInfo('Running Pastoria exports generation...');
|
|
180
|
-
cachedMetadata = await generatePastoriaExports(project);
|
|
181
|
-
rebuiltAnything = true;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (needs.has(PastoriaMakePhase.GRATS)) {
|
|
185
|
-
logInfo('Running Grats compiler...');
|
|
186
|
-
await runGratsCompiler();
|
|
187
|
-
rebuiltAnything = true;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (needs.has(PastoriaMakePhase.RELAY)) {
|
|
191
|
-
logInfo('Running Relay compiler...');
|
|
192
|
-
await runRelayCompiler();
|
|
193
|
-
rebuiltAnything = true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (needs.has(PastoriaMakePhase.PASTORIA_ARTIFACTS)) {
|
|
197
|
-
logInfo('Running Pastoria artifacts generation...');
|
|
198
|
-
await generatePastoriaArtifacts(project, cachedMetadata);
|
|
199
|
-
rebuiltAnything = true;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return rebuiltAnything;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export async function createBuild(
|
|
206
|
-
steps: string[],
|
|
207
|
-
opts: {
|
|
208
|
-
alwaysMake: boolean;
|
|
209
|
-
release: boolean;
|
|
210
|
-
watch?: boolean;
|
|
211
|
-
},
|
|
212
|
-
) {
|
|
213
|
-
if (opts.watch && opts.release) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
'Cannot use --watch and --release together. Watch mode is for development only.',
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const project = new Project({
|
|
220
|
-
tsConfigFilePath: path.join(process.cwd(), 'tsconfig.json'),
|
|
221
|
-
manipulationSettings: {
|
|
222
|
-
indentationText: IndentationText.TwoSpaces,
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const cwd = process.cwd();
|
|
227
|
-
let makePhases = new Set<PastoriaMakePhase>();
|
|
228
|
-
|
|
229
|
-
// If specific steps are provided, override automatic inference
|
|
230
|
-
if (steps.length > 0) {
|
|
231
|
-
makePhases = makePhases.union(requiredMakePhasesForArgs(steps));
|
|
232
|
-
} else if (opts.alwaysMake) {
|
|
233
|
-
makePhases = ALL_MAKE_PHASES;
|
|
234
|
-
}
|
|
235
|
-
// Use @parcel/watcher to get changes since last snapshot
|
|
236
|
-
else {
|
|
237
|
-
try {
|
|
238
|
-
// Check if snapshot exists - if not, do a full build
|
|
239
|
-
await access(SNAPSHOT_PATH);
|
|
240
|
-
|
|
241
|
-
// Get events since last snapshot
|
|
242
|
-
const events = await getEventsSince(cwd, SNAPSHOT_PATH);
|
|
243
|
-
|
|
244
|
-
if (events.length > 0) {
|
|
245
|
-
// Analyze which files changed and determine what needs to be rebuilt
|
|
246
|
-
makePhases = makePhases.union(
|
|
247
|
-
await requiredMakePhasesForChanges(events),
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
} catch (err) {
|
|
251
|
-
// No snapshot exists yet, or error reading it - do a full build
|
|
252
|
-
makePhases = ALL_MAKE_PHASES;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Execute build pipeline conditionally
|
|
257
|
-
await executeBuildSteps(project, makePhases);
|
|
258
|
-
|
|
259
|
-
// Write snapshot for next incremental build
|
|
260
|
-
await writeSnapshot(cwd, SNAPSHOT_PATH);
|
|
261
|
-
|
|
262
|
-
if (opts.release) {
|
|
263
|
-
await build({
|
|
264
|
-
...createBuildConfig(CLIENT_BUILD),
|
|
265
|
-
configFile: false,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
await build({
|
|
269
|
-
...createBuildConfig(SERVER_BUILD),
|
|
270
|
-
configFile: false,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Start watch mode if requested
|
|
275
|
-
if (opts.watch) {
|
|
276
|
-
logInfo('Watching for changes...');
|
|
277
|
-
|
|
278
|
-
const subscription = await ParcelWatcher.subscribe(
|
|
279
|
-
cwd,
|
|
280
|
-
async (err, events) => {
|
|
281
|
-
if (err) {
|
|
282
|
-
logger.error('Watch error!', {error: err});
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Analyze which files changed and determine what needs to be rebuilt
|
|
287
|
-
const rebuiltAnything = await executeBuildSteps(
|
|
288
|
-
project,
|
|
289
|
-
await requiredMakePhasesForChanges(events),
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
if (rebuiltAnything) {
|
|
293
|
-
// Write snapshot after successful rebuild
|
|
294
|
-
await writeSnapshot(cwd, SNAPSHOT_PATH);
|
|
295
|
-
logInfo('Rebuild complete. Watching for changes...');
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
// Keep the process running
|
|
301
|
-
process.on('SIGINT', async () => {
|
|
302
|
-
await subscription.unsubscribe();
|
|
303
|
-
process.exit(0);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
package/src/devserver.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import cookieParser from 'cookie-parser';
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import {readFile} from 'node:fs/promises';
|
|
5
|
-
import {loadConfig, PastoriaConfig} from 'pastoria-config';
|
|
6
|
-
import pc from 'picocolors';
|
|
7
|
-
import {createServer as createViteServer, type Manifest} from 'vite';
|
|
8
|
-
import {logInfo} from './logger.js';
|
|
9
|
-
import {CLIENT_BUILD, createBuildConfig} from './vite_plugin.js';
|
|
10
|
-
|
|
11
|
-
interface PersistedQueries {
|
|
12
|
-
[hash: string]: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface ServerEntry {
|
|
16
|
-
createHandler(
|
|
17
|
-
persistedQueries: PersistedQueries,
|
|
18
|
-
config: Required<PastoriaConfig>,
|
|
19
|
-
manifest?: Manifest,
|
|
20
|
-
): express.Router;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function startDevserver(opts: {port: string}) {
|
|
24
|
-
dotenv.config();
|
|
25
|
-
|
|
26
|
-
const buildConfig = createBuildConfig(CLIENT_BUILD);
|
|
27
|
-
const vite = await createViteServer({
|
|
28
|
-
...buildConfig,
|
|
29
|
-
configFile: false,
|
|
30
|
-
server: {middlewareMode: true},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const config = await loadConfig();
|
|
34
|
-
|
|
35
|
-
const app = express();
|
|
36
|
-
app.use(cookieParser());
|
|
37
|
-
app.use(vite.middlewares);
|
|
38
|
-
app.use(async (req, res, next) => {
|
|
39
|
-
const persistedQueries = JSON.parse(
|
|
40
|
-
await readFile('__generated__/router/persisted_queries.json', 'utf-8'),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const {createHandler} = (await vite.ssrLoadModule(
|
|
44
|
-
'virtual:pastoria-entry-server.tsx',
|
|
45
|
-
)) as ServerEntry;
|
|
46
|
-
|
|
47
|
-
const handler = createHandler(persistedQueries, config);
|
|
48
|
-
handler(req, res, next);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
app.listen(Number(opts.port), (err) => {
|
|
52
|
-
if (err) {
|
|
53
|
-
console.error(err);
|
|
54
|
-
} else {
|
|
55
|
-
logInfo(pc.cyan(`Listening on port ${opts.port}!`));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|