heraspec 0.1.15 → 0.1.16

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.
Files changed (69) hide show
  1. package/README.md +46 -12
  2. package/bin/heraspec.js +1296 -75
  3. package/bin/heraspec.js.map +4 -4
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/commands/audit.d.ts +37 -0
  6. package/dist/commands/create.d.ts +11 -0
  7. package/dist/commands/explore.d.ts +17 -0
  8. package/dist/commands/helper.d.ts +13 -0
  9. package/dist/commands/hotfix.d.ts +9 -0
  10. package/dist/commands/make-code.d.ts +14 -0
  11. package/dist/commands/make-docs.d.ts +36 -0
  12. package/dist/commands/make-test.d.ts +60 -0
  13. package/dist/commands/memory.d.ts +101 -0
  14. package/dist/commands/pack.d.ts +17 -0
  15. package/dist/commands/show.d.ts +8 -0
  16. package/dist/commands/skill.d.ts +8 -0
  17. package/dist/commands/suggest.d.ts +32 -0
  18. package/dist/commands/validate.d.ts +8 -0
  19. package/dist/core/archive.d.ts +14 -0
  20. package/dist/core/config.d.ts +33 -0
  21. package/dist/core/init.d.ts +97 -0
  22. package/dist/core/list.d.ts +7 -0
  23. package/dist/core/memory/config-advisor.d.ts +30 -0
  24. package/dist/core/memory/context-config.d.ts +14 -0
  25. package/dist/core/memory/context-generator.d.ts +19 -0
  26. package/dist/core/memory/index.d.ts +12 -0
  27. package/dist/core/memory/memory-schema.d.ts +34 -0
  28. package/dist/core/memory/memory-search.d.ts +45 -0
  29. package/dist/core/memory/memory-store.d.ts +71 -0
  30. package/dist/core/memory/memory-types.d.ts +159 -0
  31. package/dist/core/memory/memory-vector.d.ts +23 -0
  32. package/dist/core/parsers/code-parser.d.ts +53 -0
  33. package/dist/core/parsers/markdown-parser.d.ts +18 -0
  34. package/dist/core/restore.d.ts +9 -0
  35. package/dist/core/schemas/base.schema.d.ts +55 -0
  36. package/dist/core/schemas/change.schema.d.ts +35 -0
  37. package/dist/core/schemas/index.d.ts +7 -0
  38. package/dist/core/schemas/spec.schema.d.ts +50 -0
  39. package/dist/core/skills/index.d.ts +6 -0
  40. package/dist/core/skills/skill-manager.d.ts +28 -0
  41. package/dist/core/skills/skill-parser.d.ts +24 -0
  42. package/dist/core/sync.d.ts +6 -0
  43. package/dist/core/templates/index.d.ts +10 -0
  44. package/dist/core/templates/skills/README.md +4 -1
  45. package/dist/core/templates/skills/perfex-module/code-quality-guidelines/skill.md +130 -0
  46. package/dist/core/templates/skills/perfex-module/envato-review-guidelines/skill.md +132 -0
  47. package/dist/core/templates/skills/perfex-module/module-codebase/scripts/scaffold-module.js +151 -0
  48. package/dist/core/templates/skills/perfex-module/module-codebase/skill.md +204 -110
  49. package/dist/core/templates/skills/perfex-module/module-codebase/templates/Test_Module.php +79 -0
  50. package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-admin.php +71 -0
  51. package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-api.php +58 -0
  52. package/dist/core/templates/skills/perfex-module/module-codebase/templates/deploy.ps1 +97 -0
  53. package/dist/core/templates/skills/perfex-module/module-codebase/templates/helper.php +97 -0
  54. package/dist/core/templates/skills/perfex-module/module-codebase/templates/install.php +30 -0
  55. package/dist/core/templates/skills/perfex-module/module-codebase/templates/model-main.php +94 -0
  56. package/dist/core/templates/skills/perfex-module/module-codebase/templates/module-main.php +91 -0
  57. package/dist/core/templates/skills/perfex-module/module-codebase/templates/package.json +30 -0
  58. package/dist/core/templates/skills/perfex-module/module-codebase/templates/uninstall.php +11 -0
  59. package/dist/core/templates/skills/perfex-module/module-codebase/templates/webpack.config.js +163 -0
  60. package/dist/core/templates/skills/perfex-module/skill.md +50 -0
  61. package/dist/core/templates/skills-template-map.d.ts +29 -0
  62. package/dist/core/validation/validator.d.ts +26 -0
  63. package/dist/core/view.d.ts +4 -0
  64. package/dist/index.d.ts +11 -0
  65. package/dist/index.js +155 -35
  66. package/dist/utils/file-system.d.ts +19 -0
  67. package/dist/utils/index.d.ts +6 -0
  68. package/dist/utils/task-parser.d.ts +26 -0
  69. package/package.json +2 -2
@@ -1,110 +1,204 @@
1
- # Skill: Module Codebase (Perfex Module)
2
-
3
- ## Purpose
4
-
5
- This skill is used to create and manage codebase structure for Perfex CRM modules following Perfex best practices.
6
-
7
- ## When to Use
8
-
9
- - When creating a new module for Perfex CRM
10
- - When refactoring existing module structure
11
- - When ensuring module follows Perfex conventions
12
- - When creating standard folder and file structure for module
13
-
14
- ## Step-by-Step Process
15
-
16
- ### Step 1: Analyze Requirements
17
- - Identify main functionality of module
18
- - Identify required database tables
19
- - Identify hooks and filters to use
20
- - Identify permissions to create
21
-
22
- ### Step 2: Scaffold Structure
23
- - Run script: `scripts/scaffold-module.sh <module-name>`
24
- - Script will create standard folder structure:
25
- - `modules/<module-name>/`
26
- - `modules/<module-name>/controllers/`
27
- - `modules/<module-name>/models/`
28
- - `modules/<module-name>/views/`
29
- - `modules/<module-name>/language/`
30
- - `modules/<module-name>/assets/`
31
- - Copy templates to correct locations
32
-
33
- ### Step 3: Configure Module
34
- - Fill information in `module-config.php` (from template)
35
- - Register module in Perfex system
36
- - Set up permissions and menu items
37
-
38
- ### Step 4: Implement Core Logic
39
- - Create controllers following Perfex structure
40
- - Create models with Eloquent patterns
41
- - Implement hooks and filters
42
- - Create database migrations
43
-
44
- ### Step 5: Testing & Documentation
45
- - Test module with Perfex core
46
- - Write documentation (use documents skill)
47
- - Create user guide (use documents skill)
48
-
49
- ## Required Input
50
-
51
- - **Module name**: Module name (kebab-case, e.g., `category-management`)
52
- - **Module description**: Module functionality description
53
- - **Database tables**: List of tables to create
54
- - **Hooks required**: List of hooks to implement
55
- - **Permissions**: List of permissions to create
56
- - **Menu items**: List of menu items to add
57
-
58
- ## Expected Output
59
-
60
- - Complete module folder structure
61
- - Fully configured files
62
- - Database migrations
63
- - Module registration code
64
- - Basic documentation structure
65
-
66
- ## Tone & Rules
67
-
68
- ### Code Style
69
- - Follow PSR-12 coding standards
70
- - Use camelCase for functions
71
- - Use PascalCase for classes
72
- - Comment in English
73
-
74
- ### Naming Conventions
75
- - Module folder: `perfex-<module-name>`
76
- - Class names: `Perfex<ModuleName>`
77
- - Function names: `perfex_<module_name>_<action>`
78
- - Database tables: `tbl<ModuleName>`
79
-
80
- ### Limitations
81
- - ❌ DO NOT create global functions (except hooks)
82
- - ❌ DO NOT hardcode database credentials
83
- - ❌ DO NOT bypass Perfex permission system
84
- - ❌ DO NOT modify core Perfex files
85
- - ❌ DO NOT use deprecated Perfex APIs
86
-
87
- ## Available Templates
88
-
89
- - `templates/module-structure.php` - Basic module structure
90
- - `templates/module-config.php` - Module configuration file
91
- - `templates/module-hooks.php` - Template for hooks
92
- - `templates/module-migration.php` - Database migration template
93
-
94
- ## Available Scripts
95
-
96
- - `scripts/scaffold-module.sh` - Automatically create module structure
97
-
98
- ## Examples
99
-
100
- See `examples/` directory for reference:
101
- - `good-module-structure/` - Example of well-organized module
102
- - `bad-module-structure/` - Example to avoid
103
-
104
- ## Links to Other Skills
105
-
106
- - **documents**: Use to create technical docs and user guide
107
- - **ui-ux**: Use when module has admin interface
108
- - **content-optimization**: Use for module marketing pages
109
- - **module-registration**: Use to register module with Perfex
110
- - **permission-group**: Use to create permissions for module
1
+ # Skill: Module Codebase & Clean Architecture (Perfex Module)
2
+
3
+ ## Purpose
4
+
5
+ This skill provides guidelines, architectural patterns, templates, and scaffolding conventions for building high-quality, enterprise-grade Perfex CRM modules adhering to Clean Code standards, Perfex Core conventions, and modern software engineering best practices.
6
+
7
+ ## When to Use
8
+
9
+ - When scaffolding a new module or refactoring an existing module.
10
+ - When structuring controllers, models, helpers, hooks, and views.
11
+ - When designing high-performance database schemas and composite indexes.
12
+ - When configuring asset bundling (Webpack), automated testing, and clean deployment packaging.
13
+
14
+ ---
15
+
16
+ ## Clean Code Architecture
17
+
18
+ ### 1. Standard Module Directory Structure
19
+ ```
20
+ modules/{module_name}/
21
+ ├── {module_name}.php # Main module bootstrap, registration & hooks
22
+ ├── install.php # Schema migration & initial default options
23
+ ├── uninstall.php # Cleanup hooks (safe options removal / optional table drops)
24
+ ├── package.json # Build scripts (strictly excluded from production zip)
25
+ ├── webpack.config.js # Asset bundling config (strictly excluded from production zip)
26
+ ├── deploy.ps1 # Packaging script with strict /XD and /XF filters
27
+ ├── assets/ # Development source assets
28
+ │ ├── css/ # Modular CSS stylesheets
29
+ │ └── js/ # Modular JS scripts
30
+ │ ├── admin/ # Admin-specific modules
31
+ │ └── lib/ # Bundled offline libraries (Vue, SweetAlert2, etc.)
32
+ ├── dist/ # Minified production assets (enqueued in production)
33
+ │ └── assets/
34
+ │ ├── css/ # *.min.css
35
+ │ └── js/ # *.min.js
36
+ ├── controllers/ # Thin controllers (routing, permissions, input sanitization)
37
+ │ ├── {ModuleName}.php # Admin page controller (extends AdminController)
38
+ │ └── Api.php # AJAX JSON endpoints (extends App_Controller / AdminController)
39
+ ├── models/ # Rich models (business logic, database queries, caching)
40
+ │ ├── {ModuleName}_model.php # Core domain logic & query builder
41
+ │ └── {ModuleName}_settings_model.php # Settings, presets & option cache
42
+ ├── helpers/ # Utility helpers (static asset enqueuers, formatters)
43
+ │ └── {module_name}_helper.php
44
+ ├── libraries/ # Integration libraries & demo generators
45
+ ├── views/ # Pure HTML views (Zero inline JS/CSS)
46
+ │ └── admin/
47
+ ├── language/ # 100% Bilingual localization
48
+ │ ├── english/
49
+ │ │ └── {module_name}_lang.php
50
+ │ └── vietnamese/
51
+ │ └── {module_name}_lang.php
52
+ ├── tests/ # Automated test suite (strictly excluded from deploy)
53
+ │ └── Test_{ModuleName}.php
54
+ └── documentations/ # End-user documentation
55
+ └── index.html # Clean HTML guide (Zero inline style)
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Core Clean Code Principles
61
+
62
+ ### 1. Thin Controllers, Rich Models (Separation of Concerns)
63
+ - **Controllers** should only:
64
+ - Check permissions (`has_permission(...)`, `is_admin()`).
65
+ - Validate and sanitize incoming HTTP input (`$this->input->post(...)`, `(int)$id`).
66
+ - Release session lock if read-only (`session_write_close()`).
67
+ - Delegate data processing to dedicated Models.
68
+ - Return JSON or load view templates.
69
+ - **Models** should handle:
70
+ - SQL Query Builder logic with automatic escaping.
71
+ - Differential tracking and business rules.
72
+ - Multi-channel notification dispatching.
73
+ - High-performance caching.
74
+
75
+ ### 2. High-Performance Database Indexing
76
+ For high-scale CRM entities (comments, mentions, activities, logs):
77
+ - Never rely solely on single-column primary keys for polymorphic queries.
78
+ - Add composite indexes on high-frequency filter pairs:
79
+ ```sql
80
+ KEY `idx_rel_lookup` (`rel_type`, `rel_id`),
81
+ KEY `idx_user_inbox` (`target_type`, `target_id`, `is_read`, `date_created`)
82
+ ```
83
+ - Always use `db_prefix() . '{module}_{table}'` for multi-tenant table prefix compatibility.
84
+ - Always specify character set and collation:
85
+ ```sql
86
+ ENGINE=InnoDB DEFAULT CHARSET=" . $CI->db->char_set . ";
87
+ ```
88
+
89
+ ### 3. Centralized Asset Enqueuing & Fallback
90
+ In `{module_name}_helper.php`:
91
+ - Detect if minified `dist/` asset exists; fallback gracefully to `assets/` source if not built.
92
+ - Append file modification timestamp `?v={filemtime}` for zero-downtime client-side cache busting.
93
+ - Centralize JSON localization injection via `app_admin_head` so views contain zero inline scripts:
94
+ ```php
95
+ hooks()->add_action('app_admin_head', '{module_name}_inject_admin_head');
96
+ ```
97
+
98
+ ### 4. Client Portal Isolation Firewall
99
+ When extending modules to the Client Portal (`app_customers_head` / `app_customers_footer`):
100
+ - Never expose internal company staff, unassigned tickets, internal tasks, or confidential leads to clients.
101
+ - Filter lookups strictly to staff members assigned to the client's specific active projects or open tickets.
102
+ - Ensure all public visitor URLs fallback to safe placeholders (`#`) with no internal ID leakage.
103
+
104
+ ### 5. PHP Concurrency & Session Lock Prevention
105
+ - Autocomplete, mention search, and read-only AJAX endpoints in Perfex CRM hold PHP session file locks by default.
106
+ - Always release the session lock at the start of read/search controller actions:
107
+ ```php
108
+ // Release PHP session file lock immediately for fast concurrent autocompleter queries
109
+ session_write_close();
110
+ ```
111
+
112
+ ### 6. Test Isolation Rule (MANDATORY)
113
+ - All test scripts, benchmark runners, and verification scripts must be placed in `tests/` or `scratch/`.
114
+ - Never place test files in `controllers/` or `views/`.
115
+ - Ensure all packaging scripts (`deploy.ps1`, `deploy.sh`) strictly exclude `tests/` and `scratch/`.
116
+
117
+ ---
118
+
119
+ ## Step-by-Step Implementation Process
120
+
121
+ ### Step 1: Requirements & Schema Analysis
122
+ 1. Define entities and relationships (polymorphic relations to Perfex core tasks, projects, invoices, leads, tickets, clients).
123
+ 2. Determine required hooks (`app_admin_head`, `app_admin_footer`, menu hooks, notification hooks).
124
+ 3. Design database schema with composite indexes.
125
+
126
+ ### Step 2: Scaffold Module Structure
127
+ - Run the scaffolding script from `scripts/` or use templates from `templates/`:
128
+ - Main bootstrap: `{module_name}.php`
129
+ - Installer: `install.php`
130
+ - Uninstaller: `uninstall.php`
131
+ - Helper: `helpers/{module_name}_helper.php`
132
+ - Controller: `controllers/{ModuleName}.php` & `controllers/Api.php`
133
+ - Model: `models/{ModuleName}_model.php`
134
+ - Asset build system: `package.json`, `webpack.config.js`, `deploy.ps1`
135
+
136
+ ### Step 3: Database & Options Migration (`install.php`)
137
+ - Check if table exists before creating:
138
+ ```php
139
+ if (!$CI->db->table_exists(db_prefix() . '{module_name}_table')) { ... }
140
+ ```
141
+ - Register initial default settings via `add_option('{module_name}_default_option', 'value');`.
142
+
143
+ ### Step 4: Thin Controllers & Concurrency Release
144
+ - In read-only search or autocomplete endpoints, call `session_write_close()` right after security checks.
145
+ - Always validate CSRF tokens on POST endpoints.
146
+
147
+ ### Step 5: Pure Views (Zero Inline JS & CSS)
148
+ - Views must contain only semantic HTML and PHP loops/conditionals.
149
+ - Pass configuration via `data-*` attributes on wrapper container:
150
+ ```html
151
+ <div class="{module-name}-container" data-module="{module-name}" data-page="<?php echo html_escape($page_name); ?>">
152
+ ```
153
+ - All styling in `assets/css/` and all logic in `assets/js/`.
154
+
155
+ ### Step 6: Localization & Multilingual Parity
156
+ - Add all strings to `language/english/{module_name}_lang.php`.
157
+ - Mirror every key in `language/vietnamese/{module_name}_lang.php` (and any other supported language).
158
+ - 0 hardcoded English/Vietnamese strings in views or controllers.
159
+
160
+ ### Step 7: Asset Minification & Clean Packaging
161
+ - Run `npm run build` to compile JS/CSS into `dist/assets/`.
162
+ - Verify tests pass in `tests/Test_{ModuleName}.php`.
163
+ - Run `deploy.ps1` to produce the clean production zip with all dev tooling excluded.
164
+
165
+ ---
166
+
167
+ ## Naming & Style Conventions
168
+
169
+ | Component | Convention | Example |
170
+ |---|---|---|
171
+ | Module Identifier | snake_case | `crosstag` |
172
+ | PHP Controller | PascalCase | `Crosstag.php`, `Api.php` |
173
+ | PHP Model | PascalCase with suffix | `Crosstag_model.php` |
174
+ | PHP Helper Class | snake_case with `_helper` | `crosstag_helper.php` |
175
+ | Language Keys | prefix with `{module}_` | `$lang['crosstag_col_bell']` |
176
+ | CSS Classes | prefix with `{module}-` | `.crosstag-user`, `.crosstag-finder` |
177
+ | Global JS Namespace | UPPER_SNAKE_CASE | `window.CROSSTAG_CONFIG` |
178
+ | JS Functions | camelCase | `extendTinyMCEStyles()`, `debounce()` |
179
+
180
+ ---
181
+
182
+ ## Available Templates
183
+
184
+ Located in `templates/`:
185
+ - `module-main.php` - Bootstrap `{module_name}.php` template with hooks and registration.
186
+ - `install.php` - Database schema, composite indexes, and initial options.
187
+ - `uninstall.php` - Clean uninstaller script.
188
+ - `controller-admin.php` - Thin admin controller template.
189
+ - `controller-api.php` - Fast AJAX JSON controller with `session_write_close()`.
190
+ - `model-main.php` - Rich model template with query builder.
191
+ - `helper.php` - Asset enqueuing helper with `dist/` fallback and `?v=` cache buster.
192
+ - `webpack.config.js` - Webpack 5 production bundling pipeline for JS & CSS.
193
+ - `package.json` - Build package config.
194
+ - `deploy.ps1` - Robocopy production packaging script with strict exclusions.
195
+
196
+ ## Available Scripts
197
+
198
+ Located in `scripts/`:
199
+ - `scaffold-module.js` - Node.js CLI script to scaffold a complete Perfex module structure.
200
+
201
+ ---
202
+
203
+ ## Reference Implementation
204
+ - **CrossTag for Perfex** (`modules/crosstag/`): Production benchmark with dual-engine autocompleter, composite database indexes, asset fallback pipeline, and 57/57 passing automated test assertions.
@@ -0,0 +1,79 @@
1
+ <?php
2
+ /**
3
+ * Automated Test Suite for {ModuleName}
4
+ * Strictly excluded from production deploy.
5
+ */
6
+
7
+ class Test_{ModuleName}
8
+ {
9
+ private $errors = [];
10
+ private $passed = 0;
11
+
12
+ public function run()
13
+ {
14
+ echo "Running test suite for {ModuleName}...\n";
15
+
16
+ $this->test_php_guards();
17
+ $this->test_no_inline_code();
18
+ $this->test_scanner_trigger_words();
19
+
20
+ echo "\nResults: {$this->passed} passed, " . count($this->errors) . " failed.\n";
21
+ if (count($this->errors) > 0) {
22
+ foreach ($this->errors as $err) {
23
+ echo " - FAIL: $err\n";
24
+ }
25
+ exit(1);
26
+ }
27
+ echo "ALL TESTS PASSED!\n";
28
+ }
29
+
30
+ private function test_php_guards()
31
+ {
32
+ $files = glob(__DIR__ . '/../*.php');
33
+ foreach ($files as $file) {
34
+ $content = file_get_contents($file);
35
+ if (strpos($content, "defined('BASEPATH')") === false) {
36
+ $this->errors[] = basename($file) . " missing BASEPATH guard.";
37
+ } else {
38
+ $this->passed++;
39
+ }
40
+ }
41
+ }
42
+
43
+ private function test_no_inline_code()
44
+ {
45
+ $views = glob(__DIR__ . '/../views/**/*.php');
46
+ foreach ($views as $view) {
47
+ $content = file_get_contents($view);
48
+ if (preg_match('/<script\b[^>]*>/i', $content) || preg_match('/<style\b[^>]*>/i', $content)) {
49
+ $this->errors[] = basename($view) . " contains inline script or style tag.";
50
+ } else {
51
+ $this->passed++;
52
+ }
53
+ }
54
+ }
55
+
56
+ private function test_scanner_trigger_words()
57
+ {
58
+ $files = array_merge(
59
+ glob(__DIR__ . '/../*.php'),
60
+ glob(__DIR__ . '/../controllers/*.php'),
61
+ glob(__DIR__ . '/../models/*.php'),
62
+ glob(__DIR__ . '/../helpers/*.php')
63
+ );
64
+
65
+ $badWords = ['injectStyles', 'injectScript', '_seeder.php'];
66
+ foreach ($files as $file) {
67
+ $content = file_get_contents($file);
68
+ foreach ($badWords as $word) {
69
+ if (stripos($content, $word) !== false) {
70
+ $this->errors[] = basename($file) . " contains scanner trigger word: $word";
71
+ }
72
+ }
73
+ $this->passed++;
74
+ }
75
+ }
76
+ }
77
+
78
+ $test = new Test_{ModuleName}();
79
+ $test->run();
@@ -0,0 +1,71 @@
1
+ <?php
2
+ defined('BASEPATH') or exit('No direct script access allowed');
3
+
4
+ class {ModuleName} extends AdminController
5
+ {
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->load->model('{module_name}/{module_name}_model');
10
+ }
11
+
12
+ /**
13
+ * Main admin management page
14
+ */
15
+ public function index()
16
+ {
17
+ if (!has_permission('{module_name}', '', 'view')) {
18
+ access_denied('{module_name}');
19
+ }
20
+
21
+ $data['title'] = _l('{module_name}_management');
22
+ $data['items'] = $this->{module_name}_model->get_all();
23
+
24
+ $this->load->view('{module_name}/admin/manage', $data);
25
+ }
26
+
27
+ /**
28
+ * Save or update an item
29
+ */
30
+ public function save($id = '')
31
+ {
32
+ if (!has_permission('{module_name}', '', 'edit') && !has_permission('{module_name}', '', 'create')) {
33
+ access_denied('{module_name}');
34
+ }
35
+
36
+ if ($this->input->post()) {
37
+ $data = $this->input->post();
38
+
39
+ if ($id == '') {
40
+ $insert_id = $this->{module_name}_model->add($data);
41
+ if ($insert_id) {
42
+ set_alert('success', _l('added_successfully', _l('{module_name}_item')));
43
+ }
44
+ } else {
45
+ $success = $this->{module_name}_model->update((int)$id, $data);
46
+ if ($success) {
47
+ set_alert('success', _l('updated_successfully', _l('{module_name}_item')));
48
+ }
49
+ }
50
+
51
+ redirect(admin_url('{module_name}'));
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Delete an item
57
+ */
58
+ public function delete($id)
59
+ {
60
+ if (!has_permission('{module_name}', '', 'delete')) {
61
+ access_denied('{module_name}');
62
+ }
63
+
64
+ $success = $this->{module_name}_model->delete((int)$id);
65
+ if ($success) {
66
+ set_alert('success', _l('deleted', _l('{module_name}_item')));
67
+ }
68
+
69
+ redirect(admin_url('{module_name}'));
70
+ }
71
+ }
@@ -0,0 +1,58 @@
1
+ <?php
2
+ defined('BASEPATH') or exit('No direct script access allowed');
3
+
4
+ class Api extends AdminController
5
+ {
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->load->model('{module_name}/{module_name}_model');
10
+ }
11
+
12
+ /**
13
+ * AJAX search endpoint with session lock prevention
14
+ */
15
+ public function search()
16
+ {
17
+ // 1. Release PHP session file lock immediately to support fast concurrent requests
18
+ session_write_close();
19
+
20
+ if (!has_permission('{module_name}', '', 'view')) {
21
+ $this->output
22
+ ->set_status_header(403)
23
+ ->set_content_type('application/json', 'utf-8')
24
+ ->set_output(json_encode(['error' => _l('access_denied')]));
25
+ return;
26
+ }
27
+
28
+ $query = $this->input->get('q', true);
29
+ $results = $this->{module_name}_model->search($query);
30
+
31
+ $this->output
32
+ ->set_content_type('application/json', 'utf-8')
33
+ ->set_output(json_encode([
34
+ 'success' => true,
35
+ 'data' => $results,
36
+ ]));
37
+ }
38
+
39
+ /**
40
+ * AJAX state toggle or quick action
41
+ */
42
+ public function toggle_status($id)
43
+ {
44
+ if (!has_permission('{module_name}', '', 'edit')) {
45
+ ajax_access_denied();
46
+ }
47
+
48
+ $id = (int)$id;
49
+ $status = (int)$this->input->post('status');
50
+
51
+ $success = $this->{module_name}_model->update_status($id, $status);
52
+
53
+ echo json_encode([
54
+ 'success' => $success,
55
+ 'message' => $success ? _l('{module_name}_status_updated') : _l('something_went_wrong'),
56
+ ]);
57
+ }
58
+ }
@@ -0,0 +1,97 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [switch]$IncludeRawAssets = $true,
4
+ [string]$TargetDeployDir = ""
5
+ )
6
+
7
+ $ErrorActionPreference = 'Stop'
8
+
9
+ $MODULE_NAME = "{module_name}"
10
+ Write-Host "Packaging $MODULE_NAME.zip for production deploy..." -ForegroundColor Cyan
11
+
12
+ $ScriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Definition }
13
+ if (-not $ScriptDir) { $ScriptDir = (Get-Location).Path }
14
+ $SourceDir = $ScriptDir
15
+ $ParentDir = Split-Path -Parent $SourceDir
16
+ $CurrentDir = Get-Location
17
+
18
+ # 1. Build production assets with Webpack if package.json exists
19
+ if (Test-Path (Join-Path $SourceDir "package.json")) {
20
+ Write-Host "Building production assets with Webpack..." -ForegroundColor Cyan
21
+ Push-Location $SourceDir
22
+ try {
23
+ & npm run build
24
+ if ($LASTEXITCODE -ne 0) {
25
+ Write-Host "Warning: npm run build exited with code $LASTEXITCODE" -ForegroundColor Yellow
26
+ }
27
+ } catch {
28
+ Write-Host "Warning: Could not run npm run build: $_" -ForegroundColor Yellow
29
+ } finally {
30
+ Pop-Location
31
+ }
32
+ }
33
+
34
+ # 2. Prepare staging directory
35
+ Set-Location $ParentDir
36
+
37
+ $ZipPath = Join-Path $ParentDir "$MODULE_NAME.zip"
38
+ if (Test-Path $ZipPath) { Remove-Item $ZipPath -Force }
39
+
40
+ $TempBasePath = Join-Path $ENV:TEMP "${MODULE_NAME}_deploy"
41
+ if (Test-Path $TempBasePath) { Remove-Item -Recurse -Force $TempBasePath }
42
+ New-Item -ItemType Directory -Force -Path $TempBasePath | Out-Null
43
+ $TempDir = Join-Path $TempBasePath $MODULE_NAME
44
+
45
+ Write-Host "Staging files into temporary directory with strict exclusions..."
46
+
47
+ # 3. Robocopy with strict dev-tool & test exclusions
48
+ $RobocopyArgs = @(
49
+ $SourceDir,
50
+ $TempDir,
51
+ "/E",
52
+ "/XD", "node_modules", ".git", "_private_note", "ScreenShot", "heraspec", "documentations", "docs", "uploads", ".agents", "tests", "test", "scratch", ".ai",
53
+ "/XF", "package.json", "package-lock.json", "webpack.config.js", "composer.json", "composer.lock", "AGENTS.heraspec.md", "cursorrules", ".cursorrules", ".DS_Store", "*_lang.php.bak", "*.html", "*.txt", "*.sh", "*.ps1", "README.md", "API_DEPLOYMENT.md", "CHANGELOG.md", "init.md", ".gitignore", ".gitattributes", ".editorconfig", "*.test.php", "test_*.php", "Test_*.php", "*_debug.php", "*_demo.php", "*_demo_seeder.php",
54
+ "/NJH", "/NJS", "/NDL", "/NC", "/NS"
55
+ )
56
+ & robocopy $RobocopyArgs | Out-Null
57
+
58
+ # Preserve VERSION.txt if exists
59
+ if (Test-Path (Join-Path $SourceDir "VERSION.txt")) {
60
+ Copy-Item (Join-Path $SourceDir "VERSION.txt") $TempDir -Force
61
+ }
62
+
63
+ # 4. Handle raw assets vs dist assets
64
+ $TempAssetsDir = Join-Path $TempDir "assets"
65
+ $SourceAssetsDir = Join-Path $SourceDir "assets"
66
+
67
+ if ($IncludeRawAssets) {
68
+ if (Test-Path $SourceAssetsDir) {
69
+ if (!(Test-Path $TempAssetsDir)) {
70
+ New-Item -ItemType Directory -Force -Path $TempAssetsDir | Out-Null
71
+ }
72
+ Copy-Item -Path "$SourceAssetsDir\*" -Destination $TempAssetsDir -Recurse -Force
73
+ }
74
+ Write-Host "Included raw assets alongside dist/assets" -ForegroundColor Green
75
+ } else {
76
+ if (Test-Path $TempAssetsDir) {
77
+ Remove-Item -Recurse -Force $TempAssetsDir
78
+ Write-Host "Stripped raw assets (only dist/assets retained)" -ForegroundColor Yellow
79
+ }
80
+ }
81
+
82
+ # 5. Compress module zip using tar
83
+ Write-Host "Compressing module archive..."
84
+ Set-Location -Path $TempBasePath
85
+ & tar -a -cf "$ZipPath" "$MODULE_NAME"
86
+ Set-Location -Path $CurrentDir
87
+ Remove-Item -Recurse -Force $TempBasePath
88
+
89
+ Write-Host "Packaging complete: $ZipPath" -ForegroundColor Green
90
+
91
+ # 6. Copy to Target Deploy directory if specified
92
+ if ($TargetDeployDir -and (Test-Path $TargetDeployDir)) {
93
+ $DestZip = Join-Path $TargetDeployDir "${MODULE_NAME}.zip"
94
+ if (Test-Path $DestZip) { Remove-Item -Force $DestZip }
95
+ Copy-Item -Path $ZipPath -Destination $TargetDeployDir
96
+ Write-Host "Copied to target: $DestZip" -ForegroundColor Green
97
+ }