Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish-market.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish application in market

on:
push:
paths:
- 'assets/application.json'

jobs:
pulish-market:
name: Publish application in market
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: "12.x"
registry-url: "https://registry.npmjs.org/"

- name: Publish application in market
env:
MARKET_TOKEN: ${{ secrets.MARKET_TOKEN }}
run: "MARKET_TOKEN=$MARKET_TOKEN npm run publish:market"
2 changes: 1 addition & 1 deletion assets/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
},
"auth_callback_uri": "https://us-central1-ecom-app-boilerplate.cloudfunctions.net/app/ecom/auth-callback",
"version": "1.0.0"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"serve": "echo 'Firebase runs with legacy Node.js 8; Use `npm run deploy` instead.'",
"deploy": "NODE_ENV=production node ./firebase.js",
"release": "standard-version",
"release:starter": "standard-version --prerelease starter"
"release:starter": "standard-version --prerelease starter",
"publish:market": "node ./publish-market.js"
},
"repository": {
"type": "git",
Expand Down
55 changes: 55 additions & 0 deletions publish-market.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict'
const https = require('https')
const storeApp = require('./assets/application.json')
const { MARKET_TOKEN } = process.env

if (!MARKET_TOKEN) {
console.error('Env MARKET_TOKEN is unset')
process.exit(1)
}

const { title, slug } = storeApp

let data = {
title,
slug,
category: 'all',
store_app: storeApp
}

if (storeApp.app_id) {
data.id = storeApp.app_id
}

data = JSON.stringify(data)

const opt = {
hostname: 'market.e-com.plus',
port: 443,
path: '/v2/applications',
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + MARKET_TOKEN
}
}

const req = https.request(opt, res => {
const { statusCode } = res
if (statusCode >= 201 && statusCode <= 204) {
console.log('Application updated')
} else {
console.error('API Request error')
}
res.on('data', d => {
process.stdout.write(d)
})
})

req.on('error', error => {
console.error(error)
process.exit(1)
})

req.write(data)
req.end()