evophp 1.0.16 → 1.0.18

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/helpers.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const readline = require('readline');
2
4
  const rl = readline.createInterface({
3
5
  input: process.stdin,
@@ -1,147 +1,74 @@
1
- #!/usr/bin/env node
2
-
3
- const { execSync } = require("child_process");
4
- const path = require("path");
5
- const fs = require("fs");
6
- const { readLineAsync } = require(path.resolve(__dirname, 'helpers.js'));
7
-
8
- let [, , command, type, name, ...args] = process.argv;
1
+ const { execSync } = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { readLineAsync } = require('./helpers');
9
5
 
10
6
  (async () => {
11
- try {
12
- if (command === "i" || command === "install") {
13
- if (!name) {
14
- console.error("Please specify the plugin or theme name.");
15
- process.exit(1);
16
- }
7
+ try {
8
+ let [, , pluginName, ...args] = process.argv;
17
9
 
18
- console.log(`Installing ${type}: ${name}...`);
19
-
20
- if (type === "plugin") {
21
- try {
22
- execSync(`node install-plugin.js ${name}`, { stdio: "inherit" });
23
- } catch (error) {
24
- console.error(`Error installing plugin: ${error.message}`);
25
- process.exit(1);
10
+ if (!pluginName) {
11
+ console.error("Please specify the plugin or theme name.");
12
+ process.exit(1);
26
13
  }
27
- } else if (type === "theme") {
28
- try {
29
- execSync(`node install-theme.js ${name}`, { stdio: "inherit" });
30
- } catch (error) {
31
- console.error(`Error installing theme: ${error.message}`);
32
- process.exit(1);
33
- }
34
- } else {
35
- console.error("Invalid type. Please specify either 'plugin' or 'theme'.");
36
- process.exit(1);
37
- }
38
- } else if (command === "n" || command === "new") {
39
- if (!type || !name) {
40
- console.error("Please specify both the type (plugin/theme) and name.");
41
- process.exit(1);
42
- }
43
14
 
44
- console.log(`Creating a new ${type}: ${name}...`);
45
-
46
- if (type === "plugin") {
47
- try {
48
- execSync(`node new-plugin.js ${name}`, { stdio: "inherit" });
49
- } catch (error) {
50
- console.error(`Error creating new plugin: ${error.message}`);
51
- process.exit(1);
52
- }
53
- } else if (type === "theme") {
54
- try {
55
- execSync(`node new-theme.js ${name}`, { stdio: "inherit" });
56
- } catch (error) {
57
- console.error(`Error creating new theme: ${error.message}`);
58
- process.exit(1);
59
- }
60
- } else {
61
- console.error("Invalid type. Please specify either 'plugin' or 'theme'.");
62
- process.exit(1);
63
- }
64
- } else if (command === "install-dependencies" || command === "d") {
65
- if (!name || !type) {
66
- console.error("Please specify both the type (plugin) and name.");
67
- process.exit(1);
68
- }
15
+ // Check if flags for prod or dev are provided
16
+ const isProd = true;
17
+ const isDev = args.includes('--save-dev');
69
18
 
70
- console.log(`Running install-dependencies for ${type}: ${name}...`);
71
-
72
- if (type === "plugin") {
73
- try {
74
- execSync(`node install-dependencies.js ${name} ${args.join(' ')}`, { stdio: "inherit" });
75
- } catch (error) {
76
- console.error(`Error installing dependencies: ${error.message}`);
77
- process.exit(1);
19
+ if (!isProd && !isDev) {
20
+ console.error("Please specify either '--prod' or '--dev' as flags.");
21
+ process.exit(1);
78
22
  }
79
- } else {
80
- console.error("Install-dependencies only supports plugins currently.");
81
- process.exit(1);
82
- }
83
- } else if (command === "init") {
84
- if (!name) {
85
- name = await readLineAsync("Enter the name of the plugin/project:");
86
- if (!name.trim()) {
87
- console.error("Invalid name. Please provide a valid project name.");
88
- process.exit(1);
23
+
24
+ const depType = isProd ? 'prod' : 'dev';
25
+
26
+ const pluginPath = path.join('EvoJsDev', 'Module', pluginName);
27
+
28
+ if (!fs.existsSync(pluginPath)) {
29
+ console.error(`Plugin "${pluginName}" not found in ${pluginPath}.`);
30
+ process.exit(1);
89
31
  }
90
- }
91
32
 
92
- console.log(`Initializing new project: ${name}...`);
33
+ const dependenciesFile = path.join(pluginPath, 'dependencies.json');
34
+ let dependencies = {};
93
35
 
94
- try {
95
- // Clone the repository
96
- console.log("Cloning the Evolution repository...");
97
- execSync(
98
- `git clone https://github.com/kinsokafor/evolution.git ${name}`,
99
- { stdio: "inherit" }
100
- );
36
+ // If dependencies.json exists, read its content
37
+ if (fs.existsSync(dependenciesFile)) {
38
+ dependencies = JSON.parse(fs.readFileSync(dependenciesFile, 'utf-8'));
39
+ }
101
40
 
102
- // Navigate to the project directory
103
- const projectPath = path.join(process.cwd(), name);
104
- process.chdir(projectPath);
41
+ console.log(`Current dependencies in dependencies.json for ${pluginName}:`);
42
+ console.log("Production dependencies:", dependencies.prod || "None");
43
+ console.log("Development dependencies:", dependencies.dev || "None");
105
44
 
106
- // Run `node evolution`
107
- console.log(`Running node evolution for project: ${name}...`);
108
- execSync(`node evolution ${name}`, { stdio: "inherit" });
45
+ // Prompt user for additional dependencies
46
+ const additionalDeps = await readLineAsync(`Enter additional ${depType} dependencies (comma separated): `);
47
+ const newDeps = additionalDeps.split(',').map(dep => dep.trim()).filter(dep => dep);
109
48
 
110
- // Install Composer dependencies if applicable
111
- if (fs.existsSync("composer.json")) {
112
- console.log("Installing Composer dependencies...");
113
- execSync("composer install", { stdio: "inherit" });
114
- } else {
115
- console.log(
116
- "Composer file not found, skipping Composer installation."
117
- );
49
+ // Add new dependencies to the respective array
50
+ if (newDeps.length) {
51
+ dependencies[depType] = dependencies[depType]
52
+ ? dependencies[depType] + ' ' + newDeps.join(' ')
53
+ : newDeps.join(' ');
118
54
  }
119
55
 
120
- // Install NPM dependencies
121
- console.log("Installing NPM dependencies...");
122
- execSync("npm install", { stdio: "inherit" });
56
+ // Write updated dependencies to dependencies.json
57
+ fs.writeFileSync(dependenciesFile, JSON.stringify(dependencies, null, 2), 'utf-8');
58
+ console.log("Updated dependencies.json successfully.");
59
+
60
+ // Install the new dependencies
61
+ if (newDeps.length) {
62
+ const installCommand = depType === 'prod'
63
+ ? `npm install ${newDeps.join(' ')} --save` // For prod dependencies
64
+ : `npm install ${newDeps.join(' ')} --save-dev`; // For dev dependencies
65
+ console.log(`Installing ${depType} dependencies...`);
66
+ execSync(installCommand, { stdio: 'inherit' });
67
+ }
123
68
 
124
- console.log(
125
- "Project initialization complete! Navigate to your project folder:"
126
- );
127
- console.log(`cd ${name}`);
128
- } catch (error) {
129
- console.error(`Error initializing project: ${error.message}`);
69
+ console.log("Dependencies installed successfully.");
70
+ } catch (error) {
71
+ console.error("An error occurred:", error.message);
130
72
  process.exit(1);
131
- }
132
- } else {
133
- console.error(`Unknown command: "${command}".`);
134
- console.log(`
135
- Usage:
136
- i | install <plugin/theme> <name> Install a plugin or theme
137
- n | new <plugin/theme> <name> Create a new plugin or theme
138
- d | install-dependencies <plugin> <name> Install dependencies for a plugin
139
- init <name> Initialize a new project
140
- `);
141
- process.exit(1);
142
73
  }
143
- } catch (error) {
144
- console.error("An unexpected error occurred:", error.message);
145
- process.exit(1);
146
- }
147
74
  })();
package/install-plugin.js CHANGED
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const { execSync } = require('child_process');
2
4
  const path = require('path');
3
- const { readLineAsync, splitPluginName } = require(path.resolve(__dirname, 'helpers.js'));
5
+ const helpersPath = path.resolve(__dirname, 'helpers.js');
6
+ const { readLineAsync, splitPluginName } = require(helpersPath);
4
7
  const fs = require('fs');
5
8
 
6
9
  (async () => {
@@ -34,7 +37,7 @@ const fs = require('fs');
34
37
  if (type === 'plugin') {
35
38
  paths = [
36
39
  path.join('Public', 'Module', itemName), // Main plugin path
37
- path.join('EvoPhpJs', 'Module', itemName), // .js plugin path
40
+ path.join('EvoJsDev', 'Module', itemName), // .js plugin path
38
41
  ];
39
42
  } else if (type === 'theme') {
40
43
  paths = [path.join('Public', 'Themes', itemName)];
@@ -87,6 +90,7 @@ const fs = require('fs');
87
90
  }
88
91
 
89
92
  console.log(`The ${type} "${itemName}" has been installed successfully.`);
93
+ process.exit(1);
90
94
  } catch (error) {
91
95
  console.error("An error occurred while installing:", error.message);
92
96
  process.exit(1);
package/installer.js CHANGED
@@ -10,6 +10,9 @@ let [, , command, type, name] = process.argv;
10
10
  (async () => {
11
11
  try {
12
12
  if (command === "i" || command === "install") {
13
+ // sample command
14
+ // evophp (i | install) (plugin | theme) <author/name>
15
+
13
16
  if (!name) {
14
17
  console.error("Please specify the plugin or theme name.");
15
18
  process.exit(1);
@@ -26,6 +29,9 @@ let [, , command, type, name] = process.argv;
26
29
  process.exit(1);
27
30
  }
28
31
  } else if (command === "n" || command === "new") {
32
+ // sample command
33
+ // evophp (n | new) (plugin | theme) <author/name>
34
+
29
35
  // Validate type and name
30
36
  if (!type || !name) {
31
37
  console.error("Please specify the type (plugin/theme) and the name.");
@@ -50,29 +56,32 @@ let [, , command, type, name] = process.argv;
50
56
  process.exit(1);
51
57
  }
52
58
  } else if (command === "install-dependencies" || command === "d") {
53
- if (!name || !type) {
54
- console.error("Please specify both the type (plugin) and name.");
59
+ // sample command
60
+ // evophp (d | install-dependencies) <plugin-name> ?(--save-dev | --save)
61
+ const args = name ? name : [];
62
+ name = type;
63
+ if (!name) {
64
+ console.error("Please specify the name of the plugin.");
55
65
  process.exit(1);
56
66
  }
57
67
 
58
- console.log(`Running install-dependencies for ${type}: ${name}...`);
68
+ console.log(`Running install-dependencies for ${name}...`);
59
69
 
60
- if (type === "plugin") {
61
- try {
62
- const pluginPath = path.resolve(__dirname, "install-dependencies.js");
63
- execSync(`node "${pluginPath}" ${name} ${args.join(' ')}`, { stdio: "inherit" });
64
- } catch (error) {
65
- console.error(`Error installing dependencies: ${error.message}`);
66
- process.exit(1);
67
- }
68
- } else {
69
- console.error("Install-dependencies only supports plugins currently.");
70
+ try {
71
+ const pluginPath = path.resolve(__dirname, "install-dependencies.js");
72
+ execSync(`node "${pluginPath}" ${name} ${args.join(' ')}`, { stdio: "inherit" });
73
+ } catch (error) {
74
+ console.error(`Error installing dependencies: ${error.message}`);
70
75
  process.exit(1);
71
76
  }
77
+
72
78
  } else if (command === "init") {
79
+ // sample command
80
+ // evophp init ?<projectName>
81
+
73
82
  name = type;
74
83
  if (!name) {
75
- name = await readLineAsync("Enter the name of the plugin/project:");
84
+ name = await readLineAsync("Enter the name of the project:");
76
85
  if (!name.trim()) {
77
86
  console.error("Invalid name. Please provide a valid project name.");
78
87
  process.exit(1);
package/new-plugin.js CHANGED
@@ -7,11 +7,6 @@ const path = require('path');
7
7
  const fs = require('fs');
8
8
  const axios = require('axios');
9
9
  const helpersPath = path.resolve(__dirname, 'helpers.js');
10
- console.log("Resolved helpers.js path:", helpersPath);
11
- if (!fs.existsSync(helpersPath)) {
12
- console.error("helpers.js not found at path:", helpersPath);
13
- process.exit(1);
14
- }
15
10
  const { readLineAsync, splitPluginName } = require(helpersPath);
16
11
 
17
12
  (async () => {
@@ -66,7 +61,7 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
66
61
  await createGitHubRepo(gitHubToken, templateRepo, `${itemName}.js`);
67
62
 
68
63
  // Clone the newly created repositories
69
- cloneDir = path.join('EvoPhpJs', 'Modules', itemName);
64
+ cloneDir = path.join('EvoJsDev', 'Modules', itemName);
70
65
  await cloneRepository(author, itemName, cloneDir);
71
66
 
72
67
  } else if (type === 'theme') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evophp",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Installer for the Evolution PHP project",
5
5
  "main": "installer.js",
6
6
  "scripts": {