-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
115 lines (98 loc) · 2.79 KB
/
index.js
File metadata and controls
115 lines (98 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
const fs = require('fs');
const https = require('https');
const path = require('path');
const pluginName = process.argv[2];
if (!pluginName) {
console.error("❌ Usage: simpull-plugin-init <plugin-name>");
process.exit(1);
}
const pluginDir = path.join(process.cwd(), pluginName);
if (fs.existsSync(pluginDir)) {
console.error(`❌ Directory ${pluginName} already exists.`);
process.exit(1);
}
// Create folders
['', 'includes', 'src', 'assets', '.github/workflows'].forEach(folder =>
fs.mkdirSync(path.join(pluginDir, folder), { recursive: true })
);
// Download SimpullUpdater.php
https.get('https://raw.githubusercontent.com/zao-web/simpull-updater/main/SimpullUpdater.php', res => {
const dest = fs.createWriteStream(path.join(pluginDir, 'includes', 'SimpullUpdater.php'));
res.pipe(dest);
});
// Main plugin file
const pluginMain = `<?php
/**
* Plugin Name: ${pluginName.replace(/-/g, ' ')}
* Description: A Simpull plugin scaffold.
* Version: 0.1.0
* Requires PHP: 8.1
* Author: Simpull
*/
declare(strict_types=1);
require_once __DIR__ . '/includes/SimpullUpdater.php';
new SimpullUpdater(__FILE__, '${pluginName}/${pluginName}.php', 'simpull/${pluginName}');
`;
fs.writeFileSync(path.join(pluginDir, `${pluginName}.php`), pluginMain);
// src/Plugin.php
const pluginClass = `<?php
declare(strict_types=1);
namespace Simpull\\${pluginName.replace(/-/g, '')};
class Plugin {
public function run(): void {
// Plugin bootstrap logic
}
}
`;
fs.writeFileSync(path.join(pluginDir, 'src', 'Plugin.php'), pluginClass);
// composer.json
const composer = {
name: `simpull/${pluginName}`,
type: "wordpress-plugin",
require: {
"php": "^8.1"
},
autoload: {
"psr-4": {
"Simpull\\": "src/"
}
}
};
fs.writeFileSync(path.join(pluginDir, 'composer.json'), JSON.stringify(composer, null, 2));
// package.json
const pkg = {
name: pluginName,
version: "0.1.0",
scripts: {
build: "echo 'Add build scripts here'"
}
};
fs.writeFileSync(path.join(pluginDir, 'package.json'), JSON.stringify(pkg, null, 2));
// GitHub Actions workflow
const workflow = `name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: |
npm ci
composer install --no-dev --optimize-autoloader
- name: Zip Plugin
run: |
zip -r ${pluginName}.zip . -x '*.git*' '*.github*'
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
with:
files: ${pluginName}.zip
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
`;
fs.writeFileSync(path.join(pluginDir, '.github/workflows/release.yml'), workflow);
console.log(`✅ ${pluginName} scaffolded successfully.`);