|
| 1 | +import {readJSON, writeJSON} from './utils.js'; |
| 2 | +import {resolve} from 'node:path'; |
| 3 | + |
| 4 | +function resolvePath(path) { |
| 5 | + return resolve(import.meta.url.replace('file:/', ''), '../../', path); |
| 6 | +} |
| 7 | + |
| 8 | +function createImports(dependencies) { |
| 9 | + const imports = {}; |
| 10 | + for (const name in dependencies) { |
| 11 | + imports[name] = `npm:${name}@${dependencies[name]}`; |
| 12 | + } |
| 13 | + return imports; |
| 14 | +} |
| 15 | + |
| 16 | +function createTasks(scripts) { |
| 17 | + const tasks = {}; |
| 18 | + for (const name in scripts) { |
| 19 | + const command = scripts[name]; |
| 20 | + tasks[name] = command |
| 21 | + .replace('--max-old-space-size=3072', '') |
| 22 | + .replace('node ', 'deno run -A ') |
| 23 | + .replaceAll('npm run ', 'deno task '); |
| 24 | + } |
| 25 | + return tasks; |
| 26 | +} |
| 27 | + |
| 28 | +async function writeDenoJSON() { |
| 29 | + const packageJSON = resolvePath('package.json'); |
| 30 | + const denoJSON = await resolvePath('deno.json'); |
| 31 | + const pkg = await readJSON(packageJSON); |
| 32 | + |
| 33 | + if (pkg.dependencies) { |
| 34 | + console.error('TODO: support dependencies key in createImports()'); |
| 35 | + } |
| 36 | + const imports = createImports(pkg.devDependencies); |
| 37 | + |
| 38 | + const tasks = createTasks(pkg.scripts); |
| 39 | + |
| 40 | + writeJSON(denoJSON, {imports, tasks}); |
| 41 | +} |
| 42 | + |
| 43 | +async function main() { |
| 44 | + await writeDenoJSON(); |
| 45 | +} |
| 46 | + |
| 47 | +main(); |
0 commit comments