@gutenye/script.js 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ake/README.md +68 -18
- package/src/ake/ake.ts +1 -1
- package/src/ake/akectl.ts +18 -2
- package/src/ake/completions/ake.fish +13 -4
- package/src/completion.ts +1 -0
package/package.json
CHANGED
package/src/ake/README.md
CHANGED
|
@@ -40,35 +40,85 @@ ake greetings # find the ake file and runs it
|
|
|
40
40
|
ake <Tab> # uses ake file's completion
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
## Use a template / another location
|
|
44
|
+
|
|
45
|
+
Create `~/bin.src/ake/template`
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
akectl init local # create an ake file from template in current directory
|
|
49
|
+
akectl init local foo # create an akefoo file
|
|
50
|
+
akectl init remote # create in ~/bin.src/ake/<dir>, doesn't touch original project files
|
|
51
|
+
akectl init remote foo # create akefoo in remote location
|
|
52
|
+
akectl edit # opens an editor to edit the ake file
|
|
53
|
+
akectl edit foo # opens an editor to edit the akefoo file
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Organize Multiple Files
|
|
57
|
+
|
|
58
|
+
For larger projects, split commands into separate files and import them.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
project/
|
|
62
|
+
├── ake # entry point (executable)
|
|
63
|
+
├── src/
|
|
64
|
+
│ ├── index.ts # imports all command files
|
|
65
|
+
│ ├── cmd1.ts
|
|
66
|
+
│ └── cmd2.ts
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`src/cmd1.ts`
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { app } from "@gutenye/script.js";
|
|
73
|
+
|
|
74
|
+
app.cmd("greetings").add(() => {
|
|
75
|
+
$`echo greetings`;
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`src/index.ts`
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import "./cmd1";
|
|
83
|
+
import "./cmd2";
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`ake`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
#!/usr/bin/env bun
|
|
90
|
+
|
|
91
|
+
import { app } from "@gutenye/script.js";
|
|
92
|
+
import "./src";
|
|
93
|
+
|
|
94
|
+
await app.run();
|
|
95
|
+
```
|
|
96
|
+
|
|
43
97
|
## Multiple Ake Files
|
|
44
98
|
|
|
45
|
-
|
|
99
|
+
Any file named `ake<suffix>` or `ake<suffix>.ts` is supported.
|
|
100
|
+
|
|
101
|
+
1. Create a variant ake file
|
|
46
102
|
|
|
47
103
|
```sh
|
|
48
|
-
# Create variant ake files
|
|
49
104
|
akectl init local foo # creates ./akefoo
|
|
50
|
-
|
|
105
|
+
```
|
|
51
106
|
|
|
52
|
-
|
|
53
|
-
ln -sf $(which ake) ~/bin/akefoo
|
|
54
|
-
ln -sf $(which ake) ~/bin/akebar
|
|
107
|
+
2. Create a wrapper script so you can invoke it by name
|
|
55
108
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
akebar deploy # finds ./akebar and runs it
|
|
109
|
+
```sh
|
|
110
|
+
akectl install-bin ~/bin/ake foo
|
|
59
111
|
```
|
|
60
112
|
|
|
61
|
-
|
|
113
|
+
3. Enable shell completion in `ake.fish`
|
|
62
114
|
|
|
63
|
-
|
|
115
|
+
```fish
|
|
116
|
+
_setup_ake_complete ake foo
|
|
117
|
+
```
|
|
64
118
|
|
|
65
|
-
|
|
119
|
+
4. Run it
|
|
66
120
|
|
|
67
121
|
```sh
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
akectl init remote # create in ~/bin.src/ake/<dir>, doesn't touch original project files
|
|
71
|
-
akectl init remote foo # create akefoo in remote location
|
|
72
|
-
akectl edit # opens an editor to edit the ake file
|
|
73
|
-
akectl edit foo # opens an editor to edit the akefoo file
|
|
122
|
+
akefoo greetings
|
|
123
|
+
akefoo <Tab> # with autocompletion
|
|
74
124
|
```
|
package/src/ake/ake.ts
CHANGED
package/src/ake/akectl.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import { castArray } from 'lodash-es'
|
|
4
4
|
import fs from '../utils/fs'
|
|
5
5
|
import {
|
|
6
|
-
STORAGE_DIR,
|
|
7
|
-
TEMPLATE_NAME,
|
|
8
6
|
exitWithError,
|
|
9
7
|
findAkeFiles,
|
|
10
8
|
getAkeFilenames,
|
|
11
9
|
getRemoteDir,
|
|
10
|
+
STORAGE_DIR,
|
|
11
|
+
TEMPLATE_NAME,
|
|
12
12
|
} from './shared'
|
|
13
13
|
|
|
14
14
|
const NAME = 'akectl'
|
|
@@ -43,6 +43,22 @@ app
|
|
|
43
43
|
await openEditor(target)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
+
app
|
|
47
|
+
.cmd('install-bin', 'Create a wrapper script for ake with a suffix')
|
|
48
|
+
.add('<prefix>', 'Path prefix (e.g. ~/bin/ake, ~/bin/a)')
|
|
49
|
+
.add('<suffix>', 'Suffix to append (e.g. "foo" → ~/bin/akefoo)')
|
|
50
|
+
.add(async (prefix: string, suffix: string) => {
|
|
51
|
+
const target = `${prefix}${suffix}`
|
|
52
|
+
const content = `
|
|
53
|
+
#!/usr/bin/env bash
|
|
54
|
+
|
|
55
|
+
SUFFIX=${suffix} exec ${prefix} "$@"
|
|
56
|
+
`.trim()
|
|
57
|
+
await fs.writeFile(target, content)
|
|
58
|
+
await fs.chmod(target, 0o755)
|
|
59
|
+
console.log(`created ${target}`)
|
|
60
|
+
})
|
|
61
|
+
|
|
46
62
|
app
|
|
47
63
|
.cmd('edit', 'Edit ake file')
|
|
48
64
|
.add('[suffix]', 'Ake file suffix (e.g. "foo" for akefoo)')
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _setup_ake_complete
|
|
2
|
+
set cmd $argv[1]
|
|
3
|
+
set suffix $argv[2]
|
|
4
|
+
complete --erase $cmd$suffix
|
|
5
|
+
complete --command $cmd$suffix --no-files --arguments "(_ake_complete $suffix)"
|
|
6
|
+
end
|
|
3
7
|
|
|
4
8
|
function _ake_complete
|
|
5
|
-
set
|
|
6
|
-
set
|
|
9
|
+
set suffix $argv[1]
|
|
10
|
+
set unique_name (string replace --all '/' '_' $PWD)
|
|
11
|
+
set name "ake$suffix.$unique_name"
|
|
7
12
|
_carapace_completer $name
|
|
8
13
|
end
|
|
14
|
+
|
|
15
|
+
_setup_ake_complete ake
|
|
16
|
+
# _setup_ake_complete ake <suffix>
|
|
17
|
+
|
package/src/completion.ts
CHANGED
|
@@ -146,6 +146,7 @@ export async function installCompletion(
|
|
|
146
146
|
|
|
147
147
|
fsSync.mkdirSync(specsDir, { recursive: true })
|
|
148
148
|
fsSync.writeFileSync(filePath, result.text)
|
|
149
|
+
console.log(`Updated completion spec: ${filePath}`)
|
|
149
150
|
} catch {
|
|
150
151
|
// completion is supplementary — silently ignore errors
|
|
151
152
|
}
|