-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix generic node, trim all generic domain var
- Loading branch information
Showing
4 changed files
with
149 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,160 @@ | ||
#!/usr/bin/env node | ||
|
||
const wppusApi = require('./wppus-api'); | ||
const commands = { | ||
|
||
// ### CHECKING THE PACKAGE STATUS ### | ||
wppusApi.on('ready', function (api) { | ||
|
||
status: function () { | ||
const commands = { | ||
|
||
if (true === wppusApi.isInstalled()) { | ||
console.log("Status: Installed"); | ||
} else if (false === wppusApi.isInstalled()) { | ||
console.log("Status: Not installed"); | ||
} else { | ||
console.log("Status: Unknown"); | ||
} | ||
}, | ||
// ### CHECKING THE PACKAGE STATUS ### | ||
|
||
// ### INSTALLING THE PACKAGE ### | ||
status: async function () { | ||
|
||
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); | ||
if (true === api.is_installed()) { | ||
console.log("Status: Installed"); | ||
} else if (false === api.is_installed()) { | ||
console.log("Status: Not installed"); | ||
} else { | ||
console.log("Status: Unknown"); | ||
} | ||
}, | ||
|
||
console.log("Installed"); | ||
} else { | ||
console.log("Failed to install"); | ||
} | ||
}, | ||
// ### INSTALLING THE PACKAGE ### | ||
|
||
install: async function (licenseKey) { | ||
// If the command is "install", the script is not installed, and the license key is not empty | ||
if (false === api.is_installed() && '' !== licenseKey) { | ||
// Install the script | ||
api.install(licenseKey); | ||
|
||
// ### UNINSTALLING THE PACKAGE ### | ||
console.log("Installed"); | ||
} else { | ||
console.log("Failed to install"); | ||
} | ||
}, | ||
|
||
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"); | ||
} | ||
}, | ||
// ### UNINSTALLING THE PACKAGE ### | ||
|
||
// ### ACTIVATING THE LICENSE ### | ||
uninstall: async function () { | ||
// If the command is "uninstall" and the script is installed | ||
if (true === api.is_installed()) { | ||
// Uninstall the script | ||
api.uninstall(); | ||
|
||
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("Uninstalled"); | ||
} else { | ||
console.log("Failed to uninstall"); | ||
} | ||
}, | ||
|
||
console.log("Activated"); | ||
} else { | ||
console.log("The package is not installed"); | ||
} | ||
}, | ||
// ### ACTIVATING THE LICENSE ### | ||
|
||
// ### DEACTIVATING THE LICENSE ### | ||
activate: async function () { | ||
// If the command is "activate", the script is installed, and the license key is not empty | ||
if (true === api.is_installed()) { | ||
// Activate the license | ||
await api.activate_license(); | ||
|
||
deactivate: function () { | ||
// If the command is "deactivate" and the script is installed | ||
if (true === wppusApi.isInstalled()) { | ||
// Deactivate the license | ||
wppusApi.deactivate(); | ||
console.log("Activated"); | ||
} else { | ||
console.log("The package is not installed"); | ||
} | ||
}, | ||
|
||
console.log("Deactivated"); | ||
} else { | ||
console.log("The package is not installed"); | ||
} | ||
}, | ||
// ### DEACTIVATING THE LICENSE ### | ||
|
||
// ### GETTING UPDATE INFORMATION ### | ||
deactivate: async function () { | ||
// If the command is "deactivate" and the script is installed | ||
if (true === api.is_installed()) { | ||
// Deactivate the license | ||
api.deactivate_license(); | ||
|
||
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("Deactivated"); | ||
} else { | ||
console.log("The package is not installed"); | ||
} | ||
}, | ||
|
||
// ### GETTING UPDATE INFORMATION ### | ||
|
||
get_update_info: async function () { | ||
// If the command is "get_update_info" and the script is installed | ||
if (true === api.is_installed()) { | ||
// Get the update information | ||
const info = await api.get_update_info(); | ||
// Get the current version | ||
const version = api.get_version(); | ||
// Get the remote version | ||
const newVersion = info.version; | ||
|
||
console.log(""); | ||
console.log(`current ${version} vs. remote ${newVersion}`); | ||
console.log(""); | ||
|
||
if (newVersion > version) { | ||
console.log("---------"); | ||
console.log(""); | ||
console.log("Update available !!! Run the \"update\" command!"); | ||
console.log(""); | ||
} | ||
|
||
console.log("---------"); | ||
console.log(""); | ||
console.log(info); | ||
} else { | ||
console.log("The package is not installed"); | ||
} | ||
}, | ||
|
||
console.log(`current ${version} vs. remote ${newVersion}`); | ||
// ### UPDATING THE PACKAGE ### | ||
|
||
if (newVersion > version) { | ||
console.log("Update available !!! Run the \"update\" command!"); | ||
} | ||
update: async function () { | ||
// If the command is "update" and the script is installed | ||
if (true === api.is_installed()) { | ||
// Get the update information | ||
api.update(); | ||
|
||
console.log("---------"); | ||
console.log(info); | ||
} else { | ||
console.log("The package is not installed"); | ||
console.log("Updated"); | ||
console.log(api.get_update_info()); | ||
} 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."); | ||
} | ||
}, | ||
}; | ||
|
||
// ### UPDATING THE PACKAGE ### | ||
// ### MAIN ### | ||
|
||
update: function () { | ||
// If the command is "update" and the script is installed | ||
if (true === wppusApi.isInstalled()) { | ||
// Get the update information | ||
wppusApi.update(); | ||
(async function () { | ||
const command = process.argv[2] || ''; | ||
const license = process.argv[3] || ''; | ||
|
||
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); | ||
if (typeof commands[command] === 'function') { | ||
|
||
if (command === 'install') { | ||
await commands[command](license); | ||
} else { | ||
await commands[command](); | ||
} | ||
} else { | ||
commands[command](); | ||
commands.usage(); | ||
} | ||
} else { | ||
commands.usage(); | ||
} | ||
|
||
process.exit(); | ||
})(); | ||
process.exit(); | ||
})(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.