feat: add extension-tools package

This commit is contained in:
Amin Yahyaabadi 2022-08-07 18:30:29 -07:00
parent 758bb59065
commit 277b6ccd95
13 changed files with 155 additions and 2 deletions

3
.gitignore vendored
View File

@ -11,8 +11,7 @@ temp-*
*.tsbuildinfo
# Build directories
dist/
!./dist/
packages/*/dist/
.parcel-cache
exe/
*.log

2
dist/actions_python.073441c2.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/actions_python.073441c2.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/actions_python.4e47ab32.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/actions_python.4e47ab32.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/setup_cpp.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.mjs vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/setup_cpp.mjs.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,66 @@
<h1 align="center">extension-tools</h1>
<p>
<a href="https://www.npmjs.com/package/extension-tools" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/extension-tools.svg">
</a>
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
</p>
> Tools for working with file extensions such as getting the binary and shell extension on different platforms.
## Install
```sh
npm install --save extension-tools
```
## Usage
<!-- INSERT GENERATED DOCS START -->
### `addBinExtension` (function)
Add bin extension to the given binary name.
**Parameters:**
- name (`string`) - The name you want to add the shell extension to
- win_ext (`string`) - `.exe` on Windows
- unix_ext (`string`) - `""` On unix.
**returns:** string
### `addShellExtension` (function)
Add native shell extension to the given name
**Parameters:**
- name (`string`) - The name you want to add the shell extension to
- win_ext (`string`) - `.bat` on Windows
- unix_ext (`string`) - `.sh` On unix.
**returns:** string
### `addShellHere` (function)
Prefix a `./` for unix shell and nothing for the cmd shell
**Parameters:**
- name (`string`)
**returns:** string
<!-- INSERT GENERATED DOCS END -->
## 🤝 Contributing
You can sponsor my work here:
https://github.com/sponsors/aminya
Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).

View File

@ -0,0 +1,34 @@
{
"name": "extension-tools",
"version": "1.0.0",
"description": "Tools for working with file extensions such as getting the binary and shell extension on different platforms.",
"homepage": "https://github.com/aminya/setup-cpp",
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"scripts": {
"build": "tsc"
},
"keywords": [
"extension",
"shell",
"bin",
"windows",
"sh",
"cmd",
"bat",
"exec",
"execa",
"spawn",
"system",
"unix",
"linux",
"github-actions",
"github",
"actions",
"gitlab",
"ci"
]
}

View File

@ -0,0 +1,35 @@
/**
* Add bin extension to the given binary name.
*
* @param name The name you want to add the shell extension to
* @param win_ext `.exe` on Windows
* @param unix_ext `""` On unix.
*/
export function addBinExtension(name: string, win_ext = ".exe", unix_ext = "") {
if (process.platform === "win32") {
return `${name}${win_ext}`
}
return `${name}${unix_ext}`
}
/**
* Add native shell extension to the given name
*
* @param name The name you want to add the shell extension to
* @param win_ext `.bat` on Windows
* @param unix_ext `.sh` On unix.
*/
export function addShellExtension(name: string, win_ext = ".bat", unix_ext = ".sh") {
if (process.platform === "win32") {
return `${name}${win_ext}`
}
return `${name}${unix_ext}`
}
/** Prefix a `./` for unix shell and nothing for the cmd shell */
export function addShellHere(name: string) {
if (process.platform === "win32") {
return name
}
return `./${name}`
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}