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

Commit e02ba16

Browse files
Merge branch 'release/1.7.0'
2 parents 1d77fb6 + b1efca3 commit e02ba16

14 files changed

Lines changed: 524 additions & 367 deletions

File tree

‎markdown.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Dashboard Plugin
2+
Dashboard Plugin is a starter project for developing Dashboard plugins that contains all the tools you need for writing awesome plugins.
3+
4+
## Wiki
5+
[Learn all the things](https://github.com/Infomaker/Dashboard-Plugin/wiki)
6+
7+
## License
8+
Dashboard Plugin is released under the [MIT](http://www.opensource.org/licenses/MIT) License.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dashboard-plugin",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"license": "ISC",
55
"description": "Infomaker Dashboard Starter Plugin",
66
"homepage": "https://github.com/Infomaker/Dashboard-Plugin",

‎prompt.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ fs.readFile('./manifest.json', (err, data) => {
5151

5252
fs.writeFile('./manifest.json', JSON.stringify(manifest_template, null, 4), 'utf8', err => {
5353
if (!err) {
54-
console.log(`\t ${colors.bgWhite(colors.black("-----------------------------------"))}`)
55-
console.log(`\t ${colors.bgWhite(colors.black('🎉 manifest file has been updated 🎉.'))}`)
56-
console.log(`\t ${colors.bgWhite(colors.black("-----------------------------------"))}`)
54+
console.log(`\t ${colors.bgWhite(colors.black("------------------------------------"))}`)
55+
console.log(`\t ${colors.bgWhite(colors.black('🎉 manifest file has been updated 🎉'))}`)
56+
console.log(`\t ${colors.bgWhite(colors.black("------------------------------------"))}`)
5757
} else {
5858
console.log('Failed to update manifest.json')
5959
}

‎s3.js‎

Lines changed: 147 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
const AWS = require('aws-sdk')
1212
const fs = require('fs')
1313
const exec = require('child_process').exec
14+
const colors = require("colors/safe")
15+
const zlib = require('zlib')
16+
1417
let manifest = require('./manifest.json')
1518

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

28-
console.log("\n ----------------------------")
29-
console.log(" Plugin S3 plugin uploader ")
30-
console.log(" ----------------------------\n")
31+
console.log('\n')
32+
console.log(`\t ${colors.bgWhite(colors.black(" --------------------------- "))}`)
33+
console.log(`\t ${colors.bgWhite(colors.black(" Plugin S3 plugin uploader "))}`)
34+
console.log(`\t ${colors.bgWhite(colors.black(" --------------------------- "))}`)
35+
console.log('\n')
3136

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

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

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

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

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

68-
if (shouldUploadPluginIcon) {
69-
uploadPluginIcon(pluginIconData).then(location => {
70-
console.log("> uploaded plugin icon > " + location + "\n")
71-
72-
if (manifest.graphic_url != location) {
73-
manifest.graphic_url = location
74-
75-
fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', err => {
76-
if (!err) {
77-
uploadManifest()
78-
} else {
79-
console.log("> failed to set manifest graphic url... (will continue to upload manifest) \n")
80-
81-
uploadManifest()
82-
}
83-
})
84-
} else {
85-
uploadManifest()
86-
}
87-
}).catch(err => console.log("💥 " + err))
88-
} else {
89-
uploadManifest()
72+
/**
73+
* Check if icon.png is exist.
74+
* Upload icon.png
75+
*/
76+
uploadIcon(shouldUploadPluginIcon, pluginIconData).then(iconLocation => {
77+
if (iconLocation) {
78+
console.log("> uploaded plugin icon > " + iconLocation + "\n")
9079

91-
if (manifest.graphic_url) {
92-
delete manifest.graphic_url
93-
fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', () => remove("icon.png"))
80+
manifest.graphic_url = iconLocation
9481
}
95-
}
9682

83+
/**
84+
* Check if thumbnail.png is exist.
85+
* Upload thumbnail.png
86+
*/
87+
uploadThumbnail().then(thumbnailLocation => {
88+
if (thumbnailLocation) {
89+
console.log("> uploaded plugin thumbnail > " + thumbnailLocation + "\n")
90+
91+
manifest.thumbnail_url = thumbnailLocation
92+
}
93+
94+
/**
95+
* Check if markdown.md is exist.
96+
* Upload markdown.md
97+
*/
98+
uploadMarkdown().then(markDownLocation => {
99+
if (markDownLocation) {
100+
console.log("> uploaded plugin markdown > " + markDownLocation + "\n")
101+
102+
manifest.markdown_url = markDownLocation
103+
}
104+
105+
/**
106+
* Set timestamp as a build version to avoid browser cache.
107+
* buildVersion won't be stored with plugin data.
108+
*/
109+
manifest.buildVersion = Date.now()
110+
111+
/**
112+
* Update the manifest file with new urls
113+
* Upload manifest.json
114+
*/
115+
updateManifestFile().then(() => uploadManifest())
116+
})
117+
})
118+
})
97119
}).catch(err => console.log("💥 " + err))
98120
})
99121

122+
function updateManifestFile() {
123+
return new Promise(resolve => {
124+
fs.writeFile('./manifest.json', JSON.stringify(manifest, null, 4), 'utf8', err => {
125+
if (!err) {
126+
resolve()
127+
} else {
128+
console.log("> failed to set manifest properties (will continue to upload manifest) \n")
129+
130+
resolve()
131+
}
132+
})
133+
})
134+
}
135+
136+
function uploadIcon(shouldUploadPluginIcon, pluginIconData) {
137+
return new Promise(resolve => {
138+
if (shouldUploadPluginIcon) {
139+
uploadPluginIcon(pluginIconData).then(iconLocation => resolve(iconLocation)).catch(err => {
140+
console.log("💥 " + err)
141+
142+
resolve(null)
143+
})
144+
} else {
145+
resolve(null)
146+
}
147+
})
148+
}
149+
150+
function uploadThumbnail() {
151+
return new Promise(resolve => {
152+
fs.readFile('./thumbnail.png', (err, pluginThumbnail) => {
153+
if (!err && pluginThumbnail) {
154+
upload({
155+
resolve: resolve,
156+
reject: err => {
157+
console.log("💥 " + err)
158+
resolve(null)
159+
},
160+
key: "thumbnail.png",
161+
data: pluginThumbnail,
162+
contentType: "image/png"
163+
})
164+
} else {
165+
resolve(null)
166+
}
167+
})
168+
})
169+
}
170+
100171
function uploadIndexJS() {
101172
return new Promise((resolve, reject) => {
102-
upload({
103-
resolve: resolve,
104-
reject: reject,
105-
key: "index.js",
106-
data: fs.readFileSync("dist/index.js"),
107-
contentType: "text/javascript"
173+
zlib.gzip(fs.readFileSync("dist/index.js"), (error, result) => {
174+
if (error) throw error
175+
176+
upload({
177+
resolve: resolve,
178+
reject: reject,
179+
key: "index.js",
180+
data: result,
181+
contentType: "text/javascript",
182+
contentEncoding: "gzip"
183+
})
108184
})
109185
})
110186
}
111187

112188
function uploadStyleCSS() {
113189
return new Promise((resolve, reject) => {
114-
upload({
115-
resolve: resolve,
116-
reject: reject,
117-
key: "style.css",
118-
data: fs.readFileSync("dist/style.css"),
119-
contentType: "text/css"
190+
zlib.gzip(fs.readFileSync("dist/style.css"), (error, result) => {
191+
if (error) throw error
192+
193+
upload({
194+
resolve: resolve,
195+
reject: reject,
196+
key: "style.css",
197+
data: result,
198+
contentType: "text/css",
199+
contentEncoding: "gzip"
200+
})
120201
})
121202
})
122203
}
@@ -133,13 +214,34 @@ function uploadPluginIcon(data) {
133214
})
134215
}
135216

217+
function uploadMarkdown() {
218+
return new Promise(resolve => {
219+
fs.readFile('./markdown.md', (err, pluginMarkDown) => {
220+
if (!err && pluginMarkDown) {
221+
upload({
222+
resolve: resolve,
223+
reject: err => {
224+
console.log("💥 " + err)
225+
resolve(null)
226+
},
227+
key: "markdown.md",
228+
data: pluginMarkDown,
229+
contentType: "text/markdown"
230+
})
231+
} else {
232+
resolve(null)
233+
}
234+
})
235+
})
236+
}
237+
136238
function uploadManifestJSON() {
137239
return new Promise((resolve, reject) => {
138240
upload({
139241
resolve: resolve,
140242
reject: reject,
141243
key: "manifest.json",
142-
data: fs.readFileSync("dist/manifest.json"),
244+
data: JSON.stringify(manifest, null, 4),
143245
contentType: "application/json"
144246
})
145247
})
@@ -151,7 +253,7 @@ function upload(params) {
151253
Key: baseKey + "/" + params.key,
152254
Body: params.data,
153255
ContentType: params.contentType,
154-
ContentEncoding: "UTF-8",
256+
ContentEncoding: params.contentEncoding || "UTF-8",
155257
ACL: "public-read"
156258
}, (err, data) => err ? params.reject(err) : params.resolve(data.Location))
157259
}

0 commit comments

Comments
 (0)