evophp 1.0.31 → 1.1.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/README.md CHANGED
@@ -1,152 +1,175 @@
1
1
  # EvoPHP CLI - Comprehensive Guide
2
2
 
3
3
  ## Overview
4
+
4
5
  EvoPHP CLI is a command-line interface designed to simplify the development and management of projects, plugins, and themes within the EvoPHP ecosystem. With intuitive commands and shorthands, developers can quickly set up projects, manage dependencies, and handle plugin/theme creation and installation with ease.
5
6
 
6
7
  ---
7
8
 
8
9
  ## Table of Contents
9
- - [Installation](#installation)
10
- - [All Commands](#all-commands)
11
- - [Initialization](#initialization)
12
- - [Plugin/Theme Creation](#plugintheme-creation)
13
- - [Plugin/Theme Installation](#plugintheme-installation)
14
- - [Plugin/Theme Uninstallation](#plugintheme-uninstallation)
15
- - [Dependency Management](#dependency-management)
16
- - [Notes](#notes)
17
- - [Further Documentation](#further-documentation)
10
+
11
+ * [Installation](#installation)
12
+ * [All Commands](#all-commands)
13
+
14
+ * [Initialization](#initialization)
15
+ * [Plugin/Theme Creation](#plugintheme-creation)
16
+ * [Plugin/Theme Installation](#plugintheme-installation)
17
+ * [Plugin/Theme Uninstallation](#plugintheme-uninstallation)
18
+ * [Dependency Management](#dependency-management)
19
+ * [Authentication & PAT Storage](#authentication--pat-storage)
20
+ * [Further Documentation](#further-documentation)
18
21
 
19
22
  ---
20
23
 
21
24
  ## Installation
22
25
 
23
26
  ### Prerequisites
27
+
24
28
  Ensure the following are installed on your system:
25
- - **Node.js**: Verify by running `node -v` and `npm -v`.
26
- - **Composer**: For managing PHP dependencies.
29
+
30
+ * **Node.js**: Verify with `node -v` and `npm -v`
31
+ * **Composer**: Required for PHP dependencies
27
32
 
28
33
  ### Install EvoPHP
29
- To install EvoPHP globally, run:
34
+
30
35
  ```bash
31
36
  npm install -g evophp
32
37
  ```
33
38
 
34
- This command makes the `evophp` CLI available system-wide.
39
+ This makes the `evophp` CLI available globally.
35
40
 
36
41
  ---
37
42
 
38
43
  ## All Commands
39
44
 
40
45
  ### Initialization
46
+
41
47
  ```bash
42
- evophp init ?<project-name>
48
+ evophp init [project-name]
43
49
  ```
44
- - Initialize a new project.
45
- - Examples:
50
+
51
+ * Initializes a new EvoPHP project.
52
+ * Examples:
53
+
46
54
  ```bash
47
55
  evophp init
48
- evophp init example-project
56
+ evophp init my-project
49
57
  ```
50
58
 
51
59
  ---
52
60
 
53
61
  ### Plugin/Theme Creation
62
+
54
63
  ```bash
55
- evophp n | new plugin | theme <author>/<name>
64
+ evophp new plugin <name>
65
+ evophp new theme <name>
66
+ evophp n plugin <name>
67
+ evophp n theme <name>
56
68
  ```
57
- - Create a new plugin or theme.
58
- - Examples:
59
- - Plugin:
60
- ```bash
61
- evophp new plugin example-author/example-plugin
62
- evophp n plugin example-author/example-plugin
63
- ```
64
- - Theme:
65
- ```bash
66
- evophp new theme example-author/example-theme
67
- evophp n theme example-author/example-theme
68
- ```
69
+
70
+ * Creates a new plugin or theme from a template.
71
+
72
+ * Supports:
73
+
74
+ * Just `<name>` → Uses your GitHub account (token required)
75
+ * `<author>/<name>` → Creates in the specified GitHub account
76
+
77
+ * Examples:
78
+
79
+ ```bash
80
+ evophp new plugin MyPlugin # Uses your GitHub
81
+ evophp n plugin johndoe/BlogEnhancer # Uses johndoe's GitHub
82
+ ```
69
83
 
70
84
  ---
71
85
 
72
86
  ### Plugin/Theme Installation
87
+
73
88
  ```bash
74
- evophp i | install plugin | theme <author>/<name>
89
+ evophp install plugin <name>
90
+ evophp install theme <name>
91
+ evophp i plugin <name>
92
+ evophp i theme <name>
75
93
  ```
76
- - Install a plugin or theme.
77
- - Examples:
78
- - Plugin:
79
- ```bash
80
- evophp install plugin example-author/example-plugin
81
- evophp i plugin example-author/example-plugin
82
- ```
83
- - Theme:
84
- ```bash
85
- evophp install theme example-author/example-theme
86
- evophp i theme example-author/example-theme
87
- ```
94
+
95
+ * Installs a plugin or theme from GitHub into your project.
96
+
97
+ * Supports:
98
+
99
+ * Just `<name>` → Clones from your GitHub account (token required)
100
+ * `<author>/<name>` → Clones from public GitHub repo (no token required)
101
+
102
+ * Examples:
103
+
104
+ ```bash
105
+ evophp install plugin MyPlugin
106
+ evophp i theme johndoe/EvoTheme
107
+ ```
88
108
 
89
109
  ---
90
110
 
91
111
  ### Plugin/Theme Uninstallation
112
+
92
113
  ```bash
93
- evophp u | uninstall plugin | theme <plugin-name>
114
+ evophp uninstall plugin <name>
115
+ evophp uninstall theme <name>
116
+ evophp u plugin <name>
117
+ evophp u theme <name>
94
118
  ```
95
- - Uninstall a plugin or theme.
96
- - Examples:
97
- - Plugin:
98
- ```bash
99
- evophp uninstall plugin example-plugin
100
- evophp u plugin example-plugin
101
- ```
102
- - Theme:
103
- ```bash
104
- evophp uninstall theme example-theme
105
- evophp u theme example-theme
106
- ```
119
+
120
+ * Removes the installed plugin or theme from the project.
121
+
122
+ * Examples:
123
+
124
+ ```bash
125
+ evophp uninstall plugin MyPlugin
126
+ evophp u theme EvoTheme
127
+ ```
107
128
 
108
129
  ---
109
130
 
110
131
  ### Dependency Management
132
+
111
133
  ```bash
112
- evophp d | install-dependencies <plugin-name>
134
+ evophp install-dependencies <plugin-name>
135
+ evophp d <plugin-name>
113
136
  ```
114
- - Install npm production dependencies.
115
- - Examples:
116
- ```bash
117
- evophp install-dependencies example-plugin
118
- evophp d example-plugin
119
- ```
120
137
 
121
- #### Development Dependencies
138
+ * Adds or installs plugin dependencies.
139
+
140
+ #### Production (npm):
141
+
122
142
  ```bash
123
- evophp d | install-dependencies <plugin-name> --dev | --save-dev
143
+ evophp d MyPlugin
124
144
  ```
125
- - Install npm development dependencies.
126
- - Examples:
127
- ```bash
128
- evophp install-dependencies example-plugin --dev
129
- evophp d example-plugin --dev
130
- ```
131
145
 
132
- #### Composer Dependencies
146
+ #### Development (npm):
147
+
133
148
  ```bash
134
- evophp d | install-dependencies <plugin-name> --composer
149
+ evophp d MyPlugin --dev
150
+ ```
151
+
152
+ #### PHP (Composer):
153
+
154
+ ```bash
155
+ evophp d MyPlugin --composer
135
156
  ```
136
- - Install composer dependencies.
137
- - Examples:
138
- ```bash
139
- evophp install-dependencies example-plugin --composer
140
- evophp d example-plugin --composer
141
- ```
142
157
 
143
158
  ---
144
159
 
145
- ## Notes
146
- - `<author>` must be a valid GitHub username.
147
- - `<name>` must be a unique repository name (not already existing on GitHub).
160
+ ## Authentication & PAT Storage
161
+
162
+ When using a command with just `<name>` (e.g. `evophp new plugin MyPlugin`), EvoPHP CLI will:
163
+
164
+ * Prompt you for a **GitHub Personal Access Token** (PAT) the first time
165
+ * Automatically store it in `.env.development` for future use
166
+ * Use that token to fetch your GitHub username and manage private/public repos
167
+
168
+ > To change your token later, simply edit or delete `.env.development`.
148
169
 
149
170
  ---
150
171
 
151
172
  ## Further Documentation
152
- For additional details, best practices, and advanced usage, please refer to the [official EvoPHP documentation](#).
173
+
174
+ More advanced use cases, templates, and configuration details coming soon at:
175
+ 📘 [Official EvoPHP Documentation](#)
package/bin/evophp.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ const yargs = require("yargs");
4
+ const { hideBin } = require("yargs/helpers");
5
+
6
+ yargs(hideBin(process.argv))
7
+ .command(require("../commands/init"))
8
+ .command(require("../commands/new"))
9
+ .command(require("../commands/install"))
10
+ .command(require("../commands/uninstall"))
11
+ .command(require("../commands/dependencies"))
12
+ .command(require("../commands/help"))
13
+ .demandCommand(1, "Please specify a valid command. Use --help to see available commands.")
14
+ .help()
15
+ .argv;
16
+
@@ -0,0 +1,80 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { execSync } = require("child_process");
4
+ const { readLineAsync } = require("../utils/helpers");
5
+ const log = require("../utils/logger");
6
+
7
+ module.exports = {
8
+ command: "install-dependencies <plugin> [--dev|--composer]",
9
+ aliases: ["d"],
10
+ describe: "Add and install plugin or theme dependencies",
11
+
12
+ builder: yargs =>
13
+ yargs
14
+ .positional("plugin", { describe: "Plugin or theme name", type: "string" })
15
+ .option("dev", { describe: "Install as dev dependency (JS)", type: "boolean" })
16
+ .option("composer", { describe: "Use composer for PHP", type: "boolean" }),
17
+
18
+ handler: async ({ plugin, dev, composer }) => {
19
+ try {
20
+ const depType = dev ? "dev" : "prod";
21
+
22
+ const isPHP = !!composer;
23
+ const baseDir = isPHP
24
+ ? path.join("Public", "Modules", plugin)
25
+ : path.join("EvoJsDev", "Modules", plugin);
26
+
27
+ if (!fs.existsSync(baseDir)) {
28
+ log.error(`Plugin not found at ${baseDir}`);
29
+ process.exit(1);
30
+ }
31
+
32
+ const dependenciesFile = path.join(baseDir, "dependencies.json");
33
+ let dependencies = fs.existsSync(dependenciesFile)
34
+ ? JSON.parse(fs.readFileSync(dependenciesFile, "utf-8"))
35
+ : {};
36
+
37
+ log.info(`Existing ${isPHP ? "PHP" : "JS"} dependencies:`);
38
+ log.info("Production:", dependencies.prod || "None");
39
+ if (!isPHP) log.info("Development:", dependencies.dev || "None");
40
+
41
+ const additionalDeps = await readLineAsync(
42
+ `Enter additional ${depType} dependencies (space separated): `
43
+ );
44
+ const newDeps = additionalDeps
45
+ .split(" ")
46
+ .map(dep => dep.trim())
47
+ .filter(Boolean);
48
+
49
+ if (newDeps.length === 0) {
50
+ log.warn("No dependencies provided.");
51
+ return;
52
+ }
53
+
54
+ // Merge and deduplicate
55
+ const depField = isPHP || depType === "prod" ? "prod" : "dev";
56
+ dependencies[depField] = (
57
+ (dependencies[depField] || "") + " " + newDeps.join(" ")
58
+ )
59
+ .trim()
60
+ .split(" ")
61
+ .filter((value, i, arr) => arr.indexOf(value) === i)
62
+ .join(" ");
63
+
64
+ fs.writeFileSync(dependenciesFile, JSON.stringify(dependencies, null, 2));
65
+ log.success("Updated dependencies.json");
66
+
67
+ // Install
68
+ const installCmd = isPHP
69
+ ? `composer require ${newDeps.join(" ")}`
70
+ : `npm install ${newDeps.join(" ")} ${dev ? "--save-dev" : "--save"}`;
71
+
72
+ log.info("Installing dependencies...");
73
+ execSync(installCmd, { stdio: "inherit" });
74
+ log.success("Installation complete.");
75
+ } catch (err) {
76
+ log.error("Error installing dependencies: " + err.message);
77
+ process.exit(1);
78
+ }
79
+ }
80
+ };
@@ -0,0 +1,71 @@
1
+ module.exports = {
2
+ command: "help",
3
+ aliases: ["h"],
4
+ describe: "Show all available EvoPHP CLI commands",
5
+
6
+ handler: () => {
7
+ console.log(`
8
+ ==========================================
9
+ EvoPHP CLI - Help Guide
10
+ ==========================================
11
+
12
+ 📦 Initialization:
13
+ evophp init [project-name]
14
+ → Initialize a new Evolution PHP project.
15
+ → Aliases: none
16
+ → Example: evophp init my-coop-project
17
+
18
+ 🛠️ Plugin & Theme Creation:
19
+ evophp new plugin <name>
20
+ evophp new theme <name>
21
+ evophp n plugin <name>
22
+ evophp n theme <name>
23
+ → Create a plugin or theme from template repo.
24
+ → Supports:
25
+ • just <name> → uses your GitHub account
26
+ • author/name → uses any GitHub account
27
+
28
+ ⬇️ Plugin & Theme Installation:
29
+ evophp install plugin <name>
30
+ evophp install plugin author/name
31
+ evophp i theme <name>
32
+ evophp i theme author/name
33
+ → Install a plugin or theme from GitHub into your project.
34
+ → Format options:
35
+ • just <name> → installs from your GitHub account
36
+ • author/name → installs from public GitHub repo
37
+
38
+ 🗑️ Plugin & Theme Uninstallation:
39
+ evophp uninstall plugin <name>
40
+ evophp uninstall theme <name>
41
+ evophp u plugin <name>
42
+ evophp u theme <name>
43
+ → Remove an installed plugin or theme and update config.
44
+
45
+ 🔧 Dependency Management:
46
+ evophp install-dependencies <plugin>
47
+ evophp d <plugin> [--dev|--composer]
48
+ → Add and install dependencies for a plugin:
49
+ --dev → JavaScript development dependencies
50
+ --composer → PHP dependencies via Composer
51
+ → Aliases: install-dependencies → d
52
+
53
+ 🔐 GitHub Authentication:
54
+ When installing or creating with just <name>,
55
+ the CLI will prompt for your GitHub PAT and store it
56
+ in .env.development for future runs.
57
+
58
+ ❓ General:
59
+ evophp help
60
+ evophp h
61
+ → Show this help guide.
62
+ → Aliases: help → h
63
+
64
+ ==========================================
65
+ Tip: Use --help after any command
66
+ for more usage examples.
67
+ ==========================================
68
+ `);
69
+ process.exit(0);
70
+ }
71
+ };
@@ -0,0 +1,57 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { execSync } = require("child_process");
4
+ const { readLineAsync } = require("../utils/helpers");
5
+ const log = require("../utils/logger");
6
+
7
+ module.exports = {
8
+ command: "init [name]",
9
+ describe: "Initialize a new EvoPHP project",
10
+
11
+ builder: yargs =>
12
+ yargs
13
+ .positional("name", {
14
+ describe: "Project folder name (optional)",
15
+ type: "string",
16
+ default: "",
17
+ }),
18
+
19
+ handler: async ({ name }) => {
20
+ try {
21
+ if (!name) {
22
+ name = await readLineAsync("Enter the name of the project: ");
23
+ if (!name.trim()) {
24
+ log.error("You must enter a valid project name.");
25
+ process.exit(1);
26
+ }
27
+ }
28
+
29
+ const repoUrl = "https://github.com/kinsokafor/evolution.git";
30
+ const projectPath = path.join(process.cwd(), name);
31
+
32
+ log.info(`Cloning Evolution repo to "${name}"...`);
33
+ execSync(`git clone ${repoUrl} ${name}`, { stdio: "inherit" });
34
+
35
+ process.chdir(projectPath);
36
+
37
+ log.info(`Running bootstrap script: node evolution ${name}`);
38
+ execSync(`node evolution ${name}`, { stdio: "inherit" });
39
+
40
+ if (fs.existsSync("composer.json")) {
41
+ log.info("Installing Composer dependencies...");
42
+ execSync("composer install", { stdio: "inherit" });
43
+ } else {
44
+ log.info("No composer.json found. Skipping Composer installation.");
45
+ }
46
+
47
+ log.info("Installing NPM dependencies...");
48
+ execSync("npm install", { stdio: "inherit" });
49
+
50
+ log.success("Project setup complete!");
51
+ log.info(`Navigate into your project:\n cd ${name}`);
52
+ } catch (err) {
53
+ log.error("Project initialization failed: " + err.message);
54
+ process.exit(1);
55
+ }
56
+ }
57
+ };
@@ -0,0 +1,91 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const { execSync } = require('child_process');
4
+ const { readLineAsync, mergeConfig, saveToEnv } = require('../utils/helpers');
5
+ const { getUserData } = require('../utils/github');
6
+ const { cloneRepo } = require('../utils/git');
7
+ const { installDependencies } = require('../utils/dependencies');
8
+ const log = require('../utils/logger');
9
+ require("dotenv").config({ path: "./.env.development" });
10
+
11
+ module.exports = {
12
+ command: 'install [type] [name]',
13
+ aliases: ['i'],
14
+ describe: 'Install a plugin or theme',
15
+
16
+ builder: yargs => yargs
17
+ .positional('type', { describe: 'plugin or theme', type: 'string' })
18
+ .positional('name', { describe: 'name or author/name', type: 'string' }),
19
+
20
+ handler: async ({ type, name }) => {
21
+ try {
22
+ if (!type || !['plugin', 'theme'].includes(type.toLowerCase())) {
23
+ type = await readLineAsync("What are you installing? (plugin/theme): ");
24
+ type = type.toLowerCase();
25
+ if (!['plugin', 'theme'].includes(type)) {
26
+ log.error("Invalid type.");
27
+ process.exit(1);
28
+ }
29
+ }
30
+
31
+ if (!name) {
32
+ name = await readLineAsync(`Enter the ${type} name (e.g., myplugin or johndoe/myplugin): `);
33
+ }
34
+
35
+ let author, pluginName;
36
+ let gitHubToken = process.env.GITHUB_TOKEN;
37
+
38
+ if (name.includes("/")) {
39
+ // Full author/name provided — no auth required
40
+ [author, pluginName] = name.split("/");
41
+ } else {
42
+ // Token required to determine user
43
+ if (!gitHubToken) {
44
+ gitHubToken = await readLineAsync("Enter your GitHub Personal Access Token: ");
45
+ saveToEnv("GITHUB_TOKEN", gitHubToken);
46
+ log.success("GitHub token saved to .env.development");
47
+ }
48
+ const userData = await getUserData(gitHubToken);
49
+ author = userData.login;
50
+ pluginName = name;
51
+ log.info(`Authenticated as ${author}`);
52
+ }
53
+
54
+ const paths = type === 'plugin'
55
+ ? [path.join('Public', 'Modules', pluginName), path.join('EvoJsDev', 'Modules', pluginName)]
56
+ : [path.join('Public', 'Themes', pluginName)];
57
+
58
+ for (const p of paths) {
59
+ if (fs.existsSync(p)) {
60
+ log.warn(`${type} "${pluginName}" already exists at ${p}`);
61
+ process.exit(0);
62
+ }
63
+ }
64
+
65
+ log.info(`Installing ${type} "${pluginName}" from ${author}...`);
66
+
67
+ if (type === 'plugin') {
68
+ await cloneRepo(`${author}/${pluginName}`, null, paths[0]);
69
+ await cloneRepo(`${author}/${pluginName}.js`, null, paths[1]);
70
+
71
+ const configFile = path.resolve(`./EvoJsDev/Modules/${pluginName}/config.json`);
72
+ if (fs.existsSync(configFile)) {
73
+ const pluginConfig = require(configFile);
74
+ mergeConfig(pluginConfig);
75
+ }
76
+
77
+ await installDependencies(paths[1], 'js');
78
+ await installDependencies(paths[0], 'php');
79
+
80
+ } else if (type === 'theme') {
81
+ await cloneRepo(`${author}/${pluginName}`, null, paths[0]);
82
+ }
83
+
84
+ log.success(`The ${type} "${pluginName}" has been installed successfully.`);
85
+
86
+ } catch (err) {
87
+ log.error(`Install failed: ${err.message}`);
88
+ process.exit(1);
89
+ }
90
+ }
91
+ };