Skip to content

Commit

Permalink
Initial setup and post install added
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Jun 29, 2024
1 parent a249050 commit f1670e5
Show file tree
Hide file tree
Showing 9 changed files with 1,192 additions and 183 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
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

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
bin/ncnn
15 changes: 15 additions & 0 deletions .prettierrc
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
}
366 changes: 183 additions & 183 deletions LICENSE

Large diffs are not rendered by default.

129 changes: 129 additions & 0 deletions bin/setup.ts
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);
});
53 changes: 53 additions & 0 deletions package.json
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"
}
}
39 changes: 39 additions & 0 deletions tscdev.json
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"
]
}
41 changes: 41 additions & 0 deletions tsconfig.json
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"
]
}
Loading

0 comments on commit f1670e5

Please sign in to comment.