@wooksjs/event-wf 0.6.3 → 0.6.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-wf",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "@wooksjs/event-wf",
5
5
  "keywords": [
6
6
  "app",
@@ -47,13 +47,13 @@
47
47
  "devDependencies": {
48
48
  "typescript": "^5.9.3",
49
49
  "vitest": "^3.2.4",
50
- "@wooksjs/event-core": "^0.6.3",
51
- "wooks": "^0.6.3"
50
+ "@wooksjs/event-core": "^0.6.4",
51
+ "wooks": "^0.6.4"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@prostojs/logger": "^0.4.3",
55
- "@wooksjs/event-core": "^0.6.3",
56
- "wooks": "^0.6.3"
55
+ "@wooksjs/event-core": "^0.6.4",
56
+ "wooks": "^0.6.4"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rolldown -c ../../rolldown.config.mjs",
@@ -1,70 +1,77 @@
1
1
  #!/usr/bin/env node
2
- // @ts-check
3
- /**
4
- * Copies the event-wf skill files into the consuming project's
5
- * agent-skills directory so that AI coding agents (Claude Code, Cursor,
6
- * Windsurf, Codex, etc.) can discover and load them.
7
- *
8
- * Runs automatically on `postinstall` or manually via:
9
- * npx @wooksjs/event-wf setup-skills
10
- */
2
+ /* prettier-ignore */
3
+ 'use strict'
11
4
 
12
5
  const fs = require('fs')
13
6
  const path = require('path')
7
+ const os = require('os')
14
8
 
15
9
  const SKILL_NAME = 'wooksjs-event-wf'
10
+ const SKILL_SRC = path.join(__dirname, '..', 'skills', SKILL_NAME)
16
11
 
17
- /* ── locate the project root (first dir above node_modules) ──────── */
18
- function findProjectRoot() {
19
- let dir = __dirname
20
- while (dir !== path.dirname(dir)) {
21
- dir = path.dirname(dir)
22
- if (path.basename(dir) === 'node_modules') {
23
- return path.dirname(dir)
24
- }
25
- }
26
- return process.cwd()
12
+ if (!fs.existsSync(SKILL_SRC)) {
13
+ console.error(`No skills found at ${SKILL_SRC}`)
14
+ console.error('Add your SKILL.md files to the skills/' + SKILL_NAME + '/ directory first.')
15
+ process.exit(1)
27
16
  }
28
17
 
29
- const projectRoot = findProjectRoot()
30
- const srcDir = path.join(__dirname, '..', 'skills', SKILL_NAME)
31
- const agents = [
32
- { dir: '.claude', file: 'SKILL.md' },
33
- { dir: '.cursor', file: 'SKILL.md' },
34
- { dir: '.windsurf', file: 'SKILL.md' },
35
- { dir: '.codex', file: 'SKILL.md' },
36
- ]
18
+ const AGENTS = {
19
+ 'Claude Code': { dir: '.claude/skills', global: path.join(os.homedir(), '.claude', 'skills') },
20
+ 'Cursor': { dir: '.cursor/skills', global: path.join(os.homedir(), '.cursor', 'skills') },
21
+ 'Windsurf': { dir: '.windsurf/skills', global: path.join(os.homedir(), '.windsurf', 'skills') },
22
+ 'Codex': { dir: '.codex/skills', global: path.join(os.homedir(), '.codex', 'skills') },
23
+ 'OpenCode': { dir: '.opencode/skills', global: path.join(os.homedir(), '.opencode', 'skills') },
24
+ }
37
25
 
38
- /* ── copy skill files ────────────────────────────────────────────── */
39
- function copySkills() {
40
- if (!fs.existsSync(srcDir)) {
41
- console.log(`[${SKILL_NAME}] skills source not found, skipping.`)
42
- return
43
- }
26
+ const args = process.argv.slice(2)
27
+ const isGlobal = args.includes('--global') || args.includes('-g')
28
+ const isPostinstall = args.includes('--postinstall')
29
+ let installed = 0, skipped = 0
30
+ const installedDirs = []
44
31
 
45
- const files = fs.readdirSync(srcDir)
46
- let copied = 0
32
+ for (const [agentName, cfg] of Object.entries(AGENTS)) {
33
+ const targetBase = isGlobal ? cfg.global : path.join(process.cwd(), cfg.dir)
34
+ const agentRootDir = path.dirname(cfg.global) // Check if the agent has ever been installed globally
47
35
 
48
- for (const agent of agents) {
49
- const destDir = path.join(projectRoot, agent.dir, 'skills', SKILL_NAME)
50
- fs.mkdirSync(destDir, { recursive: true })
36
+ // In postinstall mode: silently skip agents that aren't set up globally
37
+ if (isPostinstall || isGlobal) {
38
+ if (!fs.existsSync(agentRootDir)) { skipped++; continue }
39
+ }
51
40
 
52
- for (const file of files) {
53
- const src = path.join(srcDir, file)
54
- const dest = path.join(destDir, file)
55
- if (fs.statSync(src).isFile()) {
56
- fs.copyFileSync(src, dest)
57
- copied++
58
- }
59
- }
41
+ const dest = path.join(targetBase, SKILL_NAME)
42
+ try {
43
+ fs.mkdirSync(dest, { recursive: true })
44
+ fs.cpSync(SKILL_SRC, dest, { recursive: true })
45
+ console.log(`✅ ${agentName}: installed to ${dest}`)
46
+ installed++
47
+ if (!isGlobal) installedDirs.push(cfg.dir + '/' + SKILL_NAME)
48
+ } catch (err) {
49
+ console.warn(`⚠️ ${agentName}: failed — ${err.message}`)
60
50
  }
51
+ }
61
52
 
62
- console.log(`[${SKILL_NAME}] copied ${files.length} skill files to ${agents.length} agent dirs (${copied} total).`)
53
+ // Add locally-installed skill dirs to .gitignore
54
+ if (!isGlobal && installedDirs.length > 0) {
55
+ const gitignorePath = path.join(process.cwd(), '.gitignore')
56
+ let gitignoreContent = ''
57
+ try { gitignoreContent = fs.readFileSync(gitignorePath, 'utf8') } catch {}
58
+ const linesToAdd = installedDirs.filter(d => !gitignoreContent.includes(d))
59
+ if (linesToAdd.length > 0) {
60
+ const hasHeader = gitignoreContent.includes('# AI agent skills')
61
+ const block = (gitignoreContent && !gitignoreContent.endsWith('\n') ? '\n' : '')
62
+ + (hasHeader ? '' : '\n# AI agent skills (auto-generated by setup-skills)\n')
63
+ + linesToAdd.join('\n') + '\n'
64
+ fs.appendFileSync(gitignorePath, block)
65
+ console.log(`📝 Added ${linesToAdd.length} entries to .gitignore`)
66
+ }
63
67
  }
64
68
 
65
- try {
66
- copySkills()
67
- } catch (err) {
68
- // Non-fatal don't break installs
69
- console.log(`[${SKILL_NAME}] skill setup skipped: ${err.message}`)
69
+ if (installed === 0 && isPostinstall) {
70
+ // Silence is fine — no agents present, nothing to do
71
+ } else if (installed === 0 && skipped === Object.keys(AGENTS).length) {
72
+ console.log('No agent directories detected. Try --global or run without it for project-local install.')
73
+ } else if (installed === 0) {
74
+ console.log('Nothing installed. Run without --global to install project-locally.')
75
+ } else {
76
+ console.log(`\n✨ Done! Restart your AI agent to pick up the "${SKILL_NAME}" skill.`)
70
77
  }