@take-out/cli 0.0.52 → 0.0.57
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/dist/cjs/cli.cjs +3 -1
- package/dist/cjs/cli.js +3 -1
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands/run-all.cjs +69 -0
- package/dist/cjs/commands/run-all.js +59 -0
- package/dist/cjs/commands/run-all.js.map +6 -0
- package/dist/cjs/commands/run.cjs +2 -2
- package/dist/cjs/commands/run.js +2 -2
- package/dist/cjs/commands/run.js.map +1 -1
- package/dist/cjs/commands/script.cjs +8 -83
- package/dist/cjs/commands/script.js +8 -85
- package/dist/cjs/commands/script.js.map +1 -1
- package/dist/cjs/utils/script-listing.cjs +9 -9
- package/dist/cjs/utils/script-listing.js +8 -8
- package/dist/cjs/utils/script-listing.js.map +1 -1
- package/dist/cjs/utils/script-utils.cjs +91 -0
- package/dist/cjs/utils/script-utils.js +87 -0
- package/dist/cjs/utils/script-utils.js.map +6 -0
- package/dist/cjs/utils/script-utils.native.js +126 -0
- package/dist/cjs/utils/script-utils.native.js.map +6 -0
- package/dist/esm/cli.js +3 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/cli.mjs +3 -1
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/commands/run-all.js +46 -0
- package/dist/esm/commands/run-all.js.map +6 -0
- package/dist/esm/commands/run-all.mjs +46 -0
- package/dist/esm/commands/run-all.mjs.map +1 -0
- package/dist/esm/commands/run.js +2 -2
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/run.mjs +2 -2
- package/dist/esm/commands/run.mjs.map +1 -1
- package/dist/esm/commands/script.js +6 -84
- package/dist/esm/commands/script.js.map +1 -1
- package/dist/esm/commands/script.mjs +7 -79
- package/dist/esm/commands/script.mjs.map +1 -1
- package/dist/esm/utils/script-listing.js +1 -5
- package/dist/esm/utils/script-listing.js.map +1 -1
- package/dist/esm/utils/script-listing.mjs +1 -1
- package/dist/esm/utils/script-listing.mjs.map +1 -1
- package/dist/esm/utils/script-utils.js +80 -0
- package/dist/esm/utils/script-utils.js.map +6 -0
- package/dist/esm/utils/script-utils.mjs +66 -0
- package/dist/esm/utils/script-utils.mjs.map +1 -0
- package/dist/esm/utils/script-utils.native.js +112 -0
- package/dist/esm/utils/script-utils.native.js.map +6 -0
- package/package.json +7 -7
- package/scripts/seed.ts +12 -4
- package/src/cli.ts +3 -0
- package/src/commands/run-all.ts +62 -0
- package/src/commands/run.ts +3 -2
- package/src/commands/script.ts +7 -157
- package/src/utils/script-listing.ts +1 -6
- package/src/utils/script-utils.ts +153 -0
- package/types/utils/script-utils.d.ts +13 -0
- package/types/utils/script-utils.d.ts.map +1 -0
package/src/commands/script.ts
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
existsSync,
|
|
7
|
+
readFileSync,
|
|
7
8
|
readdirSync,
|
|
8
9
|
statSync,
|
|
9
|
-
readFileSync,
|
|
10
10
|
writeFileSync,
|
|
11
11
|
mkdirSync,
|
|
12
12
|
} from 'node:fs'
|
|
13
|
-
import {
|
|
14
|
-
import { join, relative, dirname, basename, extname } from 'node:path'
|
|
13
|
+
import { join, relative, dirname, basename } from 'node:path'
|
|
15
14
|
import { fileURLToPath } from 'node:url'
|
|
16
15
|
|
|
17
16
|
import { defineCommand } from 'citty'
|
|
18
17
|
import pc from 'picocolors'
|
|
19
18
|
|
|
20
19
|
import { listAllScripts, listCategoryScripts } from '../utils/script-listing'
|
|
20
|
+
import { getLocalScriptsDir } from '../utils/script-utils'
|
|
21
21
|
import {
|
|
22
22
|
type FileToSync,
|
|
23
23
|
compareFiles,
|
|
@@ -25,20 +25,6 @@ import {
|
|
|
25
25
|
syncFileWithConfirmation,
|
|
26
26
|
} from '../utils/sync'
|
|
27
27
|
|
|
28
|
-
// cache configuration
|
|
29
|
-
const CACHE_DIR = join(homedir(), '.takeout')
|
|
30
|
-
const CACHE_FILE = join(CACHE_DIR, 'script-cache.json')
|
|
31
|
-
|
|
32
|
-
interface ScriptMetadata {
|
|
33
|
-
description?: string
|
|
34
|
-
args?: string[]
|
|
35
|
-
mtime?: number
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface ScriptCache {
|
|
39
|
-
[path: string]: ScriptMetadata
|
|
40
|
-
}
|
|
41
|
-
|
|
42
28
|
// find scripts package root using import.meta.resolve
|
|
43
29
|
function findScriptsPackageRoot(): string | null {
|
|
44
30
|
try {
|
|
@@ -58,131 +44,6 @@ function findScriptsPackageRoot(): string | null {
|
|
|
58
44
|
return null
|
|
59
45
|
}
|
|
60
46
|
|
|
61
|
-
// get local scripts directory
|
|
62
|
-
export function getLocalScriptsDir(): string {
|
|
63
|
-
return join(process.cwd(), 'scripts')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// extract metadata from script file
|
|
67
|
-
function extractMetadata(filePath: string): ScriptMetadata {
|
|
68
|
-
try {
|
|
69
|
-
const content = readFileSync(filePath, 'utf-8')
|
|
70
|
-
const lines = content.split('\n').slice(0, 20) // check first 20 lines
|
|
71
|
-
|
|
72
|
-
const metadata: ScriptMetadata = {}
|
|
73
|
-
|
|
74
|
-
for (const line of lines) {
|
|
75
|
-
// look for @description comment
|
|
76
|
-
const descMatch = line.match(/@description\s+(.+)/)
|
|
77
|
-
if (descMatch && descMatch[1]) {
|
|
78
|
-
metadata.description = descMatch[1].trim()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// look for @args comment
|
|
82
|
-
const argsMatch = line.match(/@args\s+(.+)/)
|
|
83
|
-
if (argsMatch && argsMatch[1]) {
|
|
84
|
-
metadata.args = argsMatch[1].split(',').map((a) => a.trim())
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// add file modification time
|
|
89
|
-
const stat = statSync(filePath)
|
|
90
|
-
metadata.mtime = stat.mtimeMs
|
|
91
|
-
|
|
92
|
-
return metadata
|
|
93
|
-
} catch (err) {
|
|
94
|
-
return {}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// load or create cache
|
|
99
|
-
function loadCache(): ScriptCache {
|
|
100
|
-
try {
|
|
101
|
-
if (existsSync(CACHE_FILE)) {
|
|
102
|
-
return JSON.parse(readFileSync(CACHE_FILE, 'utf-8'))
|
|
103
|
-
}
|
|
104
|
-
} catch (err) {
|
|
105
|
-
// ignore cache errors
|
|
106
|
-
}
|
|
107
|
-
return {}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// save cache
|
|
111
|
-
function saveCache(cache: ScriptCache) {
|
|
112
|
-
try {
|
|
113
|
-
if (!existsSync(CACHE_DIR)) {
|
|
114
|
-
mkdirSync(CACHE_DIR, { recursive: true })
|
|
115
|
-
}
|
|
116
|
-
writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2))
|
|
117
|
-
} catch (err) {
|
|
118
|
-
// ignore cache write errors
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// get metadata for a script (with caching)
|
|
123
|
-
export function getScriptMetadata(filePath: string): ScriptMetadata {
|
|
124
|
-
const cache = loadCache()
|
|
125
|
-
const stat = statSync(filePath)
|
|
126
|
-
|
|
127
|
-
// check if cache is valid
|
|
128
|
-
if (cache[filePath] && cache[filePath].mtime === stat.mtimeMs) {
|
|
129
|
-
return cache[filePath]
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// extract fresh metadata
|
|
133
|
-
const metadata = extractMetadata(filePath)
|
|
134
|
-
|
|
135
|
-
// update cache
|
|
136
|
-
cache[filePath] = metadata
|
|
137
|
-
saveCache(cache)
|
|
138
|
-
|
|
139
|
-
return metadata
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// discover scripts in a directory
|
|
143
|
-
export function discoverScripts(
|
|
144
|
-
dir: string,
|
|
145
|
-
baseDir: string = dir,
|
|
146
|
-
depth: number = 0,
|
|
147
|
-
maxDepth: number = 1
|
|
148
|
-
): Map<string, string> {
|
|
149
|
-
const scripts = new Map<string, string>()
|
|
150
|
-
|
|
151
|
-
if (!existsSync(dir)) {
|
|
152
|
-
return scripts
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
const entries = readdirSync(dir)
|
|
157
|
-
|
|
158
|
-
for (const entry of entries) {
|
|
159
|
-
const fullPath = join(dir, entry)
|
|
160
|
-
const stat = statSync(fullPath)
|
|
161
|
-
|
|
162
|
-
if (stat.isDirectory()) {
|
|
163
|
-
// skip helpers directories and limit depth to maxDepth
|
|
164
|
-
if (entry === 'helpers' || depth >= maxDepth) {
|
|
165
|
-
continue
|
|
166
|
-
}
|
|
167
|
-
// recursively discover in subdirectories
|
|
168
|
-
const subScripts = discoverScripts(fullPath, baseDir, depth + 1, maxDepth)
|
|
169
|
-
for (const [name, path] of subScripts) {
|
|
170
|
-
scripts.set(name, path)
|
|
171
|
-
}
|
|
172
|
-
} else if (entry.endsWith('.ts') || entry.endsWith('.js')) {
|
|
173
|
-
// create script name relative to base, normalize to forward slashes
|
|
174
|
-
const relativePath = relative(baseDir, fullPath).split('\\').join('/')
|
|
175
|
-
const scriptName = relativePath.replace(/\.(ts|js)$/, '')
|
|
176
|
-
scripts.set(scriptName, fullPath)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
} catch (err) {
|
|
180
|
-
// ignore directory read errors
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return scripts
|
|
184
|
-
}
|
|
185
|
-
|
|
186
47
|
// find a script by name (checks both built-in and local)
|
|
187
48
|
export function findScript(name: string): string | null {
|
|
188
49
|
// normalize name: convert colons to slashes for consistency
|
|
@@ -275,29 +136,18 @@ const newCommand = defineCommand({
|
|
|
275
136
|
* @args --verbose, --dry-run
|
|
276
137
|
*/
|
|
277
138
|
|
|
278
|
-
import {
|
|
139
|
+
import { args } from '@take-out/scripts/helpers/args'
|
|
279
140
|
|
|
280
|
-
const {
|
|
281
|
-
args: process.argv.slice(2),
|
|
282
|
-
options: {
|
|
283
|
-
verbose: {
|
|
284
|
-
type: 'boolean',
|
|
285
|
-
short: 'v',
|
|
286
|
-
},
|
|
287
|
-
'dry-run': {
|
|
288
|
-
type: 'boolean',
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
})
|
|
141
|
+
const { verbose, dryRun } = args('--verbose boolean --dry-run boolean')
|
|
292
142
|
|
|
293
143
|
async function main() {
|
|
294
144
|
console.info('Running ${basename(scriptPath)}...')
|
|
295
145
|
|
|
296
|
-
if (
|
|
146
|
+
if (verbose) {
|
|
297
147
|
console.info('Verbose mode enabled')
|
|
298
148
|
}
|
|
299
149
|
|
|
300
|
-
if (
|
|
150
|
+
if (dryRun) {
|
|
301
151
|
console.info('Dry run mode - no changes will be made')
|
|
302
152
|
}
|
|
303
153
|
|
|
@@ -8,12 +8,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
8
8
|
|
|
9
9
|
import pc from 'picocolors'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
discoverScripts,
|
|
14
|
-
getLocalScriptsDir,
|
|
15
|
-
getScriptMetadata,
|
|
16
|
-
} from '../commands/script'
|
|
11
|
+
import { discoverScripts, getLocalScriptsDir, getScriptMetadata } from './script-utils'
|
|
17
12
|
|
|
18
13
|
// find scripts package root using import.meta.resolve
|
|
19
14
|
function findScriptsPackageRoot(): string | null {
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core utility functions for script discovery and metadata
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
existsSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
statSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
} from 'node:fs'
|
|
13
|
+
import { homedir } from 'node:os'
|
|
14
|
+
import { join, relative } from 'node:path'
|
|
15
|
+
|
|
16
|
+
// cache configuration
|
|
17
|
+
const CACHE_DIR = join(homedir(), '.takeout')
|
|
18
|
+
const CACHE_FILE = join(CACHE_DIR, 'script-cache.json')
|
|
19
|
+
|
|
20
|
+
interface ScriptMetadata {
|
|
21
|
+
description?: string
|
|
22
|
+
args?: string[]
|
|
23
|
+
mtime?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ScriptCache {
|
|
27
|
+
[path: string]: ScriptMetadata
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// get local scripts directory
|
|
31
|
+
export function getLocalScriptsDir(): string {
|
|
32
|
+
return join(process.cwd(), 'scripts')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// extract metadata from script file
|
|
36
|
+
function extractMetadata(filePath: string): ScriptMetadata {
|
|
37
|
+
try {
|
|
38
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
39
|
+
const lines = content.split('\n').slice(0, 20) // check first 20 lines
|
|
40
|
+
|
|
41
|
+
const metadata: ScriptMetadata = {}
|
|
42
|
+
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
// look for @description comment
|
|
45
|
+
const descMatch = line.match(/@description\s+(.+)/)
|
|
46
|
+
if (descMatch && descMatch[1]) {
|
|
47
|
+
metadata.description = descMatch[1].trim()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// look for @args comment
|
|
51
|
+
const argsMatch = line.match(/@args\s+(.+)/)
|
|
52
|
+
if (argsMatch && argsMatch[1]) {
|
|
53
|
+
metadata.args = argsMatch[1].split(',').map((a) => a.trim())
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// add file modification time
|
|
58
|
+
const stat = statSync(filePath)
|
|
59
|
+
metadata.mtime = stat.mtimeMs
|
|
60
|
+
|
|
61
|
+
return metadata
|
|
62
|
+
} catch (err) {
|
|
63
|
+
return {}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// load or create cache
|
|
68
|
+
function loadCache(): ScriptCache {
|
|
69
|
+
try {
|
|
70
|
+
if (existsSync(CACHE_FILE)) {
|
|
71
|
+
return JSON.parse(readFileSync(CACHE_FILE, 'utf-8'))
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
// ignore cache errors
|
|
75
|
+
}
|
|
76
|
+
return {}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// save cache
|
|
80
|
+
function saveCache(cache: ScriptCache) {
|
|
81
|
+
try {
|
|
82
|
+
if (!existsSync(CACHE_DIR)) {
|
|
83
|
+
mkdirSync(CACHE_DIR, { recursive: true })
|
|
84
|
+
}
|
|
85
|
+
writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2))
|
|
86
|
+
} catch (err) {
|
|
87
|
+
// ignore cache write errors
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// get metadata for a script (with caching)
|
|
92
|
+
export function getScriptMetadata(filePath: string): ScriptMetadata {
|
|
93
|
+
const cache = loadCache()
|
|
94
|
+
const stat = statSync(filePath)
|
|
95
|
+
|
|
96
|
+
// check if cache is valid
|
|
97
|
+
if (cache[filePath] && cache[filePath].mtime === stat.mtimeMs) {
|
|
98
|
+
return cache[filePath]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// extract fresh metadata
|
|
102
|
+
const metadata = extractMetadata(filePath)
|
|
103
|
+
|
|
104
|
+
// update cache
|
|
105
|
+
cache[filePath] = metadata
|
|
106
|
+
saveCache(cache)
|
|
107
|
+
|
|
108
|
+
return metadata
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// discover scripts in a directory
|
|
112
|
+
export function discoverScripts(
|
|
113
|
+
dir: string,
|
|
114
|
+
baseDir: string = dir,
|
|
115
|
+
depth: number = 0,
|
|
116
|
+
maxDepth: number = 1
|
|
117
|
+
): Map<string, string> {
|
|
118
|
+
const scripts = new Map<string, string>()
|
|
119
|
+
|
|
120
|
+
if (!existsSync(dir)) {
|
|
121
|
+
return scripts
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const entries = readdirSync(dir)
|
|
126
|
+
|
|
127
|
+
for (const entry of entries) {
|
|
128
|
+
const fullPath = join(dir, entry)
|
|
129
|
+
const stat = statSync(fullPath)
|
|
130
|
+
|
|
131
|
+
if (stat.isDirectory()) {
|
|
132
|
+
// skip helpers directories and limit depth to maxDepth
|
|
133
|
+
if (entry === 'helpers' || depth >= maxDepth) {
|
|
134
|
+
continue
|
|
135
|
+
}
|
|
136
|
+
// recursively discover in subdirectories
|
|
137
|
+
const subScripts = discoverScripts(fullPath, baseDir, depth + 1, maxDepth)
|
|
138
|
+
for (const [name, path] of subScripts) {
|
|
139
|
+
scripts.set(name, path)
|
|
140
|
+
}
|
|
141
|
+
} else if (entry.endsWith('.ts') || entry.endsWith('.js')) {
|
|
142
|
+
// create script name relative to base, normalize to forward slashes
|
|
143
|
+
const relativePath = relative(baseDir, fullPath).split('\\').join('/')
|
|
144
|
+
const scriptName = relativePath.replace(/\.(ts|js)$/, '')
|
|
145
|
+
scripts.set(scriptName, fullPath)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
// ignore directory read errors
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return scripts
|
|
153
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core utility functions for script discovery and metadata
|
|
3
|
+
*/
|
|
4
|
+
interface ScriptMetadata {
|
|
5
|
+
description?: string;
|
|
6
|
+
args?: string[];
|
|
7
|
+
mtime?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function getLocalScriptsDir(): string;
|
|
10
|
+
export declare function getScriptMetadata(filePath: string): ScriptMetadata;
|
|
11
|
+
export declare function discoverScripts(dir: string, baseDir?: string, depth?: number, maxDepth?: number): Map<string, string>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=script-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-utils.d.ts","sourceRoot":"","sources":["../../src/utils/script-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,UAAU,cAAc;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAOD,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AA2DD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAiBlE;AAGD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAY,EACrB,KAAK,GAAE,MAAU,EACjB,QAAQ,GAAE,MAAU,GACnB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAoCrB"}
|