-
-
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.
- Loading branch information
Showing
10 changed files
with
149 additions
and
58 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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ node_modules | |
coverage | ||
.DS_Store | ||
.idea | ||
playground/**/bun.lockb | ||
playground/**/deno.lock | ||
|
||
*.log | ||
*.swp | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
coverage | ||
examples | ||
playground | ||
deno.lock | ||
.* | ||
*.log | ||
|
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// @ts-ignore: this is example | ||
import { getHeaderLanguages } from "@intlify/utils"; | ||
import { getHeaderLanguages } from '@intlify/utils' | ||
|
||
const port = 8125; | ||
const port = 8125 | ||
Deno.serve({ | ||
port, | ||
}, (req: Request) => { | ||
const languages = getHeaderLanguages(req); | ||
return new Response(`detect accpect-language: ${languages}`); | ||
}); | ||
console.log(`server listening on ${port}`); | ||
const languages = getHeaderLanguages(req) | ||
return new Response(`detect accpect-language: ${languages}`) | ||
}) | ||
console.log(`server listening on ${port}`) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Pack packages | ||
npm pack | ||
|
||
# Replace deps | ||
bun run ./scripts/replaceDeps.ts | ||
|
||
# show the diff of deps | ||
git diff | ||
|
||
# setup playground/* for e2e | ||
npm run setup | ||
|
||
# just do e2e! | ||
npm run test:e2e |
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 { constants as FS_CONSTANTS, promises as fs } from 'node:fs' | ||
import { resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { readPackageJSON, writePackageJSON } from 'pkg-types' | ||
|
||
const __dirname = fileURLToPath(new URL('.', import.meta.url)) | ||
|
||
export async function isExists(path: string) { | ||
try { | ||
await fs.access(path, FS_CONSTANTS.F_OK) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
type Platform = 'browser' | 'node' | 'deno' | 'bun' | ||
|
||
async function replaceNodePlatform(platform: 'node' | 'bun', playgroundPath: string) { | ||
const utilsPath = resolve(__dirname, '..') | ||
const utilsPkg = await readPackageJSON(resolve(utilsPath, 'package.json')) | ||
const utilsTgzPath = resolve(utilsPath, `intlify-utils-${utilsPkg.version}.tgz`) | ||
if (!await isExists(utilsTgzPath)) { | ||
return false | ||
} | ||
const targetPath = resolve(playgroundPath, platform, 'package.json') | ||
const platformPkg = await readPackageJSON(targetPath) | ||
platformPkg.dependencies![`@intlify/utils`] = `file:${utilsTgzPath}` | ||
await writePackageJSON(targetPath, platformPkg) | ||
return true | ||
} | ||
|
||
async function replaceDenoPlatform(playgroundPath: string) { | ||
const denoConfigPath = resolve(playgroundPath, 'deno', 'deno.jsonc') | ||
const denoConfig = JSON.parse(await fs.readFile(denoConfigPath, 'utf-8')) as { | ||
imports: Record<string, unknown> | ||
} | ||
denoConfig['imports']['@intlify/utils'] = '../../src/index.ts' | ||
denoConfig['imports']['cookie-es'] = 'npm:[email protected]' | ||
|
||
await fs.writeFile(denoConfigPath, JSON.stringify(denoConfig), 'utf-8') | ||
return true | ||
} | ||
|
||
async function main() { | ||
const playgroundPath = resolve(__dirname, '../playground') | ||
for (const platform of (await fs.readdir(playgroundPath)) as Platform[]) { | ||
if (platform === 'node' || platform === 'bun') { | ||
if (!await replaceNodePlatform(platform, playgroundPath)) { | ||
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`) | ||
} | ||
} else if (platform === 'deno') { | ||
if (!await replaceDenoPlatform(playgroundPath)) { | ||
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`) | ||
} | ||
} else { // for browser | ||
// TODO: | ||
} | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |