evophp 1.0.17 → 1.0.19

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,76 @@
1
1
  #!/usr/bin/env node
2
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;
3
+ const { execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { readLineAsync } = require('./helpers');
9
7
 
10
8
  (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
- }
17
-
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);
26
- }
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
-
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);
9
+ try {
10
+ let [, , pluginName, ...args] = process.argv;
11
+
12
+ if (!pluginName) {
13
+ console.error("Please specify the plugin or theme name.");
14
+ process.exit(1);
52
15
  }
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);
16
+
17
+ // Check if flags for prod or dev are provided
18
+ const isProd = true;
19
+ const isDev = args.includes('--save-dev');
20
+
21
+ if (!isProd && !isDev) {
22
+ console.error("Please specify either '--prod' or '--dev' as flags.");
23
+ process.exit(1);
59
24
  }
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
- }
69
-
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);
25
+
26
+ const depType = isProd ? 'prod' : 'dev';
27
+
28
+ const pluginPath = path.join('EvoJsDev', 'Module', pluginName);
29
+
30
+ if (!fs.existsSync(pluginPath)) {
31
+ console.error(`Plugin "${pluginName}" not found in ${pluginPath}.`);
32
+ process.exit(1);
78
33
  }
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);
34
+
35
+ const dependenciesFile = path.join(pluginPath, 'dependencies.json');
36
+ let dependencies = {};
37
+
38
+ // If dependencies.json exists, read its content
39
+ if (fs.existsSync(dependenciesFile)) {
40
+ dependencies = JSON.parse(fs.readFileSync(dependenciesFile, 'utf-8'));
89
41
  }
90
- }
91
-
92
- console.log(`Initializing new project: ${name}...`);
93
-
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
- );
101
-
102
- // Navigate to the project directory
103
- const projectPath = path.join(process.cwd(), name);
104
- process.chdir(projectPath);
105
-
106
- // Run `node evolution`
107
- console.log(`Running node evolution for project: ${name}...`);
108
- execSync(`node evolution ${name}`, { stdio: "inherit" });
109
-
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
- );
42
+
43
+ console.log(`Current dependencies in dependencies.json for ${pluginName}:`);
44
+ console.log("Production dependencies:", dependencies.prod || "None");
45
+ console.log("Development dependencies:", dependencies.dev || "None");
46
+
47
+ // Prompt user for additional dependencies
48
+ const additionalDeps = await readLineAsync(`Enter additional ${depType} dependencies (comma separated): `);
49
+ const newDeps = additionalDeps.split(',').map(dep => dep.trim()).filter(dep => dep);
50
+
51
+ // Add new dependencies to the respective array
52
+ if (newDeps.length) {
53
+ dependencies[depType] = dependencies[depType]
54
+ ? dependencies[depType] + ' ' + newDeps.join(' ')
55
+ : newDeps.join(' ');
118
56
  }
119
57
 
120
- // Install NPM dependencies
121
- console.log("Installing NPM dependencies...");
122
- execSync("npm install", { stdio: "inherit" });
58
+ // Write updated dependencies to dependencies.json
59
+ fs.writeFileSync(dependenciesFile, JSON.stringify(dependencies, null, 2), 'utf-8');
60
+ console.log("Updated dependencies.json successfully.");
61
+
62
+ // Install the new dependencies
63
+ if (newDeps.length) {
64
+ const installCommand = depType === 'prod'
65
+ ? `npm install ${newDeps.join(' ')} --save` // For prod dependencies
66
+ : `npm install ${newDeps.join(' ')} --save-dev`; // For dev dependencies
67
+ console.log(`Installing ${depType} dependencies...`);
68
+ execSync(installCommand, { stdio: 'inherit' });
69
+ }
123
70
 
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}`);
71
+ console.log("Dependencies installed successfully.");
72
+ } catch (error) {
73
+ console.error("An error occurred:", error.message);
130
74
  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
75
  }
143
- } catch (error) {
144
- console.error("An unexpected error occurred:", error.message);
145
- process.exit(1);
146
- }
147
76
  })();
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.");
@@ -44,36 +50,38 @@ let [, , command, type, name] = process.argv;
44
50
  console.log(`Creating a new ${type}: ${name}...`);
45
51
  try {
46
52
  const pluginPath = path.resolve(__dirname, "new-plugin.js");
47
- console.log(`node "${pluginPath}" ${type} ${name}`)
48
53
  execSync(`node "${pluginPath}" ${type} ${name}`, { stdio: "inherit" });
49
54
  } catch (error) {
50
55
  console.error(`Error creating new ${type}: ${error.message}`);
51
56
  process.exit(1);
52
57
  }
53
58
  } else if (command === "install-dependencies" || command === "d") {
54
- if (!name || !type) {
55
- 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.");
56
65
  process.exit(1);
57
66
  }
58
67
 
59
- console.log(`Running install-dependencies for ${type}: ${name}...`);
68
+ console.log(`Running install-dependencies for ${name}...`);
60
69
 
61
- if (type === "plugin") {
62
- try {
63
- const pluginPath = path.resolve(__dirname, "install-dependencies.js");
64
- execSync(`node "${pluginPath}" ${name} ${args.join(' ')}`, { stdio: "inherit" });
65
- } catch (error) {
66
- console.error(`Error installing dependencies: ${error.message}`);
67
- process.exit(1);
68
- }
69
- } else {
70
- 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}`);
71
75
  process.exit(1);
72
76
  }
77
+
73
78
  } else if (command === "init") {
79
+ // sample command
80
+ // evophp init ?<projectName>
81
+
74
82
  name = type;
75
83
  if (!name) {
76
- name = await readLineAsync("Enter the name of the plugin/project:");
84
+ name = await readLineAsync("Enter the name of the project:");
77
85
  if (!name.trim()) {
78
86
  console.error("Invalid name. Please provide a valid project name.");
79
87
  process.exit(1);
package/new-plugin.js CHANGED
@@ -1,17 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- console.log("new-plugin.js is being executed...");
4
-
5
3
  const { execSync } = require('child_process');
6
4
  const path = require('path');
7
5
  const fs = require('fs');
8
6
  const axios = require('axios');
9
7
  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
8
  const { readLineAsync, splitPluginName } = require(helpersPath);
16
9
 
17
10
  (async () => {
@@ -66,7 +59,7 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
66
59
  await createGitHubRepo(gitHubToken, templateRepo, `${itemName}.js`);
67
60
 
68
61
  // Clone the newly created repositories
69
- cloneDir = path.join('EvoPhpJs', 'Modules', itemName);
62
+ cloneDir = path.join('EvoJsDev', 'Modules', itemName);
70
63
  await cloneRepository(author, itemName, cloneDir);
71
64
 
72
65
  } else if (type === 'theme') {
@@ -125,7 +118,7 @@ async function cloneRepository(author, itemName, cloneDir) {
125
118
  try {
126
119
  // Ensure directories do not exist before cloning
127
120
  if (fs.existsSync(cloneDir)) {
128
- console.log(`The ${type} "${itemName}" already exists in the directory. Exiting.`);
121
+ console.log(`The plugin "${itemName}" already exists in the directory. Exiting.`);
129
122
  process.exit(0);
130
123
  }
131
124
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evophp",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "Installer for the Evolution PHP project",
5
5
  "main": "installer.js",
6
6
  "scripts": {