-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove metro and add standalone mode
- Loading branch information
1 parent
dd304fa
commit 29568d1
Showing
16 changed files
with
343 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@diacritic/core": patch | ||
"@diacritic/detector": patch | ||
"@diacritic/parser": patch | ||
"@diacritic/react": patch | ||
"@diacritic/runtime": patch | ||
"@diacritic/utilities": patch | ||
--- | ||
|
||
Remove metro and add standalone mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { DiacriticGenerationOptions, DiacriticOptions } from "./utilities/types"; | ||
|
||
import { existsSync, readFileSync } from "node:fs"; | ||
import { EOL } from "node:os"; | ||
import { dirname, resolve } from "node:path"; | ||
|
||
import { createFunctionFromEntry, createRegistry, generateTypes } from "./utilities/generator"; | ||
import { createFolderAndFile } from "./utilities/loader"; | ||
import { ResourceGraph } from "./utilities/resource"; | ||
import { watchResources } from "./utilities/watcher"; | ||
|
||
type StartDiacriticOptions = DiacriticOptions & { | ||
runtimeGeneration: DiacriticGenerationOptions; | ||
}; | ||
|
||
export async function startDiacritic({ | ||
defaultLanguage, | ||
generation, | ||
languages, | ||
parser, | ||
resources, | ||
runtimeGeneration, | ||
}: StartDiacriticOptions) { | ||
const resourceGraph = new ResourceGraph(languages, resources); | ||
|
||
const unsubscribe = await watchResources({ | ||
resourceGraph, | ||
resources, | ||
onChange: async (event) => { | ||
const shouldCreateRegistry = !event || event.type === "create" || event.type === "delete"; | ||
|
||
await generateTypes({ defaultLanguage, generation, languages, parser, resourceGraph }); | ||
|
||
if (shouldCreateRegistry) { | ||
const registry = createRegistry(defaultLanguage, languages, resourceGraph.allNamespaces(), "./"); | ||
await createFolderAndFile(runtimeGeneration.outFile, registry); | ||
} | ||
|
||
for (const language of languages) { | ||
for (const namespace of resourceGraph.allNamespaces()) { | ||
const files = resourceGraph.allEntriesForLanguageAndNamespace(language, namespace) | ||
.filter(file => existsSync(file)) | ||
.map(file => readFileSync(file, "utf-8")); | ||
|
||
const entries = files.flatMap(item => parser.convertFile(item)); | ||
const functions = entries.map(item => createFunctionFromEntry(item)); | ||
|
||
functions.unshift( | ||
...(runtimeGeneration?.banner ?? []), | ||
`import type { Proxy } from "@diacritic/runtime"`, | ||
"", | ||
); | ||
|
||
const dir = dirname(runtimeGeneration.outFile); | ||
const out = resolve(dir, `${language}/${namespace}.ts`); | ||
|
||
await createFolderAndFile(out, functions.join(EOL)); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
process.on("SIGINT", async () => unsubscribe()); | ||
process.on("SIGTERM", async () => unsubscribe()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.