@iservice-dev/is-wp-plugin-kit 1.5.5 → 1.6.1
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/bin/commands/build.js +11 -0
- package/bin/commands/compile-mo.js +10 -0
- package/bin/commands/dev.js +13 -0
- package/bin/commands/init.js +167 -0
- package/bin/is-wp-plugin-kit.js +24 -125
- package/bin/utils.js +30 -0
- package/files/.prettierrc +11 -0
- package/files/Config.php +20 -0
- package/files/Plugin.php +35 -0
- package/files/de_DE.po +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export function runBuild() {
|
|
4
|
+
execSync('oxlint assets/src/ts', { stdio: 'inherit' });
|
|
5
|
+
execSync('stylelint "assets/src/scss/**/*.scss" --fix', { stdio: 'inherit' });
|
|
6
|
+
execSync('vite build', { stdio: 'inherit' });
|
|
7
|
+
execSync('is-wp-plugin-kit compile-mo', { stdio: 'inherit' });
|
|
8
|
+
|
|
9
|
+
console.log('✓ Build completed');
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
|
|
6
|
+
export function runCompileMo() {
|
|
7
|
+
const moScript = path.resolve(__dirname, '../../files/compile-mo.mjs');
|
|
8
|
+
import(moScript);
|
|
9
|
+
process.exit(0);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export function runDev() {
|
|
4
|
+
execSync(
|
|
5
|
+
'concurrently -k ' +
|
|
6
|
+
'"vite" ' +
|
|
7
|
+
"\"chokidar 'assets/src/ts/**/*.ts' -c 'oxlint assets/src/ts'\" " +
|
|
8
|
+
"\"chokidar 'assets/src/scss/**/*.scss' -c 'stylelint \\\"assets/src/scss/**/*.scss\\\" --fix'\" " +
|
|
9
|
+
"\"chokidar 'assets/src/l10n/**/*.po' -c 'is-wp-plugin-kit compile-mo'\"",
|
|
10
|
+
{ stdio: 'inherit' }
|
|
11
|
+
);
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { copy } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const selfPkg = require('../../package.json');
|
|
11
|
+
|
|
12
|
+
const toolkitVersion = `^${selfPkg.version}`;
|
|
13
|
+
|
|
14
|
+
export function runInit() {
|
|
15
|
+
const root = process.cwd();
|
|
16
|
+
|
|
17
|
+
// ------------------------------------------
|
|
18
|
+
// 1) .gitignore kopieren
|
|
19
|
+
// ------------------------------------------
|
|
20
|
+
copy('gitignore');
|
|
21
|
+
|
|
22
|
+
// ------------------------------------------
|
|
23
|
+
// 2) stylelint config erzeugen
|
|
24
|
+
// ------------------------------------------
|
|
25
|
+
fs.writeFileSync(
|
|
26
|
+
path.join(root, '.stylelintrc.json'),
|
|
27
|
+
JSON.stringify(
|
|
28
|
+
{
|
|
29
|
+
extends: ['@iservice-dev/is-wp-plugin-kit/files/stylelintrc.json'],
|
|
30
|
+
},
|
|
31
|
+
null,
|
|
32
|
+
2
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
console.log('✓ Created .stylelintrc.json');
|
|
36
|
+
|
|
37
|
+
// ------------------------------------------
|
|
38
|
+
// 3) tsconfig erzeugen
|
|
39
|
+
// ------------------------------------------
|
|
40
|
+
fs.writeFileSync(
|
|
41
|
+
path.join(root, 'tsconfig.json'),
|
|
42
|
+
JSON.stringify(
|
|
43
|
+
{
|
|
44
|
+
extends: '@iservice-dev/is-wp-plugin-kit/files/tsconfig.json',
|
|
45
|
+
include: ['assets/src/ts/**/*.ts'],
|
|
46
|
+
},
|
|
47
|
+
null,
|
|
48
|
+
2
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
console.log('✓ Created tsconfig.json');
|
|
52
|
+
|
|
53
|
+
// ------------------------------------------
|
|
54
|
+
// 4) oxlintrc erzeugen
|
|
55
|
+
// ------------------------------------------
|
|
56
|
+
fs.writeFileSync(
|
|
57
|
+
path.join(root, '.oxlintrc.json'),
|
|
58
|
+
JSON.stringify(
|
|
59
|
+
{
|
|
60
|
+
extends: ['@iservice-dev/is-wp-plugin-kit/files/oxlintrc.json'],
|
|
61
|
+
},
|
|
62
|
+
null,
|
|
63
|
+
2
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
console.log('✓ Created .oxlintrc.json');
|
|
67
|
+
|
|
68
|
+
// ------------------------------------------
|
|
69
|
+
// 5) postcss config erzeugen
|
|
70
|
+
// ------------------------------------------
|
|
71
|
+
fs.writeFileSync(
|
|
72
|
+
path.join(root, 'postcss.config.cjs'),
|
|
73
|
+
`module.exports = require("@iservice-dev/is-wp-plugin-kit/files/postcss.config.cjs");\n`
|
|
74
|
+
);
|
|
75
|
+
console.log('✓ Created postcss.config.cjs');
|
|
76
|
+
|
|
77
|
+
// ------------------------------------------
|
|
78
|
+
// 6) vite.config.ts erzeugen
|
|
79
|
+
// ------------------------------------------
|
|
80
|
+
fs.writeFileSync(
|
|
81
|
+
path.join(root, 'vite.config.ts'),
|
|
82
|
+
`import { wpPluginKitVite } from "@iservice-dev/is-wp-plugin-kit/vite";
|
|
83
|
+
|
|
84
|
+
export default wpPluginKitVite({
|
|
85
|
+
port: 5500
|
|
86
|
+
});
|
|
87
|
+
`
|
|
88
|
+
);
|
|
89
|
+
console.log('✓ Created vite.config.ts');
|
|
90
|
+
|
|
91
|
+
// ------------------------------------------
|
|
92
|
+
// 7) package.json erzeugen (falls nicht vorhanden)
|
|
93
|
+
// ------------------------------------------
|
|
94
|
+
const pkgPath = path.join(root, 'package.json');
|
|
95
|
+
|
|
96
|
+
if (!fs.existsSync(pkgPath)) {
|
|
97
|
+
const pkg = {
|
|
98
|
+
name: path.basename(root),
|
|
99
|
+
version: '1.0.0',
|
|
100
|
+
type: 'module',
|
|
101
|
+
description: 'iService WordPress Plugin',
|
|
102
|
+
scripts: {
|
|
103
|
+
dev: 'is-wp-plugin-kit dev',
|
|
104
|
+
build: 'is-wp-plugin-kit build',
|
|
105
|
+
},
|
|
106
|
+
devDependencies: {
|
|
107
|
+
'@iservice-dev/is-wp-plugin-kit': toolkitVersion,
|
|
108
|
+
vite: '^7.1.7',
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
113
|
+
console.log('✓ Created package.json');
|
|
114
|
+
} else {
|
|
115
|
+
console.log('↺ package.json already exists – skipped');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ------------------------------------------
|
|
119
|
+
// 8) Ordnerstruktur erzeugen
|
|
120
|
+
// ------------------------------------------
|
|
121
|
+
const dirs = [
|
|
122
|
+
'assets/src/ts',
|
|
123
|
+
'assets/src/scss',
|
|
124
|
+
'assets/src/fonts',
|
|
125
|
+
'assets/src/images',
|
|
126
|
+
'assets/src/l10n',
|
|
127
|
+
'assets/src/legacy/js',
|
|
128
|
+
'assets/src/legacy/css',
|
|
129
|
+
'assets/dist',
|
|
130
|
+
'includes/lib/Admin',
|
|
131
|
+
'includes/lib/Core',
|
|
132
|
+
'includes/lib/Frontend',
|
|
133
|
+
'languages',
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
// Ordner die kein .gitkeep brauchen (bekommen andere Dateien)
|
|
137
|
+
const skipGitkeep = ['assets/src/l10n', 'includes/lib/Core'];
|
|
138
|
+
|
|
139
|
+
dirs.forEach((dir) => {
|
|
140
|
+
const full = path.join(root, dir);
|
|
141
|
+
if (!fs.existsSync(full)) {
|
|
142
|
+
fs.mkdirSync(full, { recursive: true });
|
|
143
|
+
|
|
144
|
+
if (!skipGitkeep.includes(dir)) {
|
|
145
|
+
const gitkeepPath = path.join(full, '.gitkeep');
|
|
146
|
+
fs.writeFileSync(gitkeepPath, '');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log('✓ Created folder structure with .gitkeep files');
|
|
152
|
+
|
|
153
|
+
// ------------------------------------------
|
|
154
|
+
// 9) de_DE.po Template kopieren
|
|
155
|
+
// ------------------------------------------
|
|
156
|
+
copy('de_DE.po', 'assets/src/l10n/de_DE.po');
|
|
157
|
+
|
|
158
|
+
// ------------------------------------------
|
|
159
|
+
// 10) PHP Template Files kopieren
|
|
160
|
+
// ------------------------------------------
|
|
161
|
+
copy('Plugin.php', 'includes/lib/Core/Plugin.php');
|
|
162
|
+
copy('Config.php', 'includes/lib/Core/Config.php');
|
|
163
|
+
|
|
164
|
+
// ------------------------------------------
|
|
165
|
+
console.log('\n🎉 Project initialized successfully!\n');
|
|
166
|
+
process.exit(0);
|
|
167
|
+
}
|
package/bin/is-wp-plugin-kit.js
CHANGED
|
@@ -1,134 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { runInit } from './commands/init.js';
|
|
4
|
+
import { runDev } from './commands/dev.js';
|
|
5
|
+
import { runBuild } from './commands/build.js';
|
|
6
|
+
import { runCompileMo } from './commands/compile-mo.js';
|
|
7
7
|
|
|
8
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
8
|
const cmd = process.argv[2];
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
fs.copyFileSync(src, dest);
|
|
28
|
-
console.log(`✓ Copied ${file}`);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error(`Error copying ${file}:`, error.message);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// ---------------------------
|
|
36
|
-
// INIT
|
|
37
|
-
// ---------------------------
|
|
38
|
-
if (cmd === "init") {
|
|
39
|
-
copy("gitignore");
|
|
40
|
-
copy("oxlintrc.json");
|
|
41
|
-
copy("stylelintrc.json");
|
|
42
|
-
copy("postcss.config.cjs");
|
|
43
|
-
copy("tsconfig.json");
|
|
44
|
-
|
|
45
|
-
console.log("✓ Project initialized with WP Plugin Kit defaults.");
|
|
46
|
-
process.exit(0);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ---------------------------
|
|
50
|
-
// compile-mo
|
|
51
|
-
// ---------------------------
|
|
52
|
-
if (cmd === "compile-mo") {
|
|
53
|
-
const moScript = path.resolve(__dirname, "../files/compile-mo.mjs");
|
|
54
|
-
import(moScript);
|
|
55
|
-
process.exit(0);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ---------------------------
|
|
59
|
-
// DEV (vite + watchers + mo)
|
|
60
|
-
// ---------------------------
|
|
61
|
-
if (cmd === "dev") {
|
|
62
|
-
execSync(
|
|
63
|
-
"concurrently -k " +
|
|
64
|
-
'"vite" ' +
|
|
65
|
-
"\"chokidar 'assets/src/ts/**/*.ts' -c 'oxlint assets/src/ts'\" " +
|
|
66
|
-
"\"chokidar 'assets/src/scss/**/*.scss' -c 'stylelint \\\"assets/src/scss/**/*.scss\\\" --fix'\" " +
|
|
67
|
-
"\"chokidar 'assets/src/l10n/**/*.po' -c 'is-wp-plugin-kit compile-mo'\"",
|
|
68
|
-
{ stdio: "inherit" }
|
|
69
|
-
);
|
|
70
|
-
process.exit(0);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ---------------------------
|
|
74
|
-
// Sub-tasks used by dev
|
|
75
|
-
// ---------------------------
|
|
76
|
-
|
|
77
|
-
if (cmd === "dev:vite") {
|
|
78
|
-
execSync("vite", { stdio: "inherit" });
|
|
79
|
-
process.exit(0);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (cmd === "watch:lint") {
|
|
83
|
-
execSync("chokidar 'assets/src/ts/**/*.ts' -c 'oxlint assets/src/ts'", {
|
|
84
|
-
stdio: "inherit",
|
|
85
|
-
});
|
|
86
|
-
process.exit(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (cmd === "watch:stylelint") {
|
|
90
|
-
execSync(
|
|
91
|
-
"chokidar 'assets/src/scss/**/*.scss' -c 'stylelint \"assets/src/scss/**/*.scss\" --fix'",
|
|
92
|
-
{ stdio: "inherit" }
|
|
93
|
-
);
|
|
94
|
-
process.exit(0);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (cmd === "watch:mo") {
|
|
98
|
-
execSync(
|
|
99
|
-
"chokidar 'assets/src/l10n/**/*.po' -c 'is-wp-plugin-kit compile-mo'",
|
|
100
|
-
{ stdio: "inherit" }
|
|
101
|
-
);
|
|
102
|
-
process.exit(0);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ---------------------------
|
|
106
|
-
// BUILD
|
|
107
|
-
// ---------------------------
|
|
108
|
-
if (cmd === "build") {
|
|
109
|
-
execSync("oxlint assets/src/ts", { stdio: "inherit" });
|
|
110
|
-
execSync('stylelint "assets/src/scss/**/*.scss" --fix', { stdio: "inherit" });
|
|
111
|
-
execSync("vite build", { stdio: "inherit" });
|
|
112
|
-
execSync("is-wp-plugin-kit compile-mo", { stdio: "inherit" });
|
|
113
|
-
|
|
114
|
-
console.log("✓ Build completed");
|
|
115
|
-
process.exit(0);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ---------------------------
|
|
119
|
-
// HELP
|
|
120
|
-
// ---------------------------
|
|
121
|
-
console.log(`
|
|
10
|
+
switch (cmd) {
|
|
11
|
+
case 'init':
|
|
12
|
+
runInit();
|
|
13
|
+
break;
|
|
14
|
+
case 'dev':
|
|
15
|
+
runDev();
|
|
16
|
+
break;
|
|
17
|
+
case 'build':
|
|
18
|
+
runBuild();
|
|
19
|
+
break;
|
|
20
|
+
case 'compile-mo':
|
|
21
|
+
runCompileMo();
|
|
22
|
+
break;
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
console.log(`
|
|
122
26
|
is-wp-plugin-kit – available commands:
|
|
123
27
|
|
|
124
|
-
init →
|
|
28
|
+
init → Setup a new plugin project
|
|
29
|
+
dev → Run vite + watchers
|
|
30
|
+
build → Production build
|
|
125
31
|
compile-mo → Convert .po → .mo
|
|
126
|
-
dev → Run vite + lint/watch + mo watcher
|
|
127
|
-
build → Run full production build
|
|
128
|
-
dev:vite → Run Vite only
|
|
129
|
-
watch:lint → Watch + lint TS
|
|
130
|
-
watch:stylelint → Watch + format SCSS
|
|
131
|
-
watch:mo → Watch + compile .po files
|
|
132
32
|
`);
|
|
133
|
-
|
|
134
|
-
process.exit(0);
|
|
33
|
+
}
|
package/bin/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Safely copy a file from the files directory to the current working directory
|
|
9
|
+
* @param {string} file - The filename to copy
|
|
10
|
+
*/
|
|
11
|
+
export function copy(file) {
|
|
12
|
+
try {
|
|
13
|
+
const src = path.resolve(__dirname, '../files', file);
|
|
14
|
+
const dest = path.resolve(
|
|
15
|
+
process.cwd(),
|
|
16
|
+
file.replace(/^gitignore$/, '.gitignore')
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(src)) {
|
|
20
|
+
console.error(`Error: Source file ${file} not found.`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fs.copyFileSync(src, dest);
|
|
25
|
+
console.log(`✓ Copied ${file}`);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(`Error copying ${file}:`, error.message);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/files/Config.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
//TODO change namespace
|
|
3
|
+
namespace IS\Template\Core;
|
|
4
|
+
|
|
5
|
+
use IS\Base\Core\Abstract_Config;
|
|
6
|
+
|
|
7
|
+
final class Config extends Abstract_Config {
|
|
8
|
+
protected function __construct() {
|
|
9
|
+
//TODO change pluginName and port if general plugin
|
|
10
|
+
$this->pluginName = "is-template-plugin";
|
|
11
|
+
$this->customPrefix = "iS_";
|
|
12
|
+
$this->vitePort = 5500;
|
|
13
|
+
|
|
14
|
+
parent::__construct();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
package/files/Plugin.php
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
//TODO change namespace
|
|
3
|
+
namespace IS\Template\Core;
|
|
4
|
+
|
|
5
|
+
use IS\Base\Core\Updater;
|
|
6
|
+
use IS\Base\Core\Auto_Instantiate;
|
|
7
|
+
|
|
8
|
+
class Plugin {
|
|
9
|
+
private static Config $config;
|
|
10
|
+
|
|
11
|
+
public static function boot(string $file): void {
|
|
12
|
+
|
|
13
|
+
self::$config = Config::get_instance();
|
|
14
|
+
|
|
15
|
+
if (file_exists(self::$config->path . 'languages/')) {
|
|
16
|
+
load_plugin_textdomain(
|
|
17
|
+
self::$config->pluginName,
|
|
18
|
+
false,
|
|
19
|
+
dirname(plugin_basename($file)) . '/languages/'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//TODO change github repo link and plugin slug
|
|
24
|
+
$updater = new Updater(
|
|
25
|
+
'https://github.com/iService-dev/is-template-plugin',
|
|
26
|
+
$file,
|
|
27
|
+
'is-template-plugin'
|
|
28
|
+
);
|
|
29
|
+
$updater->init();
|
|
30
|
+
|
|
31
|
+
//TODO only needed if classes in Admin or Frontend folder
|
|
32
|
+
Auto_Instantiate::instantiate_classes_static(self::$config, 'Admin');
|
|
33
|
+
Auto_Instantiate::instantiate_classes_static(self::$config, 'Frontend');
|
|
34
|
+
}
|
|
35
|
+
}
|
package/files/de_DE.po
ADDED
package/package.json
CHANGED