@iservice-dev/is-wp-plugin-kit 1.0.0

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.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const cmd = process.argv[2];
8
+
9
+ const copy = (file) => {
10
+ const src = path.resolve(__dirname, "../files", file);
11
+ const dest = path.resolve(
12
+ process.cwd(),
13
+ file.replace(/^gitignore$/, ".gitignore")
14
+ );
15
+ fs.copyFileSync(src, dest);
16
+ };
17
+
18
+ if (cmd === "init") {
19
+ copy("gitignore");
20
+ copy("oxlintrc.json");
21
+ copy("stylelintrc.json");
22
+ copy("postcss.config.cjs");
23
+ copy("tsconfig.json");
24
+
25
+ console.log("Project initialized with WP Plugin Kit defaults.");
26
+ }
27
+
28
+ if (cmd === "compile-mo") {
29
+ const moScript = path.resolve(__dirname, "../files/compile-mo.mjs");
30
+ import(moScript);
31
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "ignore": [
3
+ "assets/src/legacy/**/*"
4
+ ],
5
+ "rules": {
6
+ "no-alert": "error",
7
+ "oxc/approx-constant": "error",
8
+ "no-unused-vars": "warn",
9
+ "no-duplicate-imports": "error",
10
+ "no-unreachable": "error",
11
+ "no-empty": "error",
12
+ "no-for-loop": "warn",
13
+ "no-var": "warn",
14
+ "prefer-const": "warn",
15
+ "eqeqeq": "warn",
16
+ "semi": "warn",
17
+ "no-console": "warn"
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": [
3
+ "stylelint-config-standard-scss"
4
+ ],
5
+ "plugins": [
6
+ "stylelint-scss",
7
+ "stylelint-order"
8
+ ],
9
+ "rules": {
10
+ "color-hex-length": "short",
11
+ "order/properties-alphabetical-order": true,
12
+ "selector-class-pattern": null,
13
+ "selector-id-pattern": null,
14
+ "property-no-deprecated": [true, {"severity": "warning"}],
15
+ "keyframes-name-pattern": null,
16
+ "number-max-precision": null,
17
+ "no-descending-specificity": null,
18
+ "no-duplicate-selectors": null,
19
+ "font-family-no-missing-generic-family-keyword": null,
20
+ "keyframe-block-no-duplicate-selectors": null
21
+ }
22
+ }
@@ -0,0 +1,37 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import path from 'node:path'
3
+ import fs from 'node:fs/promises'
4
+ import { execFile } from 'node:child_process'
5
+ import { promisify } from 'node:util'
6
+ import fg from 'fast-glob'
7
+
8
+ const execFileP = promisify(execFile);
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const root = path.resolve(__dirname, '..');
11
+
12
+
13
+ const srcDir = path.join(root, 'assets', 'src', 'l10n');
14
+ const outDir = path.join(root, 'languages');
15
+
16
+ const pluginName = path.basename(root);
17
+
18
+ await fs.mkdir(outDir, { recursive: true });
19
+ const poFiles = await fg('**/*.po', { cwd: srcDir });
20
+
21
+ for (const rel of poFiles) {
22
+ const inPath = path.join(srcDir, rel)
23
+ const outSubdir = path.dirname(rel)
24
+ const locale = path.basename(rel, '.po');
25
+ const outBase = `${pluginName}-${locale}.mo`;
26
+ const outFullDir = path.join(outDir, outSubdir)
27
+ const outPath = path.join(outFullDir, outBase)
28
+ await fs.mkdir(outFullDir, { recursive: true })
29
+
30
+ const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx'
31
+ await execFileP(npxCmd, ['po2mo', inPath])
32
+
33
+ const generatedPath = path.join(srcDir, outSubdir, locale + '.mo')
34
+ await fs.rename(generatedPath, outPath)
35
+
36
+ console.log(`✔ ${rel} -> ${path.relative(root, outPath)} (with prefix ${pluginName}-)`)
37
+ }
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ plugins: {
3
+ autoprefixer: {},
4
+ },
5
+ };
@@ -0,0 +1,46 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "moduleResolution": "bundler",
7
+ "allowImportingTsExtensions": true,
8
+ "resolveJsonModule": true,
9
+ "isolatedModules": true,
10
+ "moduleDetection": "force",
11
+ "noEmit": true,
12
+ "jsx": "preserve",
13
+
14
+ "allowSyntheticDefaultImports": true,
15
+ "esModuleInterop": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "verbatimModuleSyntax": true,
18
+
19
+ "strict": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noUncheckedIndexedAccess": true,
24
+ "noImplicitReturns": true,
25
+ "exactOptionalPropertyTypes": true,
26
+
27
+ "baseUrl": ".",
28
+ "paths": {
29
+ "@/*": ["./assets/src/*"],
30
+ "@/modules/*": ["./assets/src/ts/modules/*"],
31
+ "@/types/*": ["./assets/src/ts/types/*"]
32
+ },
33
+
34
+ "types": ["jquery", "node"],
35
+ "skipLibCheck": true
36
+ },
37
+ "include": [
38
+ "assets/src/**/*.ts",
39
+ "assets/src/**/*.js",
40
+ "vite.config.ts"
41
+ ],
42
+ "exclude": [
43
+ "node_modules",
44
+ "assets/dist"
45
+ ]
46
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@iservice-dev/is-wp-plugin-kit",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "vite/index.js",
6
+ "files": [
7
+ "vite",
8
+ "files",
9
+ "bin"
10
+ ],
11
+ "bin": {
12
+ "is-wp-plugin-kit": "./bin/is-wp-plugin-kit.js"
13
+ },
14
+ "dependencies": {
15
+ "fast-glob": "^3.3.3",
16
+ "vite-plugin-static-copy": "^3.1.3"
17
+ },
18
+ "keywords": [],
19
+ "author": "iService",
20
+ "license": "ISC"
21
+ }
package/vite/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { defineConfig } from "vite";
2
+ import fg from "fast-glob";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { viteStaticCopy } from "vite-plugin-static-copy";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ export function wpPluginKitVite(userOptions = {}) {
10
+ function makeInputs() {
11
+ const files = fg.sync(
12
+ [
13
+ "assets/src/ts/*.ts",
14
+ "assets/src/scss/*.scss",
15
+ "assets/src/legacy/js/*.js",
16
+ "assets/src/legacy/css/*.css",
17
+ ],
18
+ {
19
+ cwd: userOptions.cwd ?? process.cwd(),
20
+ }
21
+ );
22
+
23
+ const entries = {};
24
+ for (const f of files) {
25
+ const base = path.basename(f).replace(/\.(ts|scss|js|css)$/i, "");
26
+
27
+ let key;
28
+ if (f.endsWith(".ts")) key = `js/${base}`;
29
+ else if (f.endsWith(".scss")) key = `css/${base}`;
30
+ else if (f.endsWith(".js")) key = `js/${base}`;
31
+ else if (f.endsWith(".css")) key = `css/${base}`;
32
+ else continue;
33
+
34
+ entries[key] = path.resolve(userOptions.cwd ?? process.cwd(), f);
35
+ }
36
+ return entries;
37
+ }
38
+
39
+ const staticCopyTargets = userOptions.staticCopyTargets ?? [
40
+ { src: "assets/src/images/*", dest: "css/images" },
41
+ { src: "assets/src/fonts/**/*.{eot,woff,woff2,ttf}", dest: "css/fonts" },
42
+ { src: "assets/src/legacy/css/*.css", dest: "css" },
43
+ { src: "assets/src/legacy/js/*.js", dest: "js" },
44
+ ];
45
+
46
+ return defineConfig({
47
+ base: "./",
48
+
49
+ server: {
50
+ host: "0.0.0.0",
51
+ port: userOptions.port ?? 5500,
52
+ origin: `http://localhost:${userOptions.port ?? 5500}`,
53
+ strictPort: true,
54
+ cors: true,
55
+ hmr: { host: "localhost", protocol: "ws" },
56
+ },
57
+
58
+ build: {
59
+ outDir: userOptions.outDir ?? "assets/dist",
60
+ assetsDir: "",
61
+ emptyOutDir: true,
62
+ manifest: "manifest.json",
63
+ target: "es2019",
64
+ cssCodeSplit: true,
65
+ rollupOptions: {
66
+ input: makeInputs(),
67
+ output: {
68
+ intro: "(function(){",
69
+ outro: "})();",
70
+ entryFileNames: (chunk) =>
71
+ chunk.name.startsWith("js/") ? "[name].js" : "js/[name].js",
72
+ chunkFileNames: "js/[name]-[hash].js",
73
+ assetFileNames: (asset) => {
74
+ const fileName = asset.names?.[0] ?? "";
75
+ const ext = path.extname(fileName).slice(1).toLowerCase();
76
+
77
+ if (fileName.endsWith(".css") || ext === "css") {
78
+ const baseName = fileName.replace(".css", "");
79
+ if (baseName.startsWith("css/")) return `${baseName}.css`;
80
+ return `css/${baseName}.css`;
81
+ }
82
+
83
+ if (["png", "jpg", "jpeg", "gif", "svg", "webp"].includes(ext))
84
+ return "css/images/[name][extname]";
85
+
86
+ if (["woff", "woff2", "ttf", "eot", "otf"].includes(ext))
87
+ return "css/fonts/[name][extname]";
88
+
89
+ return "[name][extname]";
90
+ },
91
+ },
92
+ },
93
+ },
94
+
95
+ css: { postcss: "./postcss.config.cjs" },
96
+
97
+ plugins: [viteStaticCopy({ targets: staticCopyTargets })],
98
+
99
+ ...userOptions,
100
+ });
101
+ }