diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/.travis.yml b/.travis.yml index 489c623..d6b2a76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_deploy: deploy: provider: releases api_key: - secure: "CJMqOWtrUzSAjY3jif+jIU/dlocZ+2ylAgRcPq7JV6yPM3/XyZ8i09lkzM7IrGL/KQd9ZvDuyLHAJJTtzuvgOTc8QtJLrS88hj/5lE/6uahJ8F63SlLJJ3RFPsV0DPVMpP65Azl+poZBLsjrbjaj2AlAYJl1j2FVd8CxfMIrGaLbnQARhU+HgDukrXTpIf9GMOHeEat8/oORPXpahQwfoZDb8WXZIYnG/SLZDegzZMb+281ErzLcaSfZrBnKGSPbidZQvdBYwZQqRNTXN+PLHIdMqaVckilpHi3uh4McTLs9hu8TiwxxZWFvhH4BA8BG/pcKZ6hAJXseHiOef7WAII6Btb3gE7SSKTuH0DFsEa0LvUhW1se/MTOOMxhVaSSxskpNG1UUFnQXpdabKMP9N7ZbTT7SOpMZsEsGdHPh6P9lJ5OsVogo+YLABEqgAHWtuXWBj1/g0iWUglaCBPQZcdOJWd8C0bYHsEAk+O+SovtFKXPSKtEh6OJajv+8K63GRrpnQvlMQcXg6PKlFMJBr8atpcOpdV6Ld3yFHIO0kTaEn2uZc3j5yt2GVS4M3wEpQ/eeFns6asEXg2gkwQgQh68Dc1jSoKMy/4ffbCV4LHEJn0QnowZ+T4gb4wXLIsYVFCX020HZbqA3gnJoRkgdh1P5HHr7fyN+gQPWHOnDHto=" + secure: "y2pU0ZNr7Na8CX+p2Jou2wyg7Uzf/1/Ml38ue5PSSELEvWtjTwpbC4vJ/iP8PyEBCYr9NZ0Qti/M+a5mGFaocelRHu/A6f4GuujB3fKCadW1eRV9ncTqQpLtSJ7huOk7izMlz25rcvuEft5FSxnrckSECcW0qpzr6AQG67JB/9IEveR1XfXNCn0SDFydbBOTKxrnNIJksJtSj2v+pXNQZ0wBT++7+oSLgICks0qp61/4aVBYlC4YRvxqNq4681daD+ZrywHE03CTHLW9BiOAeT02RBNRY3crZ7mQ00+Khp69sF7A8NH1Pnn6p+50HQVXsT201uNCKFvqf4B3uxGEAs4qpcptgOfyh16q0wanD8A7vR7+tvjWFi0XMhPGFpxXTyZz9WygBB76o7S+PcoFJt9spYmEuxhWrirfVF4zNBj0iTZvyFhdRtCCcvLJAPhtaXaUjUd0DF+H7iLfia4Mwp0iejvLqzNKedfgoK9pDMfSgac7SRq6+Fm84Gp6ORpTna+kVHsY0UO3sZZ5j23dwo9bmnDIH/QJVdZdiShsERuwATMQH5biUzbTR6BWYR+yDV3yUuZiYRr//kda61eK1CDLwx2YybcDv2ikVKgMdt19TfpCF3IkUE1HncSJkegSxmgZaXAvqqeqvDyV7IksdCYQ64UjTBdpcycQUdFWEyU=" file: - b4a diff --git a/README.md b/README.md index 127c196..5886513 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Alternatively, you can just type the following command. NOTE: You should already have [Go](https://golang.org/doc/install) installed and GOPATH, GOROOT set to appropriate values. ```bash - go get -t github.com/back4app/parse-cli + go get -t github.com/back4app/parse-cli@latest ``` This installs a binary called `parse-cli` at `$GOPATH/bin`. diff --git a/build_debug.sh b/build_debug.sh new file mode 100755 index 0000000..19462c2 --- /dev/null +++ b/build_debug.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +this_dir=$(pwd) +export GOPATH=$HOME/gopath +export PATH=$HOME/gopath/bin:$PATH +rsync -az ./ $HOME/gopath/src/github.com/back4app/parse-cli/ +cd $HOME/gopath/src/github.com/back4app/parse-cli +go get -t -v ./ +echo Version $(parse-cli version) installed locally +rm -rf $HOME/gopath/bin/b4a-homolog +ln -s $HOME/gopath/bin/parse-cli $HOME/gopath/bin/b4a-homolog +cd $this_dir diff --git a/ci_cd/bitbucket_pipeline.yaml b/ci_cd/bitbucket_pipeline.yaml new file mode 100644 index 0000000..5f9ae9d --- /dev/null +++ b/ci_cd/bitbucket_pipeline.yaml @@ -0,0 +1,34 @@ +image: back4app/b4a_cli:latest +pipelines: + branches: + master: + - step: + name: Install dependencies + script: + - apt-get update -y + - apt-get install -y build-essential + - apt-get install -y checkinstall + - apt-get install -y libssl-dev + - apt-get install -y curl + - apt-get install -y sudo + - apt-get install -y python + - apt-get install -y wget + - apt-get install -y git + - which git + - cd /opt + - wget https://golang.org/dl/go1.12.17.linux-amd64.tar.gz + - tar zxf go1.12.17.linux-amd64.tar.gz + - export PATH=/opt/go/bin:$PATH + - export GOPATH=/go + - mkdir -p /go/src/github.com/back4app + - /usr/bin/git clone -b back4app https://github.com/back4app/parse-cli.git $GOPATH/src/github.com/back4app + - cd $GOPATH/src/github.com/back4app + - go get ./... + - GOOS=linux GOARCH=amd64 go build -o b4a_64 + - cd $GOPATH/src/github.com/back4app + - chmod 755 $GOPATH/src/github.com/back4app/b4a_64 + - ls -la $GOPATH/src/github.com/back4app/b4a_64 + - $GOPATH/src/github.com/back4app/b4a_64 version + - file $GOPATH/src/github.com/back4app/b4a_64 + - mv $GOPATH/src/github.com/back4app/b4a_64 /usr/local/bin/b4a + - /usr/local/bin/b4a version \ No newline at end of file diff --git a/configure.go b/configure.go index 42e2bbf..ca7423f 100644 --- a/configure.go +++ b/configure.go @@ -29,7 +29,7 @@ func (c *configureCmd) accountKey(e *parsecli.Env) error { email, err := c.login.AuthToken(e, token) if err != nil { - fmt.Fprintln(e.Err, "Could not store credentials. Please try again.\n") + fmt.Fprintln(e.Err, "Could not store credentials. Please try again.") return err } @@ -80,17 +80,13 @@ for email: %q } if firstEverConfigure { - fmt.Fprintln( - e.Out, - ` -Looks like this is the first time you have configured an account key. + fmt.Fprintln(e.Out, `Looks like this is the first time you have configured an account key. Note that "b4a new" and "b4a list" can automatically pick up a default key if present. Otherwise, you'll have to explicitly set the PARSER_EMAIL common.Environment variable for them to pick the correct account key. Further, if the command line tool cannot find an account key for a configured email it will try to use the default account key. -Hence, we are automatically configuring the default account key to be the same as current account key. -`, +Hence, we are automatically configuring the default account key to be the same as current account key.`, ) err = c.login.StoreCredentials(e, "", &parsecli.Credentials{Token: token}) if err != nil { @@ -100,8 +96,7 @@ Hence, we are automatically configuring the default account key to be the same a fmt.Fprintln(e.Out, `Successfully configured the default account key. To change the default account key in future use: - "b4a configure accountkey -d" -`) + "b4a configure accountkey -d"`) } return nil @@ -139,7 +134,7 @@ func (c *configureCmd) projectType(e *parsecli.Env, args []string) error { if len(args) != 0 { projectType, ok := validTypes[args[0]] if !ok { - return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", selectionString) + return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", projectType, selectionString) } selectedProjectType = projectType } @@ -160,7 +155,7 @@ Enter a number between 1 and %d: `, } projectType, ok := validTypes[validKeys[num-1]] if !ok { - return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", selectionString) + return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", projectType, selectionString) } selectedProjectType = projectType break diff --git a/configure_test.go b/configure_test.go index d9f2b0b..e597085 100644 --- a/configure_test.go +++ b/configure_test.go @@ -32,7 +32,7 @@ Input your account key or press ENTER to generate a new one. ensure.Err(t, c.accountKey(h.Env), regexp.MustCompile("is not valid")) ensure.DeepEqual(t, h.Err.String(), - "Could not store credentials. Please try again.\n\n", + "Could not store credentials. Please try again.\n", ) h.Env.Server = "http://api.parse.com/1/" diff --git a/installer.sh b/installer.sh index b6f65dd..e48b492 100755 --- a/installer.sh +++ b/installer.sh @@ -7,17 +7,32 @@ if [ -e ${TMP_FILE} ]; then fi echo "Fetching latest version ..." -# latest="3.0.6-beta-5" -latest=$(curl https://parsecli.back4app.com/supported?version=latest | python -c "import sys, json; print(json.load(sys.stdin)['version'])") +if command -v python3 &>/dev/null; then + PYTHON_EXECUTABLE="python3" +elif command -v python &>/dev/null; then + PYTHON_EXECUTABLE="python" +elif command -v python2 &>/dev/null; then + PYTHON_EXECUTABLE="python" +else + echo "Python not found" + exit 1 +fi + +latest=$(curl https://parsecli.back4app.com/supported?version=latest | $PYTHON_EXECUTABLE -c "import sys, json; print(json.load(sys.stdin)['version'])") -case `uname` in - "Linux" ) +case `uname -pm` in + "x86_64 x86_64" ) + url="https://github.com/back4app/parse-cli/releases/download/release_${latest}/b4a_linux";; + "x86_64 unknown" ) url="https://github.com/back4app/parse-cli/releases/download/release_${latest}/b4a_linux";; - "Darwin" ) + "x86_64 i386" ) url="https://github.com/back4app/parse-cli/releases/download/release_${latest}/b4a";; + "aarch64 unknown" ) + url="https://github.com/back4app/parse-cli/releases/download/release_${latest}/b4a_linux";; + "arm64 arm" ) + url="https://github.com/back4app/parse-cli/releases/download/release_${latest}/b4a_mac_m1";; esac - echo "Version ${latest} will be installed" curl --progress-bar --compressed -Lo ${TMP_FILE} ${url} @@ -30,4 +45,4 @@ echo "Installing ..." mv /tmp/back4app.tmp /usr/local/bin/b4a chmod 755 /usr/local/bin/b4a -echo "Installation finished" +echo "Installation finished" \ No newline at end of file diff --git a/parsecli/login.go b/parsecli/login.go index a87770d..fefe35c 100644 --- a/parsecli/login.go +++ b/parsecli/login.go @@ -242,17 +242,10 @@ func (l *Login) AuthUserWithToken(e *Env, strict bool) (string, error) { // user never created an account key: educate them if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) { if strict { - fmt.Fprintln( - e.Out, - `To proceed further, you must configure an account key. -`, - ) + fmt.Fprintln(e.Out, `To proceed further, you must configure an account key.`,) } else { - fmt.Fprintln( - e.Out, - `We've changed the way the CLI works. -To save time logging in, you should create an account key. -`, + fmt.Fprintln(e.Out, `We've changed the way the CLI works. +To save time logging in, you should create an account key.`, ) } diff --git a/parsecli/main.go b/parsecli/main.go index d167f62..8deeff1 100644 --- a/parsecli/main.go +++ b/parsecli/main.go @@ -21,7 +21,7 @@ import ( ) const ( - Version = "3.1" + Version = "3.3.1" CloudDir = "cloud" HostingDir = "public" DefaultBaseURL = "https://parsecli.back4app.com/" diff --git a/parsecli/utils.go b/parsecli/utils.go index f42a1ff..a6738b5 100644 --- a/parsecli/utils.go +++ b/parsecli/utils.go @@ -18,8 +18,8 @@ const ( SampleSource = ` // Use Parse.Cloud.define to define as many cloud functions as you want. // For example: -Parse.Cloud.define("hello", function(request, response) { - response.success("Hello world!"); +Parse.Cloud.define("hello", (request) => { + return "Hello world!"; }); ` diff --git a/parsecmd/deploy.go b/parsecmd/deploy.go index b582241..0ee1319 100644 --- a/parsecmd/deploy.go +++ b/parsecmd/deploy.go @@ -42,6 +42,18 @@ func (d *deployCmd) getSourceFiles( suffixes map[string]struct{}, e *parsecli.Env, ) ([]string, []string, error) { + var selected []string + var ignored []string + + if _, err := os.Stat(dirName); os.IsNotExist(err) { + if d.Verbose { + fmt.Fprintf(e.Err, + "Skipping Source folder '%s' does not exist\n", + dirName) + } + return selected, ignored, nil + } + ignoreFile := filepath.Join(e.Root, parseIgnore) content, err := ioutil.ReadFile(ignoreFile) @@ -73,7 +85,6 @@ func (d *deployCmd) getSourceFiles( return nil, nil, stackerr.Wrap(err) } - var selected []string errors, err = parseIgnoreWalk(matcher, dirName, func(path string, info os.FileInfo, err error) error { @@ -101,7 +112,6 @@ func (d *deployCmd) getSourceFiles( ) } - var ignored []string for file := range ignoredSet { ignored = append(ignored, file) } @@ -378,16 +388,9 @@ func (d *deployCmd) deploy( return nil, err } } - scriptChecksums, scriptVersions, err := d.uploadSourceFiles(&uploader{ DirName: "cloud", - Suffixes: map[string]struct{}{ - ".js": {}, - ".ejs": {}, - ".jade": {}, - ".pug": {}, // jade now is pug - ".json": {}, - }, + Suffixes: map[string]struct{}{}, EndPoint: "scripts", PrevChecksums: prevDeplInfo.Checksums.Cloud, PrevVersions: prevDeplInfo.Versions.Cloud, diff --git a/parsecmd/deploy_test.go b/parsecmd/deploy_test.go index 0d5a703..f967c50 100644 --- a/parsecmd/deploy_test.go +++ b/parsecmd/deploy_test.go @@ -467,11 +467,11 @@ func TestDeployFilesChanged(t *testing.T) { expected := &deployInfo{ ParseVersion: "latest", Checksums: deployFileData{ - Cloud: map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, + Cloud: map[string]string{"sample.txt": "d41d8cd98f00b204e9800998ecf8427e", "main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"}, }, Versions: deployFileData{ - Cloud: map[string]string{"main.js": "f2"}, + Cloud: map[string]string{"sample.txt": "f2", "main.js": "f2"}, Public: map[string]string{"index.html": "f2"}, }, } @@ -492,9 +492,11 @@ The following files will be ignored: Finished uploading files New release is named v1 (using Parse JavaScript SDK vlatest) `, - filepath.Join(h.Env.Root, parsecli.CloudDir, "main.js"), strings.Join([]string{ - filepath.Join(h.Env.Root, parsecli.CloudDir, "sample.txt"), + filepath.Join(h.Env.Root, parsecli.CloudDir, "main.js"), + filepath.Join(h.Env.Root, parsecli.CloudDir, "sample.txt")}, + "\n"), + strings.Join([]string{ filepath.Join(h.Env.Root, parsecli.CloudDir, "test~")}, "\n"), filepath.Join(h.Env.Root, parsecli.HostingDir, "index.html"), @@ -511,11 +513,11 @@ func TestDeployFilesUnChanged(t *testing.T) { info := &deployInfo{ ParseVersion: "latest", Checksums: deployFileData{ - Cloud: map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, + Cloud: map[string]string{"sample.txt": "d41d8cd98f00b204e9800998ecf8427e", "main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"}, }, Versions: deployFileData{ - Cloud: map[string]string{"main.js": "f2"}, + Cloud: map[string]string{"sample.txt": "f2", "main.js": "f2"}, Public: map[string]string{"index.html": "f2"}, }, } @@ -530,11 +532,11 @@ func TestDeployFilesUnChanged(t *testing.T) { expected := &deployInfo{ ParseVersion: "latest", Checksums: deployFileData{ - Cloud: map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, + Cloud: map[string]string{"sample.txt": "d41d8cd98f00b204e9800998ecf8427e", "main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"}, }, Versions: deployFileData{ - Cloud: map[string]string{"main.js": "f2"}, + Cloud: map[string]string{"sample.txt": "f2", "main.js": "f2"}, Public: map[string]string{"index.html": "f2"}, }, } @@ -570,11 +572,11 @@ func TestDeployFilesNoVersion(t *testing.T) { expected := &deployInfo{ ParseVersion: "latest", Checksums: deployFileData{ - Cloud: map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, + Cloud: map[string]string{"sample.txt": "d41d8cd98f00b204e9800998ecf8427e", "main.js": "4ece160cc8e5e828ee718e7367cf5d37"}, Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"}, }, Versions: deployFileData{ - Cloud: map[string]string{"main.js": "f2"}, + Cloud: map[string]string{"sample.txt": "f2", "main.js": "f2"}, Public: map[string]string{"index.html": "f2"}, }, } @@ -596,9 +598,11 @@ The following files will be ignored: Finished uploading files New release is named v1 (using Parse JavaScript SDK vlatest) `, - filepath.Join(h.Env.Root, parsecli.CloudDir, "main.js"), strings.Join([]string{ - filepath.Join(h.Env.Root, parsecli.CloudDir, "sample.txt"), + filepath.Join(h.Env.Root, parsecli.CloudDir, "main.js"), + filepath.Join(h.Env.Root, parsecli.CloudDir, "sample.txt")}, + "\n"), + strings.Join([]string{ filepath.Join(h.Env.Root, parsecli.CloudDir, "test~")}, "\n"), filepath.Join(h.Env.Root, parsecli.HostingDir, "index.html"), @@ -650,22 +654,22 @@ func TestDeployRetries(t *testing.T) { ctx := parsecli.Context{Config: defaultParseConfig} ctx.Config.GetProjectConfig().Parse.JSSDK = "latest" - ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("no such file or directory")) + ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("No files to upload")) ensure.DeepEqual(t, h.Err.String(), "") h.Err.Reset() d.Retries = 2 - ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("no such file or directory")) + ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("No files to upload")) ensure.DeepEqual( t, h.Err.String(), - "Deploy failed with error:\nlstat cloud: no such file or directory\nWill retry in 0 seconds.\n\n", + "Deploy failed with error:\nNo files to upload\nWill retry in 0 seconds.\n\n", ) h.Err.Reset() d.Retries = 5 - ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("no such file or directory")) - errStr := "Deploy failed with error:\nlstat cloud: no such file or directory\nWill retry in 0 seconds.\n\n" + ensure.Err(t, d.run(h.Env, &ctx), regexp.MustCompile("No files to upload")) + errStr := "Deploy failed with error:\nNo files to upload\nWill retry in 0 seconds.\n\n" errStr += strings.Repeat("Sorry, deploy failed again with same error.\nWill retry in 0 seconds.\n\n", 3) ensure.DeepEqual(t, h.Err.String(), errStr) } diff --git a/parsecmd/new.go b/parsecmd/new.go index 0754f5e..d407839 100644 --- a/parsecmd/new.go +++ b/parsecmd/new.go @@ -31,13 +31,9 @@ func CloneSampleCloudCode( if err == errNoFiles { dumpTemplate = true } else { - fmt.Fprintln( - e.Out, - ` -NOTE: If you like to fetch the latest deployed Cloud Code from Parse, + fmt.Fprintln(e.Out, `NOTE: If you like to fetch the latest deployed Cloud Code from Parse, you can use the "b4a download" command after finishing the set up. -This will download Cloud Code to a temporary location. -`, +This will download Cloud Code to a temporary location.`, ) } }