Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
*.npmignore
46 changes: 35 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,53 @@ PlayCanvasWebpackPlugin.prototype.apply = function (compiler) {
console.log("Uploading " + filename.path + " to PlayCanvas")
let content = asset.children.map(c => c._value ? c._value : c).join('\n')
let req = request({
uri: `https://playcanvas.com/api/assets`,
method: 'POST',
uri: `https://playcanvas.com/api/assets/${filename.assetId}`,
method: 'PUT',
headers: {
"Authorization": `Bearer ${options.bearer}`
}
})
let form = req.form()
form.append("project", "" + options.project)
form.append("name", "" + filename.path)
form.append("asset", "" + filename.assetId)
form.append("data", JSON.stringify({order: filename.priority || 100, scripts: {}}))
form.append("preload", "true")
form.append("branchId", "" + options.branchId)
form.append("file", content, {
filename: filename.path,
contentType: "text/javascript"
})
req.then(() => {
console.log("Upload complete for file " + filename.path)
console.log("Upload complete for file (update) " + filename.path)
callback()
}, (e) => {
console.error(e)
compilation.errors.push(e)
callback()
if(e.statusCode === 404){
let req = request({
uri: `https://playcanvas.com/api/assets`,
method: 'POST',
headers: {
"Authorization": `Bearer ${options.bearer}`
}
})
let form = req.form()
form.append("name", "" + filename.path)
form.append("project", "" + options.project)
form.append("branchId", "" + options.branchId)
form.append("preload", "true")
form.append("file", content, {
filename: filename.path,
contentType: "text/javascript"
})
req.then((res) => {
console.log("Upload complete for file (create) " + filename.path)
compilation.warnings.push("PlayCanvas Webpack Plugin\nNew main.build.js has been created. Update assetId config to" + JSON.parse(res).id)
callback()
}, (e) => {
console.error(e)
compilation.errors.push(e)
callback()
})
}else{
console.error(e)
compilation.errors.push(e)
callback()
}
})


Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "playcanvas-webpack-plugin",
"version": "1.0.8",
"version": "1.0.9",
"description": "WebPack plugin to upload built script files to PlayCanvas.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mike Talbot",
"author": {
"name": "Mike Talbot"
},
"license": "ISC",
"dependencies": {
"lodash": "^4.17.4",
Expand All @@ -25,5 +27,7 @@
"bugs": {
"url": "https://github.com/whydoidoit/playcanvas-webpack-plugin/issues"
},
"homepage": "https://github.com/whydoidoit/playcanvas-webpack-plugin#readme"
"homepage": "https://github.com/whydoidoit/playcanvas-webpack-plugin#readme",
"bundleDependencies": false,
"deprecated": false
}
13 changes: 8 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ npm install --save playcanvas-webpack-plugin

1. Build your WebPack output one time.

2. Go to the PlayCanvas editor for your project on the web and open your developer tools.
2. Go to your account settings and scroll down to API Tokens and generate a new one.

3. Drop the build file into the assets window.
2. Go to the project overview page and copy the project id from the URL.

4. In the javascript console type config.accessToken - use this as your bearer token later
3. Go to the PlayCanvas editor for your project on the web.

5. In the javascript console type config.project.id - use this as your project id later
4. Go to version control and note the branch id of the current/wanted branch.

5. Drop the build file into the assets window.

6. Select the build file you dropped in the assets window of the PlayCanvas editor and note its
Asset Id in the properties panel. Use this in your WebPack configuration along with
the bearer token and the project id.
the API token, branch id and the project id.

7. In your webpack config add the plugin and configure its options:

Expand Down Expand Up @@ -56,6 +58,7 @@ module.exports = {

bearer: 'YOUR_BEARER_TOKEN', // From the step above
project: YOUR_PROJECT_ID, // From the step above
branchid: YOUR_BRANCH_ID, // From the step above
files: {
"your_build.output.js": { //Name of your build output
path: "your_build.output.js", //Name in PlayCanvas, normally the same
Expand Down