-
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.
Initial setup and post install added
- Loading branch information
Showing
9 changed files
with
1,192 additions
and
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Editor configuration, see https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
|
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,3 @@ | ||
dist | ||
node_modules | ||
bin/ncnn |
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,15 @@ | ||
{ | ||
|
||
"bracketSameLine": true, | ||
"semi": true, | ||
"proseWrap": "always", | ||
"printWidth": 75, | ||
"arrowParens": "always", | ||
"singleAttributePerLine": true, | ||
"trailingComma": "all", | ||
"embeddedLanguageFormatting": "auto", | ||
"experimentalTernaries": true, | ||
"parser": "typescript", | ||
"tabWidth": 2, | ||
"useTabs": true | ||
} |
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,129 @@ | ||
#! node.exe | ||
|
||
import decompress from "decompress"; | ||
import { createWriteStream, existsSync, mkdirSync, rmSync } from "fs"; | ||
import { get } from "https"; | ||
import { join } from "path"; | ||
import { format } from "util"; | ||
|
||
async function _getLatestRelease( | ||
owner: string, | ||
repo: string, | ||
): Promise<string> { | ||
const options = { | ||
hostname: "api.github.com", | ||
path: `/repos/${owner}/${repo}/releases/latest`, | ||
method: "GET", | ||
headers: { | ||
"User-Agent": "node.js", | ||
Accept: "application/vnd.github.v3+json", | ||
}, | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
get(options, (res) => { | ||
let data: string = ""; | ||
|
||
res.on("data", (chunk) => { | ||
data += chunk; | ||
}); | ||
|
||
res.on("end", () => { | ||
if (res.statusCode === 200) { | ||
const latestRelease = JSON.parse(data); | ||
|
||
resolve(latestRelease.tag_name); | ||
} else { | ||
reject( | ||
`Failed to fetch the latest release. Status code: ${res.statusCode}`, | ||
); | ||
} | ||
}); | ||
}).on("error", (err) => { | ||
reject(`Error: ${err.message}`); | ||
}); | ||
}); | ||
} | ||
|
||
function _downloadFile(sourceUrl: string, to: string, cb: Function): void { | ||
console.log("fetching: " + sourceUrl); | ||
|
||
get(sourceUrl, (response) => { | ||
if (response.statusCode === 200) { | ||
const fileStream = createWriteStream(to); | ||
response.pipe(fileStream); | ||
fileStream.on("close", () => { | ||
cb(); | ||
}); | ||
} else if (response.statusCode === 302) { | ||
const redirectedUrl: string = response.headers.location as string; | ||
_downloadFile(redirectedUrl, to, cb); | ||
return; | ||
} else { | ||
throw new Error( | ||
`Failed to download ncnn: ${response.statusCode} ${response.statusMessage}`, | ||
); | ||
} | ||
}).on("error", (err: Error) => { | ||
console.error(`Error downloading file: ${err.message}`); | ||
}); | ||
} | ||
|
||
function _extractFile(archive: string, destPath: string): void { | ||
console.log("extracting: " + archive); | ||
|
||
decompress(archive, destPath, { | ||
strip: 1, | ||
}).then(() => { | ||
console.log("ncnn-CLI installation complete"); | ||
|
||
rmSync(archive, { recursive: true }); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
function install(url: string, destPath: string): void { | ||
const tempFilePath: string = "temp.zip"; | ||
|
||
//mkdir | ||
mkdirSync(destPath, { recursive: true }); | ||
|
||
_downloadFile(url, tempFilePath, () => { | ||
_extractFile(tempFilePath, destPath); | ||
}); | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const destpath: string = join(__dirname, "..", "..", "bin/ncnn"); | ||
|
||
if (existsSync(destpath)) { | ||
return; | ||
} | ||
|
||
const downloadPath: string = | ||
"https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan/releases/download/%s/realesrgan-ncnn-vulkan-%s-%s"; | ||
|
||
const version: Awaited<string> = await _getLatestRelease( | ||
"xinntao", | ||
"Real-ESRGAN-ncnn-vulkan", | ||
); | ||
|
||
if (process.platform === "darwin") { | ||
install(format(downloadPath, version, version, "macos.zip"), destpath); | ||
} else if (process.platform === "win32") { | ||
install( | ||
format(downloadPath, version, version, "windows.zip"), | ||
destpath, | ||
); | ||
} else if (process.platform === "linux") { | ||
install( | ||
format(downloadPath, version, version, "ubuntu.zip"), | ||
destpath, | ||
); | ||
} | ||
} | ||
|
||
main().catch((err: Error) => { | ||
console.log(err); | ||
process.exit(1); | ||
}); |
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,53 @@ | ||
{ | ||
"name": "pixteroid", | ||
"displayName": "Pixteroid", | ||
"version": "0.0.1a", | ||
"description": "Image upscaling module", | ||
"main": "./dist/pixteroid.js", | ||
"exports": { | ||
"import": "./dist/pixteroid.js", | ||
"require": "./dist/pixteroid.js", | ||
"types": "./dist/types/pixteroid.d.ts" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"directories": { | ||
"lib": "./dist/lib" | ||
}, | ||
"preferGlobal": true, | ||
"bin": { | ||
"pixteroid": "./dist/bin/setup.js" | ||
}, | ||
"repository": "https://github.com/cresteem/pixteroid", | ||
"bugs": { | ||
"url": "https://github.com/cresteem/pixteroid/issues" | ||
}, | ||
"author": "DARSAN <darsan@cresteem.com>", | ||
"maintainers": [ | ||
"DARSAN <darsan@cresteem.com>" | ||
], | ||
"license": "Apache-2.0", | ||
"private": false, | ||
"scripts": { | ||
"dev": "rimraf dist && tsc -p tscdev.json", | ||
"dr": "cls && yarn dev && yarn rp", | ||
"rp": "node ./dist/pixteroid.js", | ||
"build": "cls && rimraf dist && tsc -p tsconfig.json", | ||
"watch": "tsc --watch", | ||
"clean": "cls && rimraf dist", | ||
"deploy": "yarn build && yarn publish --access public && git push", | ||
"postinstall": "./dist/bin/setup.js" | ||
}, | ||
"keywords": [], | ||
"dependencies": { | ||
"decompress": "4.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/decompress": "^4.2.7", | ||
"@types/node": "latest", | ||
"rimraf": "5.0.5", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.4.5" | ||
} | ||
} |
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,39 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"baseUrl": ".", | ||
"rootDir": ".", | ||
"outDir": "dist", | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"strict": true, | ||
"strictBindCallApply": true, | ||
"strictNullChecks": true, | ||
"alwaysStrict": true, | ||
"strictFunctionTypes": true, | ||
"allowUmdGlobalAccess": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"preserveConstEnums": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"pretty": false, | ||
"noUnusedLocals": true, | ||
"noImplicitOverride": false, | ||
"noUnusedParameters": true, | ||
"noUncheckedIndexedAccess": false, | ||
"sourceMap": false, | ||
"removeComments": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"test", | ||
"jest.config.ts" | ||
] | ||
} |
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,41 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"baseUrl": ".", | ||
"rootDir": ".", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"declarationDir": "dist/types", | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"strict": true, | ||
"strictBindCallApply": true, | ||
"strictNullChecks": true, | ||
"alwaysStrict": true, | ||
"strictFunctionTypes": true, | ||
"allowUmdGlobalAccess": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"preserveConstEnums": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"pretty": false, | ||
"noUnusedLocals": true, | ||
"noImplicitOverride": false, | ||
"noUnusedParameters": true, | ||
"noUncheckedIndexedAccess": false, | ||
"sourceMap": false, | ||
"removeComments": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"test", | ||
"jest.config.ts" | ||
] | ||
} |
Oops, something went wrong.