Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahalhariri committed Mar 26, 2018
2 parents 1d77fb6 + b1efca3 commit e02ba16
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 367 deletions.
8 changes: 8 additions & 0 deletions markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dashboard Plugin
Dashboard Plugin is a starter project for developing Dashboard plugins that contains all the tools you need for writing awesome plugins.

## Wiki
[Learn all the things](https://github.com/Infomaker/Dashboard-Plugin/wiki)

## License
Dashboard Plugin is released under the [MIT](http://www.opensource.org/licenses/MIT) License.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashboard-plugin",
"version": "1.6.0",
"version": "1.7.0",
"license": "ISC",
"description": "Infomaker Dashboard Starter Plugin",
"homepage": "https://github.com/Infomaker/Dashboard-Plugin",
Expand Down
6 changes: 3 additions & 3 deletions prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ fs.readFile('./manifest.json', (err, data) => {

fs.writeFile('./manifest.json', JSON.stringify(manifest_template, null, 4), 'utf8', err => {
if (!err) {
console.log(`\t ${colors.bgWhite(colors.black("-----------------------------------"))}`)
console.log(`\t ${colors.bgWhite(colors.black('🎉 manifest file has been updated 🎉.'))}`)
console.log(`\t ${colors.bgWhite(colors.black("-----------------------------------"))}`)
console.log(`\t ${colors.bgWhite(colors.black("------------------------------------"))}`)
console.log(`\t ${colors.bgWhite(colors.black('🎉 manifest file has been updated 🎉'))}`)
console.log(`\t ${colors.bgWhite(colors.black("------------------------------------"))}`)
} else {
console.log('Failed to update manifest.json')
}
Expand Down
192 changes: 147 additions & 45 deletions s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
const AWS = require('aws-sdk')
const fs = require('fs')
const exec = require('child_process').exec
const colors = require("colors/safe")
const zlib = require('zlib')

let manifest = require('./manifest.json')

const expectedArgs = ["bucket", "accessKeyId", "secretAccessKey"]
Expand All @@ -25,9 +28,11 @@ process.argv.forEach(arg => {
}
})

console.log("\n ----------------------------")
console.log(" Plugin S3 plugin uploader ")
console.log(" ----------------------------\n")
console.log('\n')
console.log(`\t ${colors.bgWhite(colors.black(" --------------------------- "))}`)
console.log(`\t ${colors.bgWhite(colors.black(" Plugin S3 plugin uploader "))}`)
console.log(`\t ${colors.bgWhite(colors.black(" --------------------------- "))}`)
console.log('\n')

if (!args.accessKeyId) {
console.log("💥 Failed to upload plugin, missing arg accessKeyId")
Expand All @@ -42,10 +47,9 @@ if (!args.accessKeyId) {

const s3Bucket = new AWS.S3({ accessKeyId: args.accessKeyId, secretAccessKey: args.secretAccessKey })

const pluginName = manifest.name.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()}).replace(/\s/g, '')

const versionPaths = manifest.version.split(".")
const bundlePath = manifest.bundle.replace(/\./g, '-').toLowerCase()
const versionPaths = manifest.version.split(".")
const majorVersionPath = versionPaths[0]
const baseKey = `${bundlePath}/v${majorVersionPath}`

Expand All @@ -65,58 +69,135 @@ fs.readFile('./icon.png', (err, pluginIconData) => {
}).catch(err => console.log("💥 " + err))
}

if (shouldUploadPluginIcon) {
uploadPluginIcon(pluginIconData).then(location => {
console.log("> uploaded plugin icon > " + location + "\n")

if (manifest.graphic_url != location) {
manifest.graphic_url = location

fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', err => {
if (!err) {
uploadManifest()
} else {
console.log("> failed to set manifest graphic url... (will continue to upload manifest) \n")

uploadManifest()
}
})
} else {
uploadManifest()
}
}).catch(err => console.log("💥 " + err))
} else {
uploadManifest()
/**
* Check if icon.png is exist.
* Upload icon.png
*/
uploadIcon(shouldUploadPluginIcon, pluginIconData).then(iconLocation => {
if (iconLocation) {
console.log("> uploaded plugin icon > " + iconLocation + "\n")

if (manifest.graphic_url) {
delete manifest.graphic_url
fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', () => remove("icon.png"))
manifest.graphic_url = iconLocation
}
}

/**
* Check if thumbnail.png is exist.
* Upload thumbnail.png
*/
uploadThumbnail().then(thumbnailLocation => {
if (thumbnailLocation) {
console.log("> uploaded plugin thumbnail > " + thumbnailLocation + "\n")

manifest.thumbnail_url = thumbnailLocation
}

/**
* Check if markdown.md is exist.
* Upload markdown.md
*/
uploadMarkdown().then(markDownLocation => {
if (markDownLocation) {
console.log("> uploaded plugin markdown > " + markDownLocation + "\n")

manifest.markdown_url = markDownLocation
}

/**
* Set timestamp as a build version to avoid browser cache.
* buildVersion won't be stored with plugin data.
*/
manifest.buildVersion = Date.now()

/**
* Update the manifest file with new urls
* Upload manifest.json
*/
updateManifestFile().then(() => uploadManifest())
})
})
})
}).catch(err => console.log("💥 " + err))
})

function updateManifestFile() {
return new Promise(resolve => {
fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', err => {
if (!err) {
resolve()
} else {
console.log("> failed to set manifest properties (will continue to upload manifest) \n")

resolve()
}
})
})
}

function uploadIcon(shouldUploadPluginIcon, pluginIconData) {
return new Promise(resolve => {
if (shouldUploadPluginIcon) {
uploadPluginIcon(pluginIconData).then(iconLocation => resolve(iconLocation)).catch(err => {
console.log("💥 " + err)

resolve(null)
})
} else {
resolve(null)
}
})
}

function uploadThumbnail() {
return new Promise(resolve => {
fs.readFile('./thumbnail.png', (err, pluginThumbnail) => {
if (!err && pluginThumbnail) {
upload({
resolve: resolve,
reject: err => {
console.log("💥 " + err)
resolve(null)
},
key: "thumbnail.png",
data: pluginThumbnail,
contentType: "image/png"
})
} else {
resolve(null)
}
})
})
}

function uploadIndexJS() {
return new Promise((resolve, reject) => {
upload({
resolve: resolve,
reject: reject,
key: "index.js",
data: fs.readFileSync("dist/index.js"),
contentType: "text/javascript"
zlib.gzip(fs.readFileSync("dist/index.js"), (error, result) => {
if (error) throw error

upload({
resolve: resolve,
reject: reject,
key: "index.js",
data: result,
contentType: "text/javascript",
contentEncoding: "gzip"
})
})
})
}

function uploadStyleCSS() {
return new Promise((resolve, reject) => {
upload({
resolve: resolve,
reject: reject,
key: "style.css",
data: fs.readFileSync("dist/style.css"),
contentType: "text/css"
zlib.gzip(fs.readFileSync("dist/style.css"), (error, result) => {
if (error) throw error

upload({
resolve: resolve,
reject: reject,
key: "style.css",
data: result,
contentType: "text/css",
contentEncoding: "gzip"
})
})
})
}
Expand All @@ -133,13 +214,34 @@ function uploadPluginIcon(data) {
})
}

function uploadMarkdown() {
return new Promise(resolve => {
fs.readFile('./markdown.md', (err, pluginMarkDown) => {
if (!err && pluginMarkDown) {
upload({
resolve: resolve,
reject: err => {
console.log("💥 " + err)
resolve(null)
},
key: "markdown.md",
data: pluginMarkDown,
contentType: "text/markdown"
})
} else {
resolve(null)
}
})
})
}

function uploadManifestJSON() {
return new Promise((resolve, reject) => {
upload({
resolve: resolve,
reject: reject,
key: "manifest.json",
data: fs.readFileSync("dist/manifest.json"),
data: JSON.stringify(manifest, null, 4),
contentType: "application/json"
})
})
Expand All @@ -151,7 +253,7 @@ function upload(params) {
Key: baseKey + "/" + params.key,
Body: params.data,
ContentType: params.contentType,
ContentEncoding: "UTF-8",
ContentEncoding: params.contentEncoding || "UTF-8",
ACL: "public-read"
}, (err, data) => err ? params.reject(err) : params.resolve(data.Location))
}
Expand Down
Loading

0 comments on commit e02ba16

Please sign in to comment.