Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "svelte-check",
"build": "rollup -c rollup.config.js",
"compile": "tsc",
"bootstrap": "node scripts/getDTS.js",
"bootstrap": "ts-node scripts/getDTS.ts",
"dev": "yarn start",
"start": "concurrently -p \"[{name}]\" -n \"ROLLUP,SITE\" -c \"bgBlue.bold,bgMagenta.bold\" \"yarn rollup -c rollup.config.js --watch\" \"yarn serve dist\"",
"prepublishOnly": "yarn build",
Expand All @@ -30,6 +30,8 @@
"@rollup/plugin-node-resolve": "^7.1.0",
"@rollup/plugin-typescript": "^3.0.0",
"@types/markdown-it": "^10.0.2",
"@types/node": "^14.14.9",
"@types/node-fetch": "^2.5.7",
"@types/prismjs": "^1.16.2",
"@types/react": "^16.9.23",
"concurrently": "^5.1.0",
Expand All @@ -41,6 +43,7 @@
"serve": "^11.3.0",
"svelte-check": "^1.1.13",
"svelte-preprocess": "^4.6.0",
"ts-node": "^9.0.0",
"typescript": "latest"
},
"dependencies": {
Expand Down
86 changes: 0 additions & 86 deletions scripts/getDTS.js

This file was deleted.

107 changes: 107 additions & 0 deletions scripts/getDTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Grab the DTS files from the TypeScript website
// then do a bit of string manipulation in order to make it
// compile without _all_ of the dependencies

import { promises as fs, constants as fsConsts } from 'fs'
import * as path from 'path'
import fetch from 'node-fetch'

function download(url: string): Promise<string> {
return fetch(url).then((r) => r.text())
}

function saveFile(dest: string, content: string): Promise<void> {
return fs.writeFile(path.join(__dirname, '..', dest), content, 'utf8')
}

async function isNotExists(path: string): Promise<boolean> {
try {
await fs.access(path, fsConsts.F_OK)
return false
} catch {
return true
}
}

;(async () => {
const vendor = path.join('src', 'vendor')
const ds = path.join(vendor, 'ds')

if (await isNotExists(ds)) {
await fs.mkdir(ds, { recursive: true })
}

const host = 'https://www.staging-typescript.org'
// For playground-dev purposes
// const host = 'http://localhost:8000'

/** The API for the monaco typescript worker. */
async function getTSWorker() {
const text = await download(`${host}/js/sandbox/tsWorker.d.ts`)
return saveFile(path.join(vendor, 'tsWorker.d.ts'), text)
}

async function getDesignSystemDts() {
const text = await download(
`${host}/js/playground/ds/createDesignSystem.d.ts`
)
return saveFile(
path.join(ds, 'createDesignSystem.d.ts'),
text.replace('typescriptlang-org/static/js/sandbox', '../sandbox')
)
}

async function getPluginUtils() {
const text = await download(`${host}/js/playground/pluginUtils.d.ts`)
return saveFile(
path.join(vendor, 'pluginUtils.d.ts'),
text.replace('from "typescript-sandbox"', 'from "./sandbox"')
)
}

async function getTSVfs() {
const text = await download(`${host}/js/sandbox/vendor/typescript-vfs.d.ts`)
return saveFile(
path.join(vendor, 'typescript-vfs.d.ts'),
text
.replace('/// <reference types="lz-string" />', '') // remove import
.replace('import("lz-string").LZStringStatic', 'any') // remove 'lz-string'
)
}

async function getSandbox() {
const text = await download(`${host}/js/sandbox/index.d.ts`)
return saveFile(
path.join(vendor, 'sandbox.d.ts'),
text
.replace('./vendor/typescript-vfs', './typescript-vfs') // replace TS-VFS
.replace('import lzstring', '// import lzstring') // remove 'lz-string'
.replace('lzstring: typeof lzstring', '// lzstring: typeof lzstring') // remove 'lz-string'
)
}

async function getPlayground() {
const text = await download(`${host}/js/playground/index.d.ts`)
return saveFile(
path.join(vendor, '/playground.d.ts'),
text
.replace(/typescript-sandbox/g, './sandbox') // replace sandbox
.replace(
/typescriptlang-org\/static\/js\/sandbox\/vendor\/typescript-vfs/g,
'./typescript-vfs'
) // replace TS-VFS
.replace('lzstring: typeof', '// lzstring: typeof') // remove 'lz-string'
.replace('getWorkerProcess', '// getWorkerProcess') // remove worker
.replace('ui:', '// ui:') // remove UI
)
}

return Promise.all([
getTSWorker(),
getDesignSystemDts(),
getPluginUtils(),
getTSVfs(),
getSandbox(),
getPlayground(),
])
})()
5 changes: 2 additions & 3 deletions src/vendor/sandbox.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TypeScriptWorker } from "./tsWorker";// import { TypeScriptWorker } from "./tsWorker";
import { TypeScriptWorker } from "./tsWorker";
// import lzstring from "./vendor/lzstring.min";

import * as tsvfs from './typescript-vfs';
import * as tsvfs from "./typescript-vfs";
declare type CompilerOptions = import("monaco-editor").languages.typescript.CompilerOptions;
declare type Monaco = typeof import("monaco-editor");
/**
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"module": "es2015",
"moduleResolution": "node",
"types": ["svelte"]
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
}
}
Loading