heraspec 0.1.14 → 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 (236) hide show
  1. package/LICENSE +187 -0
  2. package/README.md +140 -107
  3. package/bin/heraspec.js +1491 -155
  4. package/bin/heraspec.js.map +4 -4
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/commands/audit.d.ts +37 -0
  7. package/dist/commands/create.d.ts +11 -0
  8. package/dist/commands/explore.d.ts +17 -0
  9. package/dist/commands/helper.d.ts +13 -0
  10. package/dist/commands/hotfix.d.ts +9 -0
  11. package/dist/commands/make-code.d.ts +14 -0
  12. package/dist/commands/make-docs.d.ts +36 -0
  13. package/dist/commands/make-test.d.ts +60 -0
  14. package/dist/commands/memory.d.ts +101 -0
  15. package/dist/commands/pack.d.ts +17 -0
  16. package/dist/commands/show.d.ts +8 -0
  17. package/dist/commands/skill.d.ts +8 -0
  18. package/dist/commands/suggest.d.ts +32 -0
  19. package/dist/commands/validate.d.ts +8 -0
  20. package/dist/core/archive.d.ts +14 -0
  21. package/dist/core/config.d.ts +33 -0
  22. package/dist/core/init.d.ts +97 -0
  23. package/dist/core/list.d.ts +7 -0
  24. package/dist/core/memory/config-advisor.d.ts +30 -0
  25. package/dist/core/memory/context-config.d.ts +14 -0
  26. package/dist/core/memory/context-generator.d.ts +19 -0
  27. package/dist/core/memory/index.d.ts +12 -0
  28. package/dist/core/memory/memory-schema.d.ts +34 -0
  29. package/dist/core/memory/memory-search.d.ts +45 -0
  30. package/dist/core/memory/memory-store.d.ts +71 -0
  31. package/dist/core/memory/memory-types.d.ts +159 -0
  32. package/dist/core/memory/memory-vector.d.ts +23 -0
  33. package/dist/core/parsers/code-parser.d.ts +53 -0
  34. package/dist/core/parsers/markdown-parser.d.ts +18 -0
  35. package/dist/core/restore.d.ts +9 -0
  36. package/dist/core/schemas/base.schema.d.ts +55 -0
  37. package/dist/core/schemas/change.schema.d.ts +35 -0
  38. package/dist/core/schemas/index.d.ts +7 -0
  39. package/dist/core/schemas/spec.schema.d.ts +50 -0
  40. package/dist/core/skills/index.d.ts +6 -0
  41. package/dist/core/skills/skill-manager.d.ts +28 -0
  42. package/dist/core/skills/skill-parser.d.ts +24 -0
  43. package/dist/core/sync.d.ts +6 -0
  44. package/dist/core/templates/index.d.ts +10 -0
  45. package/dist/core/templates/skills/README.md +44 -38
  46. package/dist/core/templates/skills/campaign-plan/skill.md +76 -0
  47. package/dist/core/templates/skills/campaign-plan/skill.vi.md +76 -0
  48. package/dist/core/templates/skills/campaign-plan-skill.md +76 -0
  49. package/dist/core/templates/skills/campaign-plan-skill.vi.md +76 -0
  50. package/dist/core/templates/skills/code-review/skill.md +70 -0
  51. package/dist/core/templates/skills/code-review/skill.vi.md +70 -0
  52. package/dist/core/templates/skills/code-review-skill.md +70 -0
  53. package/dist/core/templates/skills/code-review-skill.vi.md +70 -0
  54. package/dist/core/templates/skills/content-creation/skill.md +69 -0
  55. package/dist/core/templates/skills/content-creation/skill.vi.md +69 -0
  56. package/dist/core/templates/skills/content-creation-skill.md +69 -0
  57. package/dist/core/templates/skills/content-creation-skill.vi.md +69 -0
  58. package/dist/core/templates/skills/content-optimization/skill.md +104 -0
  59. package/dist/core/templates/skills/debug/skill.md +69 -0
  60. package/dist/core/templates/skills/debug/skill.vi.md +69 -0
  61. package/dist/core/templates/skills/debug-skill.md +69 -0
  62. package/dist/core/templates/skills/debug-skill.vi.md +69 -0
  63. package/dist/core/templates/skills/deploy-documentation/skill.md +408 -0
  64. package/dist/core/templates/skills/design-system/knowledge/design-systems/airbnb/DESIGN.md +246 -0
  65. package/dist/core/templates/skills/design-system/knowledge/design-systems/airtable/DESIGN.md +89 -0
  66. package/dist/core/templates/skills/design-system/knowledge/design-systems/apple/DESIGN.md +313 -0
  67. package/dist/core/templates/skills/design-system/knowledge/design-systems/bmw/DESIGN.md +180 -0
  68. package/dist/core/templates/skills/design-system/knowledge/design-systems/cal/DESIGN.md +259 -0
  69. package/dist/core/templates/skills/design-system/knowledge/design-systems/claude/DESIGN.md +312 -0
  70. package/dist/core/templates/skills/design-system/knowledge/design-systems/clay/DESIGN.md +304 -0
  71. package/dist/core/templates/skills/design-system/knowledge/design-systems/clickhouse/DESIGN.md +281 -0
  72. package/dist/core/templates/skills/design-system/knowledge/design-systems/cohere/DESIGN.md +266 -0
  73. package/dist/core/templates/skills/design-system/knowledge/design-systems/coinbase/DESIGN.md +129 -0
  74. package/dist/core/templates/skills/design-system/knowledge/design-systems/composio/DESIGN.md +307 -0
  75. package/dist/core/templates/skills/design-system/knowledge/design-systems/cursor/DESIGN.md +309 -0
  76. package/dist/core/templates/skills/design-system/knowledge/design-systems/elevenlabs/DESIGN.md +265 -0
  77. package/dist/core/templates/skills/design-system/knowledge/design-systems/expo/DESIGN.md +281 -0
  78. package/dist/core/templates/skills/design-system/knowledge/design-systems/figma/DESIGN.md +220 -0
  79. package/dist/core/templates/skills/design-system/knowledge/design-systems/framer/DESIGN.md +246 -0
  80. package/dist/core/templates/skills/design-system/knowledge/design-systems/hashicorp/DESIGN.md +278 -0
  81. package/dist/core/templates/skills/design-system/knowledge/design-systems/ibm/DESIGN.md +332 -0
  82. package/dist/core/templates/skills/design-system/knowledge/design-systems/index.json +72 -0
  83. package/dist/core/templates/skills/design-system/knowledge/design-systems/intercom/DESIGN.md +146 -0
  84. package/dist/core/templates/skills/design-system/knowledge/design-systems/kraken/DESIGN.md +125 -0
  85. package/dist/core/templates/skills/design-system/knowledge/design-systems/linear.app/DESIGN.md +367 -0
  86. package/dist/core/templates/skills/design-system/knowledge/design-systems/lovable/DESIGN.md +298 -0
  87. package/dist/core/templates/skills/design-system/knowledge/design-systems/minimax/DESIGN.md +257 -0
  88. package/dist/core/templates/skills/design-system/knowledge/design-systems/mintlify/DESIGN.md +326 -0
  89. package/dist/core/templates/skills/design-system/knowledge/design-systems/miro/DESIGN.md +108 -0
  90. package/dist/core/templates/skills/design-system/knowledge/design-systems/mistral.ai/DESIGN.md +261 -0
  91. package/dist/core/templates/skills/design-system/knowledge/design-systems/mongodb/DESIGN.md +266 -0
  92. package/dist/core/templates/skills/design-system/knowledge/design-systems/notion/DESIGN.md +309 -0
  93. package/dist/core/templates/skills/design-system/knowledge/design-systems/nvidia/DESIGN.md +293 -0
  94. package/dist/core/templates/skills/design-system/knowledge/design-systems/ollama/DESIGN.md +267 -0
  95. package/dist/core/templates/skills/design-system/knowledge/design-systems/opencode.ai/DESIGN.md +281 -0
  96. package/dist/core/templates/skills/design-system/knowledge/design-systems/pinterest/DESIGN.md +230 -0
  97. package/dist/core/templates/skills/design-system/knowledge/design-systems/posthog/DESIGN.md +256 -0
  98. package/dist/core/templates/skills/design-system/knowledge/design-systems/raycast/DESIGN.md +268 -0
  99. package/dist/core/templates/skills/design-system/knowledge/design-systems/replicate/DESIGN.md +261 -0
  100. package/dist/core/templates/skills/design-system/knowledge/design-systems/resend/DESIGN.md +303 -0
  101. package/dist/core/templates/skills/design-system/knowledge/design-systems/revolut/DESIGN.md +185 -0
  102. package/dist/core/templates/skills/design-system/knowledge/design-systems/runwayml/DESIGN.md +244 -0
  103. package/dist/core/templates/skills/design-system/knowledge/design-systems/sanity/DESIGN.md +357 -0
  104. package/dist/core/templates/skills/design-system/knowledge/design-systems/sentry/DESIGN.md +262 -0
  105. package/dist/core/templates/skills/design-system/knowledge/design-systems/spacex/DESIGN.md +194 -0
  106. package/dist/core/templates/skills/design-system/knowledge/design-systems/spotify/DESIGN.md +246 -0
  107. package/dist/core/templates/skills/design-system/knowledge/design-systems/stripe/DESIGN.md +322 -0
  108. package/dist/core/templates/skills/design-system/knowledge/design-systems/supabase/DESIGN.md +255 -0
  109. package/dist/core/templates/skills/design-system/knowledge/design-systems/superhuman/DESIGN.md +252 -0
  110. package/dist/core/templates/skills/design-system/knowledge/design-systems/together.ai/DESIGN.md +263 -0
  111. package/dist/core/templates/skills/design-system/knowledge/design-systems/uber/DESIGN.md +295 -0
  112. package/dist/core/templates/skills/design-system/knowledge/design-systems/vercel/DESIGN.md +310 -0
  113. package/dist/core/templates/skills/design-system/knowledge/design-systems/voltagent/DESIGN.md +323 -0
  114. package/dist/core/templates/skills/design-system/knowledge/design-systems/warp/DESIGN.md +253 -0
  115. package/dist/core/templates/skills/design-system/knowledge/design-systems/webflow/DESIGN.md +92 -0
  116. package/dist/core/templates/skills/design-system/knowledge/design-systems/wise/DESIGN.md +173 -0
  117. package/dist/core/templates/skills/design-system/knowledge/design-systems/x.ai/DESIGN.md +257 -0
  118. package/dist/core/templates/skills/design-system/knowledge/design-systems/zapier/DESIGN.md +328 -0
  119. package/dist/core/templates/skills/design-system/skill.md +176 -0
  120. package/dist/core/templates/skills/documents/skill.md +104 -0
  121. package/dist/core/templates/skills/e2e-test/skill.md +119 -0
  122. package/dist/core/templates/skills/email-sequence/skill.md +68 -0
  123. package/dist/core/templates/skills/email-sequence/skill.vi.md +68 -0
  124. package/dist/core/templates/skills/email-sequence-skill.md +68 -0
  125. package/dist/core/templates/skills/email-sequence-skill.vi.md +68 -0
  126. package/dist/core/templates/skills/git-embed/skill.md +57 -0
  127. package/dist/core/templates/skills/integration-test/skill.md +118 -0
  128. package/dist/core/templates/skills/knowledge/README.md +63 -63
  129. package/dist/core/templates/skills/knowledge/design-systems/index.json +72 -72
  130. package/dist/core/templates/skills/knowledge/frameworks/php/codeigniter/rise-cms/profile.json +27 -27
  131. package/dist/core/templates/skills/knowledge/frameworks/php/codeigniter/rise-cms/structure.md +137 -137
  132. package/dist/core/templates/skills/knowledge/frameworks/php/laravel/botble/profile.json +39 -39
  133. package/dist/core/templates/skills/knowledge/frameworks/php/laravel/botble/structure.md +207 -207
  134. package/dist/core/templates/skills/knowledge/frameworks/php/wordpress/core/profile.json +51 -51
  135. package/dist/core/templates/skills/knowledge/frameworks/php/wordpress/core/structure.md +369 -369
  136. package/dist/core/templates/skills/knowledge/index.json +65 -65
  137. package/dist/core/templates/skills/perfex-module/code-quality-guidelines/skill.md +130 -0
  138. package/dist/core/templates/skills/perfex-module/envato-review-guidelines/skill.md +132 -0
  139. package/dist/core/templates/skills/perfex-module/module-codebase/scripts/scaffold-module.js +151 -0
  140. package/dist/core/templates/skills/perfex-module/module-codebase/skill.md +204 -0
  141. package/dist/core/templates/skills/perfex-module/module-codebase/templates/Test_Module.php +79 -0
  142. package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-admin.php +71 -0
  143. package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-api.php +58 -0
  144. package/dist/core/templates/skills/perfex-module/module-codebase/templates/deploy.ps1 +97 -0
  145. package/dist/core/templates/skills/perfex-module/module-codebase/templates/helper.php +97 -0
  146. package/dist/core/templates/skills/perfex-module/module-codebase/templates/install.php +30 -0
  147. package/dist/core/templates/skills/perfex-module/module-codebase/templates/model-main.php +94 -0
  148. package/dist/core/templates/skills/perfex-module/module-codebase/templates/module-main.php +91 -0
  149. package/dist/core/templates/skills/perfex-module/module-codebase/templates/package.json +30 -0
  150. package/dist/core/templates/skills/perfex-module/module-codebase/templates/uninstall.php +11 -0
  151. package/dist/core/templates/skills/perfex-module/module-codebase/templates/webpack.config.js +163 -0
  152. package/dist/core/templates/skills/perfex-module/skill.md +50 -0
  153. package/dist/core/templates/skills/project-memory/skill.md +222 -0
  154. package/dist/core/templates/skills/project-memory/skill.vi.md +223 -0
  155. package/dist/core/templates/skills/seo-audit/skill.md +75 -0
  156. package/dist/core/templates/skills/seo-audit/skill.vi.md +75 -0
  157. package/dist/core/templates/skills/seo-audit-skill.md +75 -0
  158. package/dist/core/templates/skills/seo-audit-skill.vi.md +75 -0
  159. package/dist/core/templates/skills/smart-explore/skill.md +141 -0
  160. package/dist/core/templates/skills/sourcecode-analyzer/skill.md +210 -0
  161. package/dist/core/templates/skills/sourcecode-analyzer/skill.vi.md +210 -0
  162. package/dist/core/templates/skills/spec-writer/skill.md +61 -0
  163. package/dist/core/templates/skills/spec-writer/skill.vi.md +61 -0
  164. package/dist/core/templates/skills/spec-writer-skill.md +61 -0
  165. package/dist/core/templates/skills/spec-writer-skill.vi.md +61 -0
  166. package/dist/core/templates/skills/sql-queries/skill.md +67 -0
  167. package/dist/core/templates/skills/sql-queries/skill.vi.md +67 -0
  168. package/dist/core/templates/skills/sql-queries-skill.md +67 -0
  169. package/dist/core/templates/skills/sql-queries-skill.vi.md +67 -0
  170. package/dist/core/templates/skills/suggestion/skill.md +118 -0
  171. package/dist/core/templates/skills/system-design/skill.md +70 -0
  172. package/dist/core/templates/skills/system-design/skill.vi.md +70 -0
  173. package/dist/core/templates/skills/system-design-skill.md +70 -0
  174. package/dist/core/templates/skills/system-design-skill.vi.md +70 -0
  175. package/dist/core/templates/skills/tech-debt/skill.md +70 -0
  176. package/dist/core/templates/skills/tech-debt/skill.vi.md +70 -0
  177. package/dist/core/templates/skills/tech-debt-skill.md +70 -0
  178. package/dist/core/templates/skills/tech-debt-skill.vi.md +70 -0
  179. package/dist/core/templates/skills/ui-ux/data/charts.csv +26 -0
  180. package/dist/core/templates/skills/ui-ux/data/colors.csv +97 -0
  181. package/dist/core/templates/skills/ui-ux/data/design-systems.csv +54 -0
  182. package/dist/core/templates/skills/ui-ux/data/landing.csv +31 -0
  183. package/dist/core/templates/skills/ui-ux/data/pages-proposed.csv +22 -0
  184. package/dist/core/templates/skills/ui-ux/data/pages.csv +10 -0
  185. package/dist/core/templates/skills/ui-ux/data/products.csv +97 -0
  186. package/dist/core/templates/skills/ui-ux/data/prompts.csv +24 -0
  187. package/dist/core/templates/skills/ui-ux/data/stacks/flutter.csv +53 -0
  188. package/dist/core/templates/skills/ui-ux/data/stacks/html-tailwind.csv +56 -0
  189. package/dist/core/templates/skills/ui-ux/data/stacks/nextjs.csv +53 -0
  190. package/dist/core/templates/skills/ui-ux/data/stacks/react-native.csv +52 -0
  191. package/dist/core/templates/skills/ui-ux/data/stacks/react.csv +54 -0
  192. package/dist/core/templates/skills/ui-ux/data/stacks/svelte.csv +54 -0
  193. package/dist/core/templates/skills/ui-ux/data/stacks/swiftui.csv +51 -0
  194. package/dist/core/templates/skills/ui-ux/data/stacks/vue.csv +50 -0
  195. package/dist/core/templates/skills/ui-ux/data/styles.csv +59 -0
  196. package/dist/core/templates/skills/ui-ux/data/typography.csv +58 -0
  197. package/dist/core/templates/skills/ui-ux/data/ux-guidelines.csv +100 -0
  198. package/dist/core/templates/skills/ui-ux/scripts/CODE_EXPLANATION.md +394 -0
  199. package/dist/core/templates/skills/ui-ux/scripts/SEARCH_ALGORITHMS_COMPARISON.md +421 -0
  200. package/dist/core/templates/skills/ui-ux/scripts/SEARCH_MODES_GUIDE.md +238 -0
  201. package/dist/core/templates/skills/ui-ux/scripts/core.py +391 -0
  202. package/dist/core/templates/skills/ui-ux/scripts/search.py +73 -0
  203. package/dist/core/templates/skills/ui-ux/skill.md +595 -0
  204. package/dist/core/templates/skills/ui-ux/templates/accessibility-checklist.md +40 -0
  205. package/dist/core/templates/skills/ui-ux/templates/example-prompt-full-theme.md +333 -0
  206. package/dist/core/templates/skills/ui-ux/templates/page-types-guide.md +338 -0
  207. package/dist/core/templates/skills/ui-ux/templates/pages-proposed-summary.md +273 -0
  208. package/dist/core/templates/skills/ui-ux/templates/pre-delivery-checklist.md +42 -0
  209. package/dist/core/templates/skills/ui-ux/templates/prompt-template-full-theme.md +313 -0
  210. package/dist/core/templates/skills/ui-ux/templates/responsive-design.md +40 -0
  211. package/dist/core/templates/skills/unit-test/skill.md +111 -0
  212. package/dist/core/templates/skills/wordpress/plugin-check/skill.md +151 -0
  213. package/dist/core/templates/skills/wordpress/plugin-directory/skill.md +396 -0
  214. package/dist/core/templates/skills/wordpress/plugin-standard/skill.md +100 -0
  215. package/dist/core/templates/skills/wordpress/plugin-standard/templates/admin-dashboard.php +47 -0
  216. package/dist/core/templates/skills/wordpress/plugin-standard/templates/admin-settings.php +60 -0
  217. package/dist/core/templates/skills/wordpress/plugin-standard/templates/assets/admin-css.css +22 -0
  218. package/dist/core/templates/skills/wordpress/plugin-standard/templates/assets/admin-js.js +15 -0
  219. package/dist/core/templates/skills/wordpress/plugin-standard/templates/plugin-main.php +169 -0
  220. package/dist/core/templates/skills/wordpress/plugin-standard/templates/readme.txt +41 -0
  221. package/dist/core/templates/skills/wordpress/plugin-standard/templates/uninstall.php +21 -0
  222. package/dist/core/templates/skills/wordpress/ux-element/skill.md +83 -0
  223. package/dist/core/templates/skills/wordpress/ux-element/templates/Controller.php +50 -0
  224. package/dist/core/templates/skills/wordpress/ux-element/templates/Shortcode.php +23 -0
  225. package/dist/core/templates/skills/wordpress/ux-element/templates/Template.html +20 -0
  226. package/dist/core/templates/skills/wordpress/ux-element/templates/Thumbnail.svg +8 -0
  227. package/dist/core/templates/skills/wordpress/ux-element/templates/View.php +21 -0
  228. package/dist/core/templates/skills-template-map.d.ts +29 -0
  229. package/dist/core/validation/validator.d.ts +26 -0
  230. package/dist/core/view.d.ts +4 -0
  231. package/dist/index.d.ts +11 -0
  232. package/dist/index.js +350 -114
  233. package/dist/utils/file-system.d.ts +19 -0
  234. package/dist/utils/index.d.ts +6 -0
  235. package/dist/utils/task-parser.d.ts +26 -0
  236. package/package.json +2 -2
@@ -0,0 +1,204 @@
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
+ }
@@ -0,0 +1,97 @@
1
+ <?php
2
+ defined('BASEPATH') or exit('No direct script access allowed');
3
+
4
+ /**
5
+ * {ModuleName} Helper
6
+ *
7
+ * Provides asset rendering with dist/ fallback, cache busting, and utility helpers.
8
+ */
9
+ class {module_name}_helper
10
+ {
11
+ /**
12
+ * Get file timestamp for zero-downtime cache busting
13
+ */
14
+ public static function get_file_timestamp($relative_path)
15
+ {
16
+ $full_path = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $relative_path);
17
+ return file_exists($full_path) ? filemtime($full_path) : '1.0.0';
18
+ }
19
+
20
+ /**
21
+ * Render module custom JS with dist fallback & cache busting
22
+ *
23
+ * @param string $subpath Relative path inside assets/js/ (without .js extension)
24
+ * @return string HTML script tag
25
+ */
26
+ public static function render_module_js($subpath)
27
+ {
28
+ $rel_dist = 'dist/assets/js/' . $subpath . '.min.js';
29
+ $rel_src = 'assets/js/' . $subpath . '.js';
30
+
31
+ $full_dist = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_dist);
32
+ $full_src = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_src);
33
+
34
+ $chosen = file_exists($full_dist) ? $rel_dist : $rel_src;
35
+ $path = 'modules/' . {MODULE_UPPERCASE}_MODULE_NAME . '/' . $chosen;
36
+ $url = module_dir_url({MODULE_UPPERCASE}_MODULE_NAME, $chosen);
37
+ $v = self::get_file_timestamp($path);
38
+
39
+ return '<script src="' . $url . '?v=' . $v . '"></script>' . PHP_EOL;
40
+ }
41
+
42
+ /**
43
+ * Render module custom CSS with dist fallback & cache busting
44
+ *
45
+ * @param string $subpath Relative path inside assets/css/ (without .css extension)
46
+ * @return string HTML link tag
47
+ */
48
+ public static function render_module_css($subpath)
49
+ {
50
+ $rel_dist = 'dist/assets/css/' . $subpath . '.min.css';
51
+ $rel_src = 'assets/css/' . $subpath . '.css';
52
+
53
+ $full_dist = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_dist);
54
+ $full_src = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_src);
55
+
56
+ $chosen = file_exists($full_dist) ? $rel_dist : $rel_src;
57
+ $path = 'modules/' . {MODULE_UPPERCASE}_MODULE_NAME . '/' . $chosen;
58
+ $url = module_dir_url({MODULE_UPPERCASE}_MODULE_NAME, $chosen);
59
+ $v = self::get_file_timestamp($path);
60
+
61
+ return '<link rel="stylesheet" href="' . $url . '?v=' . $v . '">' . PHP_EOL;
62
+ }
63
+
64
+ /**
65
+ * Render third-party vendor library JS from lib/
66
+ */
67
+ public static function render_lib_js($library)
68
+ {
69
+ $rel_dist = 'dist/assets/js/lib/' . $library . '.js';
70
+ $rel_src = 'assets/js/lib/' . $library . '.js';
71
+
72
+ $full_dist = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_dist);
73
+ $chosen = file_exists($full_dist) ? $rel_dist : $rel_src;
74
+ $path = 'modules/' . {MODULE_UPPERCASE}_MODULE_NAME . '/' . $chosen;
75
+ $url = module_dir_url({MODULE_UPPERCASE}_MODULE_NAME, $chosen);
76
+ $v = self::get_file_timestamp($path);
77
+
78
+ return '<script src="' . $url . '?v=' . $v . '"></script>' . PHP_EOL;
79
+ }
80
+
81
+ /**
82
+ * Render third-party vendor library CSS from lib/
83
+ */
84
+ public static function render_lib_css($library)
85
+ {
86
+ $rel_dist = 'dist/assets/css/lib/' . $library . '.css';
87
+ $rel_src = 'assets/css/lib/' . $library . '.css';
88
+
89
+ $full_dist = rtrim(FCPATH, '/\\') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . {MODULE_UPPERCASE}_MODULE_NAME . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel_dist);
90
+ $chosen = file_exists($full_dist) ? $rel_dist : $rel_src;
91
+ $path = 'modules/' . {MODULE_UPPERCASE}_MODULE_NAME . '/' . $chosen;
92
+ $url = module_dir_url({MODULE_UPPERCASE}_MODULE_NAME, $chosen);
93
+ $v = self::get_file_timestamp($path);
94
+
95
+ return '<link rel="stylesheet" href="' . $url . '?v=' . $v . '">' . PHP_EOL;
96
+ }
97
+ }
@@ -0,0 +1,30 @@
1
+ <?php
2
+ defined('BASEPATH') or exit('No direct script access allowed');
3
+
4
+ $CI = &get_instance();
5
+
6
+ // Create primary entity table if not exists
7
+ if (!$CI->db->table_exists(db_prefix() . '{module_name}_items')) {
8
+ $CI->db->query('CREATE TABLE `' . db_prefix() . '{module_name}_items` (
9
+ `id` INT(11) NOT NULL AUTO_INCREMENT,
10
+ `rel_type` VARCHAR(40) NOT NULL,
11
+ `rel_id` INT(11) NOT NULL,
12
+ `title` VARCHAR(255) NOT NULL,
13
+ `description` TEXT NULL,
14
+ `status` TINYINT(1) NOT NULL DEFAULT 1,
15
+ `date_created` DATETIME NOT NULL,
16
+ `created_by` INT(11) NOT NULL,
17
+ PRIMARY KEY (`id`),
18
+ KEY `idx_rel_lookup` (`rel_type`, `rel_id`),
19
+ KEY `idx_status_created` (`status`, `date_created`)
20
+ ) ENGINE=InnoDB DEFAULT CHARSET=' . $CI->db->char_set . ';');
21
+ }
22
+
23
+ // Add default module options if not exists
24
+ if (empty(get_option('{module_name}_enabled'))) {
25
+ add_option('{module_name}_enabled', '1', 1);
26
+ }
27
+
28
+ if (empty(get_option('{module_name}_version'))) {
29
+ add_option('{module_name}_version', '1.0.0', 1);
30
+ }