Skip to content

Commit

Permalink
fix moved paths + generic nodeJS MVP ; next is python
Browse files Browse the repository at this point in the history
  • Loading branch information
froger-me committed Jan 9, 2024
1 parent a5f309e commit b5f80be
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 5 deletions.
149 changes: 148 additions & 1 deletion integration/dummy-generic/dummy-generic.js
Original file line number Diff line number Diff line change
@@ -1 +1,148 @@
const wppusApi = require('./wppus-api');
const wppusApi = require('./wppus-api');
const commands = {

// ### CHECKING THE PACKAGE STATUS ###

status: function () {

if (true === wppusApi.isInstalled()) {
console.log("Status: Installed");
} else if (false === wppusApi.isInstalled()) {
console.log("Status: Not installed");
} else {
console.log("Status: Unknown");
}
},

// ### INSTALLING THE PACKAGE ###

install: function (licenseKey) {
// If the command is "install", the script is not installed, and the license key is not empty
if (false === wppusApi.isInstalled() && '' !== licenseKey) {
// Install the script
wppusApi.install(licenseKey);

console.log("Installed");
} else {
console.log("Failed to install");
}
},


// ### UNINSTALLING THE PACKAGE ###

uninstall: function () {
// If the command is "uninstall" and the script is installed
if (true === wppusApi.isInstalled()) {
// Uninstall the script
wppusApi.uninstall();

console.log("Uninstalled");
} else {
console.log("Failed to uninstall");
}
},

// ### ACTIVATING THE LICENSE ###

activate: function () {
// If the command is "activate", the script is installed, and the license key is not empty
if (true === wppusApi.isInstalled()) {
// Activate the license
wppusApi.activate();

console.log("Activated");
} else {
console.log("The package is not installed");
}
},

// ### DEACTIVATING THE LICENSE ###

deactivate: function () {
// If the command is "deactivate" and the script is installed
if (true === wppusApi.isInstalled()) {
// Deactivate the license
wppusApi.deactivate();

console.log("Deactivated");
} else {
console.log("The package is not installed");
}
},

// ### GETTING UPDATE INFORMATION ###

get_update_info: function () {
// If the command is "get_update_info" and the script is installed
if (true === wppusApi.isInstalled()) {
// Get the update information
const info = wppusApi.getUpdateInfo();
// Get the current version
const version = wppusApi.getVersion();
// Get the remote version
const newVersion = info.version;

console.log(`current ${version} vs. remote ${newVersion}`);

if (newVersion > version) {
console.log("Update available !!! Run the \"update\" command!");
}

console.log("---------");
console.log(info);
} else {
console.log("The package is not installed");
}
},

// ### UPDATING THE PACKAGE ###

update: function () {
// If the command is "update" and the script is installed
if (true === wppusApi.isInstalled()) {
// Get the update information
wppusApi.update();

console.log("Updated");
console.log(wppusApi.getUpdateInfo());
} else {
console.log("The package is not installed");
}
},

// ### USAGE ###

usage: function () {
console.log("Usage: ./dummy-generic.js [command] [arguments]");
console.log("Commands:");
console.log(" install [license] - install the package");
console.log(" uninstall - uninstall the package");
console.log(" activate - activate the license");
console.log(" deactivate - deactivate the license");
console.log(" get_update_info - output information about the remote package update");
console.log(" update - update the package if available");
console.log(" status - output the package status");
console.log("Note: this package assumes it needs a license.");
}
};

// ### MAIN ###

(function () {
const command = process.argv[2] || '';
const license = process.argv[3] || '';

if (typeof commands[command] === 'function') {

if (command === 'install') {
commands[command](license);
} else {
commands[command]();
}
} else {
commands.usage();
}

process.exit();
})();
16 changes: 16 additions & 0 deletions integration/dummy-generic/wppus-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ async function main() {
let file = files[i];

if (file !== script_name) {
let destinationPath = path.join(__dirname, file);

if (fs.existsSync(destinationPath)) {

if (parseInt(process.version.slice(1).split('.')[0]) >= 14) {
fs.rmSync(destinationPath, { recursive: true, force: true });
} else {

if (fs.lstatSync(destinationPath).isDirectory()) {
fs.rmdirSync(destinationPath, { recursive: true });
} else {
fs.unlinkSync(destinationPath);
}
}
}

fs.renameSync('/tmp/' + package_name + '/' + file, path.join(__dirname, file));
}
}
Expand Down
4 changes: 3 additions & 1 deletion integration/dummy-generic/wppus-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ public static function update() {
# move the updated main script to the current directory ;
# the updated main script is in charge of overriding the update
# scripts by moving files around after update
$t_info = PATHINFO_FILENAME;

foreach ( glob( '/tmp/' . self::$package_name . '/*' ) as $file ) {

if ( ! is_dir( $file ) && pathinfo( $file, PATHINFO_FILENAME ) !== pathinfo( self::$package_script, PATHINFO_FILENAME ) ) {
if ( pathinfo( $file, $t_info ) !== pathinfo( self::$package_script, $t_info ) ) {
rename( $file, dirname( self::$package_script ) . '/' . basename( $file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.rename_rename
}
}
Expand Down
6 changes: 3 additions & 3 deletions integration/dummy-generic/wppus-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ if [ "$1" == "update" ]; then
# set the permissions of the new file to the permissions of the old file
chmod $OCTAL_MODE /tmp/$package_name/$package_name.sh

# move all the files except the wppus-api (all languages) to the
# move all the files and directories except the wppus-api (all languages) to the
# current directory ; the updated main script is in charge of
# overriding the update scripts by moving files around after update
for file in /tmp/$package_name *; do
if [[ ! -d "$file" ]] && [[ "${file%.*}" != "${script_name%.*}" ]]; then
for file in /tmp/$package_name/*; do
if [[ "${file%.*}" != "${script_name%.*}" ]]; then
mv /tmp/$package_name/$file $(dirname "$0")
fi
done
Expand Down

0 comments on commit b5f80be

Please sign in to comment.