Skip to content

Commit

Permalink
Merge pull request #40 from Pure-D/install-served
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Feb 25, 2021
2 parents 6a6ecc2 + 1890a3e commit 50f9a0a
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* text=auto

# don't diff machine generated files
dist/ -diff
package-lock.json -diff
pnpm-lock.yaml -diff

# Built files
dist/ -diff
dist/** filter=lfs diff=lfs merge=lfs -text
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
},
"scripts": {
"format": "prettier --write .",
"test.format": "prettier . --check",
"lint": "eslint . --fix",
"test.lint": "eslint .",
"test.format": "prettier . --check",
"lint": "eslint . --fix",
"test.lint": "eslint .",
"test": "atom --test spec",
"clean": "shx rm -rf dist",
"tsc": "tsc -p src/tsconfig.json",
"tsc.dev": "tsc -p src/tsconfig.json --watch",
"build": "npm run tsc",
"dev": "npm run tsc.dev",
"get.grammars": "node ./scripts/get-grammars.js",
"get.serve-d": "node ./scripts/get-serve-d.js",
"get.serve-d": "ts-node -P ./scripts/tsconfig.json ./scripts/get-serve-d.ts",
"build-commit": "build-commit -o dist",
"prepare": "npm run build"
},
Expand Down Expand Up @@ -85,8 +85,10 @@
"devDependencies": {
"@terascope/fetch-github-release": "^0.7.4",
"@types/atom": "1.40.7",
"@types/decompress": "^4.2.3",
"@types/fs-extra": "^9.0.7",
"@types/node": "^14.14.31",
"@types/semver": "^7.3.4",
"build-commit": "0.1.4",
"cross-env": "7.0.3",
"decompress": "^4.2.1",
Expand All @@ -95,7 +97,9 @@
"eslint-config-atomic": "^1.10.2",
"gitly": "^2.0.2",
"prettier": "^2.2.1",
"semver": "^7.3.4",
"shx": "0.3.3",
"ts-node": "^9.1.1",
"typescript": "^4.2.2"
},
"dependencies": {
Expand Down
76 changes: 76 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions scripts/get-serve-d.js

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/get-serve-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import downloadRelease from "@terascope/fetch-github-release"
import { join, dirname, extname, basename } from "path"
import { remove, ensureDir } from "fs-extra"
import decompress from "decompress"
import decompressTarxz from "decompress-tarxz"

// function to download serve-d binaries from GitHub
export async function getServeD() {
const distFolder = join(dirname(__dirname), "dist")

await remove(distFolder)
await ensureDir(distFolder)

const assets = ((await downloadRelease(
/* username */ "Pure-D",
/* repo */ "serve-d",
/* download folder */ distFolder,
/* filter release */ undefined,
/* filter asset */ undefined, // (asset) => asset.name.indexOf(platform) >= 0,
true
)) as unknown) as string[]

for (const asset of assets) {
const platform = basename(asset).match(/windows|linux|osx/)[0]
const downloadFolder = join(distFolder, platform)
if (extname(asset) === ".xz") {
await decompress(asset, downloadFolder, {
plugins: [decompressTarxz()],
})
} else {
await decompress(asset, downloadFolder)
}
remove(asset)
}
}

getServeD()
.then(() => console.log("Done"))
.catch((e) => {
throw e
})
3 changes: 3 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../src/tsconfig.json"
}
37 changes: 34 additions & 3 deletions src/installation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { copy } from "fs-extra"
import pathExists from "path-exists"
import { join, dirname } from "path"
import semverCompare from "semver/functions/compare"

import { execFile as execFileRaw } from "child_process"
import { promisify } from "util"
const execFile = promisify(execFileRaw)

const distFolder = join(dirname(__dirname), "dist")

Expand Down Expand Up @@ -28,12 +33,38 @@ async function isServeDInstalled(serveDPath: string) {
return pathExists(serveDPath)
}

/** get the version of serve-d */
async function getServeDVersion(file: string) {
try {
const output = (await execFile(file, ["--version"])).stderr
const version = output.match(/v(\d\S*)\s/)[1]
return version
} catch (e) {
console.error(e)
return null
}
}

/** Check if the given serve-d is up to date against the target version */
export async function isServeDUpToDate(givenFile: string, targetFile: string) {
const givenVersion = await getServeDVersion(givenFile)
const targetVersion = await getServeDVersion(targetFile)
return givenVersion && targetVersion && semverCompare(givenVersion, targetVersion) !== -1
}

async function copyServeD(codeDBinFolder: string) {
atom.notifications.addInfo("Installing serve-d...")
// copy the whole served folder
await copy(bundledServerMap[process.platform], codeDBinFolder, { overwrite: true })
atom.notifications.addSuccess("Serve-d was installed")
}

export async function installServeD() {
const codeDBinFolder = await getCodeDBinFolder()
const serveDPath = join(codeDBinFolder, serveDExeFileName)
if (!(await isServeDInstalled(serveDPath))) {
// copy the whole served folder
await copy(bundledServerMap[process.platform], codeDBinFolder)
const bundledServeDPath = join(bundledServerMap[process.platform], serveDExeFileName)
if (!(await isServeDInstalled(serveDPath)) || !(await isServeDUpToDate(serveDPath, bundledServeDPath))) {
await copyServeD(codeDBinFolder)
}
return serveDPath
}

0 comments on commit 50f9a0a

Please sign in to comment.