|
| 1 | +/// <reference types="node"/> |
| 2 | +import { join } from "path"; |
| 3 | +import { readFileSync, unlinkSync } from "fs"; |
| 4 | +import { tmpdir } from "os"; |
| 5 | +import { execSync, ExecSyncOptions } from "child_process"; |
| 6 | +import chalk from "chalk"; |
| 7 | + |
| 8 | +interface PackageJson { |
| 9 | + name: string; |
| 10 | + version: string |
| 11 | +} |
| 12 | + |
| 13 | +const exec = (cmd: string, opts?: ExecSyncOptions) => { |
| 14 | + console.log(chalk.gray(`> ${cmd} ${opts ? JSON.stringify(opts) : ""}`)); |
| 15 | + execSync(cmd, opts); |
| 16 | +}; |
| 17 | + |
| 18 | +const step = (msg: string) => { |
| 19 | + console.log("\n\n" + chalk.bold("- ") + msg); |
| 20 | +}; |
| 21 | + |
| 22 | +function main(): void { |
| 23 | + console.log(chalk.bold("## Creating the language services build of TypeScript")); |
| 24 | + process.stdout.write(chalk.grey("> node /scripts/createLanguageServiceBuild.ts")); |
| 25 | + |
| 26 | + // Create a tarball of the current version |
| 27 | + step("Packing the current TypeScript via npm."); |
| 28 | + exec("npm pack"); |
| 29 | + |
| 30 | + const packageJsonValue: PackageJson = JSON.parse(readFileSync("package.json", "utf8")); |
| 31 | + const tarballFileName = `${packageJsonValue.name}-${packageJsonValue.version}.tgz`; |
| 32 | + |
| 33 | + const unzipDir = tmpdir(); |
| 34 | + step(`Extracting the built version into a temporary folder. ${unzipDir}/package`); |
| 35 | + exec(`tar -xvzf ${tarballFileName} -C ${unzipDir}`); |
| 36 | + unlinkSync(tarballFileName); |
| 37 | + |
| 38 | + step(`Updating the build metadata`); |
| 39 | + const packagePath = join(unzipDir, "package"); |
| 40 | + exec(`node scripts/configureLanguageServiceBuild.js ${join(packagePath, "package.json")}`); |
| 41 | + |
| 42 | + step(`Deploying the language service`); |
| 43 | + exec("npm publish --access public", { cwd: packagePath }); |
| 44 | +} |
| 45 | + |
| 46 | +main(); |
0 commit comments