Skip to content

Commit

Permalink
v0.9.2 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaandrle authored Feb 21, 2023
1 parent a4fcc63 commit e9c4d9d
Show file tree
Hide file tree
Showing 75 changed files with 623 additions and 1,211 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ curl https://api.spacexdata.com/v4/launches/latest | nodejsscript -p 'Object.ent
## Goods
[s #shelljs](./docs/modules/s.md)
· [$](./docs/modules/.md) ([$.api() #sade](./docs/modules/.md#api), [$.read()](./docs/modules/.md#read), [$.xdg](./docs/modules/xdg_.xdg.md), …)
· [echo()](./docs/README.md#echo)
· [echo() #css-in-console](./docs/README.md#echo)
· [fetch() #node-fetch](./docs/README.md#fetch)
· [pipe()](./docs/README.md#pipe)
· [cyclicLoop()](./docs/README.md#cyclicloop)
Expand Down Expand Up @@ -136,6 +136,12 @@ Keep in mind that you can always turn off this for next command by using:
s.$("-g").rm("*.txt");
```
## Helper(s) for developing
You can create `jsconfig.json` to help your editor provide proper suggestions.
As editor you can use VSCode or Vim with for example [neoclide/coc.nvim](https://github.com/neoclide/coc.nvim).
NodeJSScript provides `nodejsscript --global-jsconfig add script_file` to
help generate `jsconfig.json`.
## Migration from `zx`
The `runA` is almost identical to `$`:
```js
Expand Down
2 changes: 1 addition & 1 deletion _index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @category Public */
export { echo, EchoFunction, css_rules, css_colors } from './src/echo.d';
export { echo, EchoFunction } from './src/echo.d';
export { xdg_, __sade, _env, _exit } from './src/$.d';
/**
* Contains configuration for current script and methods
Expand Down
44 changes: 31 additions & 13 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { stdin as key_stdin } from "../src/keys.js";

process.on('uncaughtException', printError);
(async function main(){
const candidate= argv.splice(2, 1)[0];
const candidate= argv.splice(2, 1)[0] || "--help";
let filepath_tmp;
if(candidate[0]==="-")
filepath_tmp= handleMyArgvs(candidate);
Expand Down Expand Up @@ -58,15 +58,15 @@ function printError(e){
}
function printUsage(){
const [ n, v, d ]= info("name", "version", "description");
const css= echo.css(
"* { margin-left: 2; }",
".n { color: lightblue; }",
".v { color: lightgreen; margin-left: 0; }",
".code { font-style: italic; margin-left: 0; }",
".H { color: yellow; }",
".T { margin-left: 4; }"
);
echo(`%c${n}@%c${v}`, css.n, css.v);
const css= echo.css`
* { margin-left: 2; }
.n { color: lightblue; }
.v { color: lightgreen; margin-left: 0; }
.code { font-style: italic; margin-left: 0; }
.H { color: yellow; }
.T { margin-left: 4; }
`;
echo("%c%s%c@%c%s", css.n, css.unset, css.v, n, v);
echo(`%c${d}`, css.T);
echo(`%cUsage%c:`, css.H);
echo(`%c${n} [options] <script>`, css.T);
Expand All @@ -83,6 +83,7 @@ function printUsage(){
echo(`%cls | ${n} -p '$.stdin.lines().filter(line=> line[0]==="R").map(line=> \`file: \${line}\`)'`, css.T);
echo("%cUsage in scripts%c:", css.H);
echo("%cJust start the file with: %c#!/usr/bin/env nodejsscript", css.T, css.code);
echo("%c…and make the script file executable.", css.T);
$.exit(0);
}
function info(...keys){
Expand All @@ -108,13 +109,30 @@ function jsconfigTypes(){
$.exit(0);
}
function runEval(is_print){
let input= argv.splice(2, 1)[0];
let input= argv.splice(2, 1)[0] ?? "";
if(is_print){
let out_arr= input.split(";").reverse();
const m= "--§--"+randomUUID().replaceAll("-", "")+"--§--";
const store_quotes= [];
input= input.replace(/(['"`])(?:(?!\1)[^\\]|\\[\s\S])*\1/g,
//temporary remove quotes (can contain ';')
f=> (store_quotes.push(f), m));
const m_regexp= new RegExp(m, "g");
let out_arr= input.split(";")
.map(/* return quotes */ v=> v.replace(m_regexp, ()=> store_quotes.shift()))
.reverse();
if(out_arr[0].trim()==="") out_arr.shift();
out_arr[0]= `echo(${out_arr[0]})`;
let pre= "";
let out= out_arr[0]?.trim();
if(out && out[0]==="}"){// "function …{ …; }" ⇒ [ " }".trim(), "function …{ …" ]
pre= "}";
out= out.slice(1).trim();
}
const input_rest= argv.slice(2).join(",");
if(input_rest.trim()!=="") out= `pipe(${input_rest})(${out})`;
out_arr[0]= `${pre} echo(${out})`;
input= out_arr.reverse().join(";");
}
input+= ";$.exit(0);";
const filepath= $.xdg.temp`nodejsscript-${randomUUID()}.mjs`;
s.echo(input).to(filepath);
return filepath;
Expand Down
32 changes: 3 additions & 29 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ nodejsscript

- [EchoFunction](interfaces/EchoFunction.md)

### Type Aliases

- [css\_rules](README.md#css_rules)
- [css\_colors](README.md#css_colors)

### Public Namespaces

- [$](modules/.md)
Expand All @@ -44,7 +39,7 @@ nodejsscript

### pipe

**pipe**(...`funs`): (`input`: `any`) => `any`
**pipe**(`...funs`): (`input`: `any`) => `any`

Function similar to [Ramda `R.pipe`](https://ramdajs.com/docs/#pipe). Provides functional way to combine commands/functions.

Expand Down Expand Up @@ -168,11 +163,11 @@ ___

### echo

**echo**(`message?`, ...`optionalParams`): [`ShellString`](modules/s.md#shellstring)
**echo**(`message?`, `...optionalParams`): [`ShellString`](modules/s.md#shellstring)

This is mixed function between bash’s `echo` and `console.log`.
By default, works more like `console.log` with partial supports
for styling mimic CSS and `console.log` in the web browser. See [css](interfaces/EchoFunction.md#css).
for styling mimic CSS and `console.log` in the web browser. See [`echo.css`](interfaces/EchoFunction.md#type-declaration) (internally uses [css-in-console - npm](https://www.npmjs.com/package/css-in-console)).

The [use](interfaces/EchoFunction.md#use) provides more `echo` way,
the first argument accepts options string starting with `-`:
Expand Down Expand Up @@ -322,27 +317,6 @@ v0.1.13

`never`

## Type Aliases

### css\_rules

Ƭ **css\_rules**: ``"unset: all;"`` \| ``"display: none;"`` \| \`color: ${css\_colors};\` \| \`background: ${css\_colors};\` \| \`margin-left: ${number};\` \| ``"font-style: italic;"`` \| ``"font-weight: bold;"`` \| \`text-decoration: ${"underline" \| "line-through"}\` \| ``"animation: blink;"``

- `color: COLOR` – see [css_colors](README.md#css_colors)
- `background: COLOR` – see [css_colors](README.md#css_colors)
- `margin-left: NUMBER` – counts spaces before string
- `font-style: italic`
- `font-weight: bold`
- `text-decoration: underline|line-through`
- `animation:blink`
- TODO: `…:before { content: "…" }`, `tab-size`

___

### css\_colors

Ƭ **css\_colors**: ``"black"`` \| ``"red"`` \| ``"green"`` \| ``"yellow"`` \| ``"blue"`` \| ``"magenta"`` \| ``"cyan"`` \| ``"white"`` \| ``"gray"`` \| ``"lightred"`` \| ``"lightgreen"`` \| ``"lightyellow"`` \| ``"lightblue"`` \| ``"lightmagenta"`` \| ``"lightcyan"`` \| ``"whitesmoke"``

## Properties

### \_env
Expand Down
20 changes: 19 additions & 1 deletion docs/classes/fetch.Response.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

- [error](fetch.Response.md#error)
- [redirect](fetch.Response.md#redirect)
- [json](fetch.Response.md#json)
- [clone](fetch.Response.md#clone)
- [buffer](fetch.Response.md#buffer)
- [arrayBuffer](fetch.Response.md#arraybuffer)
- [formData](fetch.Response.md#formdata)
- [blob](fetch.Response.md#blob)
- [json](fetch.Response.md#json)
- [json](fetch.Response.md#json-1)
- [text](fetch.Response.md#text)

### Constructors
Expand Down Expand Up @@ -70,6 +71,23 @@ ___

___

### json

`Static` **json**(`data`, `init?`): [`Response`](fetch.Response.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | `any` |
| `init?` | [`ResponseInit`](../interfaces/fetch.ResponseInit.md) |

#### Returns

[`Response`](fetch.Response.md)

___

### clone

**clone**(): [`Response`](fetch.Response.md)
Expand Down
32 changes: 29 additions & 3 deletions docs/classes/s.ProcessPromise.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,33 @@ A resolved promise.

Promise.resolve

`Static` **resolve**<`T`\>(`value`): `Promise`<`T`\>
`Static` **resolve**<`T`\>(`value`): `Promise`<`Awaited`<`T`\>\>

Creates a new resolved promise for the provided value.

#### Type parameters

| Name |
| :------ |
| `T` |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value` | `T` | A promise. |

#### Returns

`Promise`<`Awaited`<`T`\>\>

A promise whose internal state matches the provided promise.

#### Inherited from

Promise.resolve

`Static` **resolve**<`T`\>(`value`): `Promise`<`Awaited`<`T`\>\>

Creates a new resolved promise for the provided value.

Expand All @@ -224,7 +250,7 @@ Creates a new resolved promise for the provided value.

#### Returns

`Promise`<`T`\>
`Promise`<`Awaited`<`T`\>\>

A promise whose internal state matches the provided promise.

Expand Down Expand Up @@ -459,7 +485,7 @@ Creates a new Promise.

| Name | Type | Description |
| :------ | :------ | :------ |
| `executor` | (`resolve`: (`value`: [`ProcessOutput`](s.ProcessOutput.md) \| `PromiseLike`<[`ProcessOutput`](s.ProcessOutput.md)\>) => `void`, `reject`: (`reason?`: `any`) => `void`) => `void` | A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error. |
| `executor` | (`resolve`: (`value`: [`ProcessOutput`](s.ProcessOutput.md) \| `PromiseLike`<[`ProcessOutput`](s.ProcessOutput.md)\>) => `void`, `reject`: (`reason?`: `any`) => `void`) => `void` | A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error. |

#### Inherited from

Expand Down
12 changes: 6 additions & 6 deletions docs/classes/s.child.ChildProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ v11.13.0, v10.16.0

| Name | Type |
| :------ | :------ |
| `emitter` | `NodeEventTarget` |
| `emitter` | `_NodeEventTarget` |
| `eventName` | `string` \| `symbol` |
| `options?` | `StaticEventEmitterOptions` |

Expand All @@ -189,7 +189,7 @@ EventEmitter.once

| Name | Type |
| :------ | :------ |
| `emitter` | `DOMEventTarget` |
| `emitter` | `_DOMEventTarget` |
| `eventName` | `string` |
| `options?` | `StaticEventEmitterOptions` |

Expand Down Expand Up @@ -362,7 +362,7 @@ v15.2.0, v14.17.0

| Name | Type |
| :------ | :------ |
| `emitter` | `EventEmitter` \| `DOMEventTarget` |
| `emitter` | `EventEmitter` \| `_DOMEventTarget` |
| `name` | `string` \| `symbol` |

#### Returns
Expand All @@ -377,7 +377,7 @@ ___

### setMaxListeners

`Static` **setMaxListeners**(`n?`, ...`eventTargets`): `void`
`Static` **setMaxListeners**(`n?`, `...eventTargets`): `void`

```js
const {
Expand All @@ -400,7 +400,7 @@ v15.4.0
| Name | Type | Description |
| :------ | :------ | :------ |
| `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. |
| `...eventTargets` | (`EventEmitter` \| `DOMEventTarget`)[] | - |
| `...eventTargets` | (`EventEmitter` \| `_DOMEventTarget`)[] | - |

#### Returns

Expand Down Expand Up @@ -907,7 +907,7 @@ ___

### emit

**emit**(`event`, ...`args`): `boolean`
**emit**(`event`, `...args`): `boolean`

#### Parameters

Expand Down
Loading

0 comments on commit e9c4d9d

Please sign in to comment.