heraspec 0.1.15 → 0.1.17
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/README.md +109 -71
- package/bin/heraspec.js +1866 -89
- package/bin/heraspec.js.map +4 -4
- package/dist/cli/index.d.ts +2 -0
- package/dist/commands/audit.d.ts +37 -0
- package/dist/commands/create.d.ts +12 -0
- package/dist/commands/explore.d.ts +17 -0
- package/dist/commands/helper.d.ts +13 -0
- package/dist/commands/hotfix.d.ts +9 -0
- package/dist/commands/make-code.d.ts +14 -0
- package/dist/commands/make-docs.d.ts +36 -0
- package/dist/commands/make-test.d.ts +60 -0
- package/dist/commands/memory.d.ts +101 -0
- package/dist/commands/pack.d.ts +17 -0
- package/dist/commands/show.d.ts +8 -0
- package/dist/commands/skill.d.ts +8 -0
- package/dist/commands/suggest.d.ts +32 -0
- package/dist/commands/validate.d.ts +8 -0
- package/dist/core/archive.d.ts +14 -0
- package/dist/core/config.d.ts +33 -0
- package/dist/core/init.d.ts +101 -0
- package/dist/core/list.d.ts +7 -0
- package/dist/core/memory/config-advisor.d.ts +30 -0
- package/dist/core/memory/context-config.d.ts +14 -0
- package/dist/core/memory/context-generator.d.ts +19 -0
- package/dist/core/memory/index.d.ts +12 -0
- package/dist/core/memory/memory-schema.d.ts +34 -0
- package/dist/core/memory/memory-search.d.ts +45 -0
- package/dist/core/memory/memory-store.d.ts +71 -0
- package/dist/core/memory/memory-types.d.ts +159 -0
- package/dist/core/memory/memory-vector.d.ts +23 -0
- package/dist/core/parsers/code-parser.d.ts +53 -0
- package/dist/core/parsers/markdown-parser.d.ts +18 -0
- package/dist/core/restore.d.ts +9 -0
- package/dist/core/schemas/base.schema.d.ts +58 -0
- package/dist/core/schemas/change.schema.d.ts +35 -0
- package/dist/core/schemas/index.d.ts +7 -0
- package/dist/core/schemas/spec.schema.d.ts +52 -0
- package/dist/core/skills/index.d.ts +6 -0
- package/dist/core/skills/skill-manager.d.ts +28 -0
- package/dist/core/skills/skill-parser.d.ts +24 -0
- package/dist/core/sync.d.ts +6 -0
- package/dist/core/templates/index.d.ts +10 -0
- package/dist/core/templates/skills/README.md +4 -1
- package/dist/core/templates/skills/content-channel/content-compliance/skill.md +83 -0
- package/dist/core/templates/skills/content-channel/content-prompts/skill.md +74 -0
- package/dist/core/templates/skills/content-channel/content-scaffolding/skill.md +82 -0
- package/dist/core/templates/skills/content-channel/content-scripting/skill.md +147 -0
- package/dist/core/templates/skills/content-channel/content-strategy/skill.md +78 -0
- package/dist/core/templates/skills/content-channel/content-vault-sync/skill.md +74 -0
- package/dist/core/templates/skills/content-channel/content-voice-adapter/skill.md +143 -0
- package/dist/core/templates/skills/content-channel/skill.md +127 -0
- package/dist/core/templates/skills/perfex-module/code-quality-guidelines/skill.md +130 -0
- package/dist/core/templates/skills/perfex-module/envato-review-guidelines/skill.md +132 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/scripts/scaffold-module.js +151 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/skill.md +204 -110
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/Test_Module.php +79 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-admin.php +71 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/controller-api.php +58 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/deploy.ps1 +97 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/helper.php +97 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/install.php +30 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/model-main.php +94 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/module-main.php +91 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/package.json +30 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/uninstall.php +11 -0
- package/dist/core/templates/skills/perfex-module/module-codebase/templates/webpack.config.js +163 -0
- package/dist/core/templates/skills/perfex-module/skill.md +50 -0
- package/dist/core/templates/skills-template-map.d.ts +29 -0
- package/dist/core/validation/validator.d.ts +26 -0
- package/dist/core/view.d.ts +4 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +383 -50
- package/dist/utils/file-system.d.ts +19 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/task-parser.d.ts +26 -0
- package/package.json +2 -2
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
defined('BASEPATH') or exit('No direct script access allowed');
|
|
3
|
+
|
|
4
|
+
class {ModuleName}_model extends App_Model
|
|
5
|
+
{
|
|
6
|
+
protected $table;
|
|
7
|
+
|
|
8
|
+
public function __construct()
|
|
9
|
+
{
|
|
10
|
+
parent::__construct();
|
|
11
|
+
$this->table = db_prefix() . '{module_name}_items';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get all items with optional filters
|
|
16
|
+
*/
|
|
17
|
+
public function get_all($where = [])
|
|
18
|
+
{
|
|
19
|
+
if (!empty($where)) {
|
|
20
|
+
$this->db->where($where);
|
|
21
|
+
}
|
|
22
|
+
$this->db->order_by('date_created', 'DESC');
|
|
23
|
+
return $this->db->get($this->table)->result_array();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get single item by ID
|
|
28
|
+
*/
|
|
29
|
+
public function get($id)
|
|
30
|
+
{
|
|
31
|
+
$this->db->where('id', (int)$id);
|
|
32
|
+
return $this->db->get($this->table)->row_array();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Add new item
|
|
37
|
+
*/
|
|
38
|
+
public function add($data)
|
|
39
|
+
{
|
|
40
|
+
$data['date_created'] = date('Y-m-d H:i:s');
|
|
41
|
+
$data['created_by'] = get_staff_user_id();
|
|
42
|
+
|
|
43
|
+
$this->db->insert($this->table, $data);
|
|
44
|
+
$insert_id = $this->db->insert_id();
|
|
45
|
+
|
|
46
|
+
if ($insert_id) {
|
|
47
|
+
log_activity('{ModuleName} Item Added [ID: ' . $insert_id . ']');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return $insert_id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Update item by ID
|
|
55
|
+
*/
|
|
56
|
+
public function update($id, $data)
|
|
57
|
+
{
|
|
58
|
+
$this->db->where('id', (int)$id);
|
|
59
|
+
$this->db->update($this->table, $data);
|
|
60
|
+
|
|
61
|
+
return $this->db->affected_rows() > 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Delete item by ID
|
|
66
|
+
*/
|
|
67
|
+
public function delete($id)
|
|
68
|
+
{
|
|
69
|
+
$this->db->where('id', (int)$id);
|
|
70
|
+
$this->db->delete($this->table);
|
|
71
|
+
|
|
72
|
+
$deleted = $this->db->affected_rows() > 0;
|
|
73
|
+
if ($deleted) {
|
|
74
|
+
log_activity('{ModuleName} Item Deleted [ID: ' . (int)$id . ']');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return $deleted;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Search items using polymorphic composite index
|
|
82
|
+
*/
|
|
83
|
+
public function search($query, $limit = 20)
|
|
84
|
+
{
|
|
85
|
+
$this->db->select('id, rel_type, rel_id, title, status, date_created');
|
|
86
|
+
$this->db->from($this->table);
|
|
87
|
+
if (!empty($query)) {
|
|
88
|
+
$this->db->like('title', $query);
|
|
89
|
+
}
|
|
90
|
+
$this->db->where('status', 1);
|
|
91
|
+
$this->db->limit($limit);
|
|
92
|
+
return $this->db->get()->result_array();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
defined('BASEPATH') or exit('No direct script access allowed');
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Module Name: {MODULE_FRIENDLY_NAME}
|
|
6
|
+
Description: {MODULE_DESCRIPTION}
|
|
7
|
+
Version: 1.0.0
|
|
8
|
+
Requires at least: 2.9.*
|
|
9
|
+
Author: PolyXGO
|
|
10
|
+
Author URI: https://codecanyon.net/user/polyxgo
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
define('{MODULE_UPPERCASE}_MODULE_NAME', '{module_name}');
|
|
14
|
+
define('{MODULE_UPPERCASE}_VERSION', '1.0.0');
|
|
15
|
+
|
|
16
|
+
// Register activation, deactivation, and uninstall hooks
|
|
17
|
+
register_activation_hook({MODULE_UPPERCASE}_MODULE_NAME, '{module_name}_activation_hook');
|
|
18
|
+
register_deactivation_hook({MODULE_UPPERCASE}_MODULE_NAME, '{module_name}_deactivation_hook');
|
|
19
|
+
register_uninstall_hook({MODULE_UPPERCASE}_MODULE_NAME, '{module_name}_uninstall_hook');
|
|
20
|
+
|
|
21
|
+
function {module_name}_activation_hook()
|
|
22
|
+
{
|
|
23
|
+
$CI = &get_instance();
|
|
24
|
+
require_once(__DIR__ . '/install.php');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function {module_name}_deactivation_hook()
|
|
28
|
+
{
|
|
29
|
+
// Clean up temporary session flags or cache if needed
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function {module_name}_uninstall_hook()
|
|
33
|
+
{
|
|
34
|
+
require_once(__DIR__ . '/uninstall.php');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Register language files
|
|
38
|
+
register_language_files({MODULE_UPPERCASE}_MODULE_NAME, [{MODULE_UPPERCASE}_MODULE_NAME]);
|
|
39
|
+
|
|
40
|
+
// Autoload helper
|
|
41
|
+
$CI = &get_instance();
|
|
42
|
+
$CI->load->helper({MODULE_UPPERCASE}_MODULE_NAME . '/{module_name}');
|
|
43
|
+
|
|
44
|
+
// Hook: Register Admin Menu Item
|
|
45
|
+
hooks()->add_action('admin_init', '{module_name}_init_menu_items');
|
|
46
|
+
|
|
47
|
+
function {module_name}_init_menu_items()
|
|
48
|
+
{
|
|
49
|
+
$CI = &get_instance();
|
|
50
|
+
if (has_permission('{module_name}', '', 'view')) {
|
|
51
|
+
$CI->app_menu->add_sidebar_menu_item('{module_name}-menu', [
|
|
52
|
+
'name' => _l('{module_name}_menu_title'),
|
|
53
|
+
'href' => admin_url('{module_name}'),
|
|
54
|
+
'icon' => 'fa-solid fa-cube',
|
|
55
|
+
'position' => 30,
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Hook: Enqueue Admin Assets & Localization
|
|
61
|
+
hooks()->add_action('app_admin_head', '{module_name}_enqueue_admin_head');
|
|
62
|
+
hooks()->add_action('app_admin_footer', '{module_name}_enqueue_admin_footer');
|
|
63
|
+
|
|
64
|
+
function {module_name}_enqueue_admin_head()
|
|
65
|
+
{
|
|
66
|
+
// Centralized localization data - Zero inline script in views
|
|
67
|
+
$config = [
|
|
68
|
+
'moduleName' => {MODULE_UPPERCASE}_MODULE_NAME,
|
|
69
|
+
'version' => {MODULE_UPPERCASE}_VERSION,
|
|
70
|
+
'adminUrl' => admin_url('{module_name}/'),
|
|
71
|
+
'csrfToken' => get_instance()->security->get_csrf_hash(),
|
|
72
|
+
];
|
|
73
|
+
$lang = [
|
|
74
|
+
'confirmDelete' => _l('{module_name}_confirm_delete'),
|
|
75
|
+
'saveSuccess' => _l('{module_name}_saved_successfully'),
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
echo '<script>' . PHP_EOL;
|
|
79
|
+
echo 'window.' . '{MODULE_UPPERCASE}_CONFIG = ' . json_encode($config) . ';' . PHP_EOL;
|
|
80
|
+
echo 'window.' . '{MODULE_UPPERCASE}_LANG = ' . json_encode($lang) . ';' . PHP_EOL;
|
|
81
|
+
echo '</script>' . PHP_EOL;
|
|
82
|
+
|
|
83
|
+
// Load custom stylesheet with auto dist fallback and cache busting
|
|
84
|
+
echo {module_name}_helper::render_module_css('admin/{module_name}_admin');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function {module_name}_enqueue_admin_footer()
|
|
88
|
+
{
|
|
89
|
+
// Load custom scripts with auto dist fallback and cache busting
|
|
90
|
+
echo {module_name}_helper::render_module_js('admin/{module_name}_admin');
|
|
91
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{module_name}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "{MODULE_DESCRIPTION}",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "webpack --mode production",
|
|
8
|
+
"dev": "webpack --mode development",
|
|
9
|
+
"watch": "webpack --mode development --watch"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"perfex",
|
|
13
|
+
"perfex-crm",
|
|
14
|
+
"module"
|
|
15
|
+
],
|
|
16
|
+
"author": "PolyXGO",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/core": "^7.24.7",
|
|
20
|
+
"@babel/preset-env": "^7.24.7",
|
|
21
|
+
"babel-loader": "^9.1.3",
|
|
22
|
+
"clean-css": "^5.3.3",
|
|
23
|
+
"clean-css-cli": "^5.6.3",
|
|
24
|
+
"fs-extra": "^11.2.0",
|
|
25
|
+
"glob": "^8.1.0",
|
|
26
|
+
"terser-webpack-plugin": "^5.3.10",
|
|
27
|
+
"webpack": "^5.92.0",
|
|
28
|
+
"webpack-cli": "^5.1.4"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
defined('BASEPATH') or exit('No direct script access allowed');
|
|
3
|
+
|
|
4
|
+
$CI = &get_instance();
|
|
5
|
+
|
|
6
|
+
// Delete module registered options
|
|
7
|
+
delete_option('{module_name}_enabled');
|
|
8
|
+
delete_option('{module_name}_version');
|
|
9
|
+
|
|
10
|
+
// Optional: Drop database tables if complete cleanup is requested
|
|
11
|
+
// $CI->db->query('DROP TABLE IF EXISTS `' . db_prefix() . '{module_name}_items`');
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack Configuration for Perfex CRM Module
|
|
3
|
+
*
|
|
4
|
+
* Compiles and minifies development assets from assets/ into dist/assets/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const is_console_remove = true;
|
|
8
|
+
const is_minimize = true;
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
11
|
+
const glob = require("glob");
|
|
12
|
+
const fs = require("fs-extra");
|
|
13
|
+
const CleanCSS = require("clean-css");
|
|
14
|
+
|
|
15
|
+
// Plugin to delete the dist folder before compilation starts
|
|
16
|
+
class CleanDistFolderPlugin {
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
compiler.hooks.beforeRun.tapAsync(
|
|
19
|
+
"CleanDistFolderPlugin",
|
|
20
|
+
(compilation, callback) => {
|
|
21
|
+
const distPath = path.resolve(__dirname, "dist");
|
|
22
|
+
if (fs.existsSync(distPath)) {
|
|
23
|
+
fs.removeSync(distPath);
|
|
24
|
+
}
|
|
25
|
+
callback();
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Plugin to copy library files directly to dist without mangling
|
|
32
|
+
class CopyLibFilesPlugin {
|
|
33
|
+
apply(compiler) {
|
|
34
|
+
compiler.hooks.afterEmit.tap("CopyLibFilesPlugin", () => {
|
|
35
|
+
const jsLibPath = path.resolve(__dirname, "./assets/js/lib");
|
|
36
|
+
const cssLibPath = path.resolve(__dirname, "./assets/css/lib");
|
|
37
|
+
const distJsLibPath = path.resolve(__dirname, "dist/assets/js/lib");
|
|
38
|
+
const distCssLibPath = path.resolve(__dirname, "dist/assets/css/lib");
|
|
39
|
+
|
|
40
|
+
if (fs.existsSync(jsLibPath)) {
|
|
41
|
+
fs.copySync(jsLibPath, distJsLibPath, { overwrite: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (fs.existsSync(cssLibPath)) {
|
|
45
|
+
fs.copySync(cssLibPath, distCssLibPath, { overwrite: true });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Plugin to minify custom CSS files using CleanCSS
|
|
52
|
+
class MinifyCssPlugin {
|
|
53
|
+
apply(compiler) {
|
|
54
|
+
compiler.hooks.afterEmit.tap("MinifyCssPlugin", () => {
|
|
55
|
+
const cssFiles = glob.sync("./assets/css/**/!(*.min).css", {
|
|
56
|
+
ignore: ["./assets/css/lib/**/*"],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const cleanCssInstance = new CleanCSS({
|
|
60
|
+
level: 1,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
cssFiles.forEach((file) => {
|
|
64
|
+
const relativePath = path.relative("./assets", file);
|
|
65
|
+
const minifiedFile = path.resolve(
|
|
66
|
+
__dirname,
|
|
67
|
+
"dist/assets",
|
|
68
|
+
relativePath.replace(/\.css$/, ".min.css")
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const sourceContent = fs.readFileSync(file, "utf8");
|
|
73
|
+
const minifiedOutput = cleanCssInstance.minify(sourceContent);
|
|
74
|
+
if (minifiedOutput.styles) {
|
|
75
|
+
fs.outputFileSync(minifiedFile, minifiedOutput.styles);
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(`Error minifying ${file}:`, err);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Scan custom JS files excluding lib and .min.js
|
|
86
|
+
const jsFiles = glob.sync("./assets/js/**/*.js", {
|
|
87
|
+
ignore: [
|
|
88
|
+
"./assets/js/lib/**/*",
|
|
89
|
+
"./assets/js/**/*.min.js"
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const jsEntry = jsFiles.reduce((entries, file) => {
|
|
94
|
+
const name = path
|
|
95
|
+
.relative("./assets", file)
|
|
96
|
+
.replace(/\\/g, "/")
|
|
97
|
+
.replace(/\.js$/, "");
|
|
98
|
+
entries[name] = `./${file}`;
|
|
99
|
+
return entries;
|
|
100
|
+
}, {});
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
entry: jsEntry,
|
|
104
|
+
output: {
|
|
105
|
+
filename: (pathData) => {
|
|
106
|
+
const filePath = pathData.chunk.name.replace(/\\/g, "/");
|
|
107
|
+
return `${filePath}.min.js`;
|
|
108
|
+
},
|
|
109
|
+
path: path.resolve(__dirname, "dist/assets/"),
|
|
110
|
+
},
|
|
111
|
+
resolve: {
|
|
112
|
+
modules: [path.resolve(__dirname), "node_modules"],
|
|
113
|
+
extensions: [".js"],
|
|
114
|
+
},
|
|
115
|
+
optimization: {
|
|
116
|
+
minimize: is_minimize,
|
|
117
|
+
minimizer: [
|
|
118
|
+
new TerserPlugin({
|
|
119
|
+
test: /\.js$/,
|
|
120
|
+
exclude: /assets\/js\/lib\//,
|
|
121
|
+
extractComments: false,
|
|
122
|
+
terserOptions: {
|
|
123
|
+
compress: {
|
|
124
|
+
drop_console: is_console_remove,
|
|
125
|
+
dead_code: true,
|
|
126
|
+
drop_debugger: true,
|
|
127
|
+
},
|
|
128
|
+
mangle: {
|
|
129
|
+
keep_classnames: true,
|
|
130
|
+
keep_fnames: true,
|
|
131
|
+
},
|
|
132
|
+
output: {
|
|
133
|
+
comments: false,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
}),
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
module: {
|
|
140
|
+
rules: [
|
|
141
|
+
{
|
|
142
|
+
test: /\.js$/,
|
|
143
|
+
exclude: [
|
|
144
|
+
/node_modules/,
|
|
145
|
+
/assets\/js\/lib\//,
|
|
146
|
+
],
|
|
147
|
+
use: {
|
|
148
|
+
loader: "babel-loader",
|
|
149
|
+
options: {
|
|
150
|
+
presets: ["@babel/preset-env"],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
mode: "production",
|
|
157
|
+
plugins: [
|
|
158
|
+
new CleanDistFolderPlugin(),
|
|
159
|
+
new CopyLibFilesPlugin(),
|
|
160
|
+
new MinifyCssPlugin(),
|
|
161
|
+
],
|
|
162
|
+
devtool: false,
|
|
163
|
+
};
|