generated from YieldRay/nodejs-purejs-template
-
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.
- Loading branch information
Showing
15 changed files
with
394 additions
and
56 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,26 @@ | ||
name: Release | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
|
||
- run: npx changelogithub | ||
env: | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 YieldRay | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -1,4 +1,33 @@ | ||
# nodejs-purejs-template | ||
# nrm-lite | ||
|
||
Build a nodejs package in pure javascript, | ||
but use [JSDoc](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) to enable typescript check! | ||
Simple and lightweight replacement for nrm. | ||
Like [dnrm](https://github.com/markthree/dnrm), but in pure Node.js | ||
|
||
## Features | ||
|
||
- Super lightweight, pure Node.js with NO dependency | ||
- Fast, DO NOT parse the `.npmrc` file (slightly slower that `dnrm`, due to the runtime) | ||
- Correct, follow the rules of the `.npmrc` file | ||
|
||
## Install | ||
|
||
```sh | ||
# install `nrml` command globally | ||
npm install -g nrm-lite | ||
|
||
nrml --help | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
nrm-lite v0.1.0 | ||
|
||
Usage: | ||
nrml ls List registry | ||
nrml use [name] Use registry | ||
nrml rc Open .npmrc file | ||
nrml help Show this help | ||
Global Options: | ||
--local Use local .npmrc file, rather than the global one (default: false) | ||
``` |
This file was deleted.
Oops, something went wrong.
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
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,55 @@ | ||
import * as fs from 'node:fs' | ||
import { writeFile } from 'node:fs/promises' | ||
import { homedir } from 'node:os' | ||
import { REGISTRIES, findRegistryFromStream } from './registry.mjs' | ||
import { isFile } from './utils.mjs' | ||
|
||
/** | ||
* @param {boolean|undefined} local | ||
* @param {string} registryUrl | ||
*/ | ||
export async function setRegistry(local, registryUrl) { | ||
const filePath = await getConfigPath(local) | ||
|
||
const fileStream = fs.createReadStream(filePath) | ||
const { registry, lines, registryLineNumber } = | ||
await findRegistryFromStream(fileStream) | ||
const newRegistryLine = `registry=${registryUrl}` | ||
|
||
if (!registry) { | ||
lines.push(newRegistryLine) | ||
} else if (registry === registryUrl) { | ||
// same, do nothing | ||
return | ||
} else { | ||
// number-1 is index | ||
lines[registryLineNumber - 1] = newRegistryLine | ||
} | ||
|
||
const result = lines.join('\n') | ||
return writeFile(filePath, result) | ||
} | ||
|
||
/** | ||
* @param {boolean|undefined} local | ||
*/ | ||
export async function getRegistry(local) { | ||
const filePath = await getConfigPath(local) | ||
const fileStream = fs.createReadStream(filePath) | ||
const { registry } = await findRegistryFromStream(fileStream) | ||
return registry || REGISTRIES['npm'] | ||
} | ||
|
||
/** | ||
* If `local` is not provided, check if local npmrc file exists | ||
* @param {boolean|undefined} local | ||
* @noexcept | ||
*/ | ||
export async function getConfigPath(local) { | ||
const rc = '.npmrc' | ||
const detectLocal = typeof local !== 'boolean' && (await isFile(rc)) | ||
if (local || detectLocal) { | ||
return rc | ||
} | ||
return `${homedir().replaceAll('\\', '/')}/${rc}` | ||
} |
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,7 @@ | ||
import { test } from 'node:test' | ||
import * as assert from 'node:assert' | ||
import { getConfigPath } from './config.mjs' | ||
|
||
test('test getConfigPath()', async () => { | ||
assert.ok((await getConfigPath(false)).endsWith('/.npmrc')) | ||
}) |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './add.mjs' | ||
export * from './config.mjs' | ||
export * from './registry.mjs' |
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 |
---|---|---|
@@ -1,25 +1,44 @@ | ||
{ | ||
"name": "nodejs-purejs-template", | ||
"private": true, | ||
"name": "nrm-lite", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"description": "", | ||
"description": "simple and lightweight replacement for nrm", | ||
"main": "index.mjs", | ||
"scripts": { | ||
"test": "node --test", | ||
"watch": "tsc --watch" | ||
"watch": "tsc --watch", | ||
"format": "prettier --write ." | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "", | ||
"engines": { | ||
"node": ">16" | ||
}, | ||
"files": [ | ||
"*.js", | ||
"*.mjs", | ||
"!*.test.*" | ||
], | ||
"bin": { | ||
"cli-name": "./cli.mjs" | ||
"nrml": "cli.mjs" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.10.6", | ||
"typescript": "^5.3.3" | ||
} | ||
"@types/node": "^20.11.25", | ||
"typescript": "^5.4.2" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"keywords": [ | ||
"nrm", | ||
"registry" | ||
], | ||
"author": "YieldRay", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/YieldRay/nrm-lite.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/YieldRay/nrm-lite/issues" | ||
}, | ||
"homepage": "https://github.com/YieldRay/nrm-lite#readme" | ||
} |
Oops, something went wrong.