Objective: Iterate through a list of package and only publish the package which does not exist in the npm registry. If the package with same version is already in the registry, discard any further action.
package="@react-framework/deploy@1.2.3.0" // package name extracted from the actual tgz file
checkRegistry=$(npm view $package) # There are three types of output
# NPM Err (Package Not Exists)
# NULL (Package Not Exists)
# return information about the package (Package Exists)
if [ [grep -q "npm ERR!"] || [$checkRegistry==""] ]; then
npm publish $package
I am keep having an error around the if-statement, and assuming there is a syntax error with my condition.
I would like to know if:
- Is it possible to assign an output from a npm command (in this case
npm view
) to a variable? - Is there anything wrong with the syntax from the if-statement?