Skip to content

Commit 8e46fb0

Browse files
authored
v0.7 (#9)
1 parent b9d4525 commit 8e46fb0

File tree

83 files changed

+15764
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+15764
-637
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: 'bug'
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug:**
11+
12+
Here is place for your 😉 clear and concise description of what the bug is.
13+
14+
**To Reproduce/Example:**
15+
16+
Yes, it is nice to have for example code snippet of 🐛 behaviour.
17+
18+
**Technical background (following information can be really helpful 👍):**
19+
20+
- Device: [e.g. iPhone6]
21+
- OS: [e.g. iOS]
22+
- Browser [e.g. chrome, safari]
23+
- Version [e.g. 22]
24+
25+
**Additional context:**
26+
27+
Add any other context about the problem here.
28+
29+
---
30+
31+
Thanks for your help 🎉!
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: 'enhancement'
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe:**
11+
12+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
13+
14+
**Describe the solution you'd like:**
15+
16+
A clear and concise description of what you want to happen.
17+
18+
**Describe alternatives you've considered:**
19+
20+
A clear and concise description of any alternative solutions or features you've considered.
21+
22+
---
23+
24+
Thanks for your help 🎉!

.github/ISSUE_TEMPLATE/idea.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Idea
3+
about: Suggest an idea improving library usage but needs discussion if schould be part of library
4+
title: ''
5+
labels: 'idea'
6+
assignees: ''
7+
8+
---
9+
10+
11+
---
12+
13+
Thanks for your help 🎉!

.github/workflows/npm-publish.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
# Setup .npmrc file to publish to npm
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: '16.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
- run: npm ci
16+
- run: npm publish
17+
env:
18+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
2+
registry=https://registry.npmjs.org/
3+
always-auth=true

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# How to contribute
2+
Contributions to the project generally take one of three forms:
3+
4+
1. Issues reports
5+
1. Bug reports
6+
1. Feature requests
7+
1. Patches
8+
1. Documentation/examples improvements
9+
10+
## Issues reports
11+
The proper way to report Bug/Feature is to use corresponding issue template.
12+
13+
The maintenance team will read all created issues and …:
14+
15+
<!--1. … assign them to proper [projects](../../projects/)
16+
based on targerted library version. Also, each issue schould have chooosed
17+
priority (__low__/__high__) by using specific column i project
18+
(__To Do – Low priority__/__To Do – High priority__).-->
19+
1. … assign them to targerted milestone (with specific deadline, if it is known).
20+
21+
## Patches
22+
__We're super grateful for your patch__
23+
24+
The best way to make sure your issue is addressed is to submit a patch.
25+
We accept patches through all mediums: pull requests, email, issue
26+
comment, tweet with a link to a snippet, etc.
27+
28+
However, before sending a patch, please take try to:
29+
30+
- make your commit message describtive and use issue links for better
31+
understandig commit purpose.
32+
- make your coding style similar to ours (TBD).
33+
34+
### Development Environment
35+
The library is developed using [Node.js](http://nodejs.org/) and has
36+
a number of dependencies specified in its package.json file.
37+
To install them just run the following command from within your
38+
repo directory:
39+
```bash
40+
$ npm ci
41+
```
42+
43+
## Documentation/examples improvements
44+
You can use issue for reporting errors and suggesting improvements
45+
similary to [Issues reports](#issues-reports). It is also acceptable
46+
to open issue with question if it wasn’t currently adressed anywhere
47+
and you think it schould.
48+
49+
For updating documentation and examples follow [Patches](#Patches).
50+
The documentation is created by [typedoc](https://github.com/TypeStrong/typedoc).
51+
Examples are in [examples/](./docs/examples/).
52+
53+
---
54+
This text was inspired by
55+
[jshint’s one](https://github.com/jshint/jshint/blob/master/CONTRIBUTING.md).

README.md

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ This is primarily achieved by using [shelljs/shelljs](https://github.com/shelljs
88
You can compare the final script code to `zx` example:
99
```javascript
1010
#!/usr/bin/env nodejsscript
11-
import { s, echo } from "nodejsscript";
1211
echo(s.grep("name", "package.json"));
1312

14-
s.exec("git branch --show-current").xargs(s.exec, "dep deploy --branch={}");
13+
s.run("git branch --show-current").xargs(s.run, "dep deploy --branch={}");
1514

16-
s.exec("sleep 1; echo 1");
17-
s.exec("sleep 2; echo 2");
18-
s.exec("sleep 3; echo 3");
15+
s.run("sleep 1; echo 1");
16+
s.run("sleep 2; echo 2");
17+
s.run("sleep 3; echo 3");
1918

2019
import { join } from "node:path";
2120
const name= "foo bar";
@@ -27,10 +26,11 @@ s.mkdir(join(s.tempdir(), name));
2726

2827
1. tested/used on *NodeJS*: `[email protected]` and `[email protected]` ⇒ for installation follow [nvm-sh/nvm: Node Version Manager](https://github.com/nvm-sh/nvm)[^OR]
2928
1. `npm install https://github.com/jaandrle/nodejsscript --global` (**will be registered also in npm repository**)
29+
1. alternatively install locally
3030

3131
## Goods
3232
[s #shelljs](./docs/modules/s.md)
33-
· [cli](./docs/modules/cli.md) ([cli.api() #sade](./docs/modules/cli.md#api), [cli.read()](./docs/modules/cli.md#read), …)
33+
· [cli](./docs/modules/cli.md) ([cli.api() #sade](./docs/modules/cli.md#api), [cli.read()](./docs/modules/cli.md#read), [cli.xdg](./docs/modules/xdg_.xdg.md), …)
3434
· [echo()](./docs/README.md#echo)
3535
· [fetch() #node-fetch](./docs/README.md#fetch)
3636
· [style #ansi-colors](./docs/modules/style.md)
@@ -59,17 +59,65 @@ Or via the `nodejsscript` executable:
5959
nodejsscript ./script.mjs
6060
```
6161

62-
All function (`shelljs`, `fetch`, …) are exported by library, so use:
63-
```javascript
64-
import { … } from "nodejsscript";
62+
<details>
63+
<summary>Alternatively when installed locally</summary>
64+
65+
```bash
66+
#!/usr/bin/env -S npx nodejsscript
67+
```
68+
```bash
69+
npx nodejsscript ./script.mjs
6570
```
66-
*The entry point for documentation of all exported (**Public**) items is in the* [**docs/**](./docs/README.md).
71+
72+
</details>
73+
74+
All function (`shelljs`, `fetch`, …) are registered as global namespaces/functions:
75+
*The entry point for documentation of all **Public** items is in the* [**docs/**](./docs/README.md).
6776

6877
Note that there are also built-in `'node:*'` modules:
6978
```js
7079
import { setTimeout } from "node:timers/promises";
7180
import { join, resolve } from "node:path";
81+
82+
//current file url
83+
import.meta.url;
84+
//url to path
85+
import { fileURLToPath } from "node:url";
86+
const file_path= fileURLToPath(import.meta.url);
7287
```
7388
…and more, see [Node.js v17.9.1 Documentation](https://nodejs.org/docs/latest-v17.x/api/documentation.html#stability-overview).
7489
90+
## Security guidelines
91+
**`run()` command injection**: this advice applies to `child_process.exec()` just as
92+
much as it applies to `s.run()`. It is potentially risky to run commands passed
93+
for example by user input:
94+
```js
95+
function curlUnsafe(urlToDownload){ return s.run('curl ' + urlToDownload); }
96+
curlUnsafe('https://some/url ; rm -rf $HOME'); //=> curl https://some/url ; rm -rf $HOME
97+
```
98+
Therefore, `nodejsscript`s `s.run()` provide way to escapes untrusted parameters:
99+
```js
100+
function curl(url){ return s.run("run ::url::", { url }); }
101+
curl('https://some/url ; rm -rf $HOME'); //=> curl 'https://some/url ; rm -rf $HOME'
102+
```
103+
…*Note: The ['xargs()'](../interfaces/s.XargsFunction.md) by default also escapes piped strings.*
104+
105+
*…Note 2: `s.run(…cmd, …vars)` is also helpul for escaping parameters passed as variables (e.g. arrays).*
106+
107+
*…Note 3: ShellJS also provides `s.exec`, but `s.run` should be prefered way to execute commands.*
108+
109+
**Glob injection (all commands)**: Most ShellJS commands support [glob](https://github.com/isaacs/node-glob) expansion,
110+
expanding wildcards such as `*` to match files. While this is very powerful,
111+
dependent modules should exercise caution. Unsanitized user input may contain
112+
wildcard characters. Consider for example that the `*.txt` is valid file name,
113+
however the `s.rm("*.txt")` by default (using the globbing) delete all `txt` files.
114+
Keep in mind that you can always turn off this for next command by using:
115+
```js
116+
s.$("-g").rm("*.txt");
117+
```
118+
119+
## Contribute
120+
- [Contributor Covenant Code of Conduc](./CODE_OF_CONDUCT.md)
121+
- [How to contribute](./CONTRIBUTING.md)
122+
75123
[^OR]: Alternatively `curl -sL install-node.vercel.app/16.13.0 | bash`

0 commit comments

Comments
 (0)