From 459a2f466cc393954f2fa5261943cd04b6a4bcad Mon Sep 17 00:00:00 2001 From: Ian Turgeon Date: Tue, 28 May 2019 22:22:50 -0400 Subject: [PATCH] run prettier over js/css --- assets/css/mwdk-datatable.css | 166 ++++++----- assets/css/mwdk-download.css | 10 +- assets/css/mwdk-main.css | 34 +-- assets/css/mwdk-player.css | 6 +- express.js | 503 +++++++++++++++++--------------- package.json | 2 +- src/mwdk.package.js | 43 ++- src/mwdk.splash.js | 34 ++- webpack-generate-widget-hash.js | 22 +- webpack-widget.js | 69 ++--- webpack.config.js | 16 +- 11 files changed, 474 insertions(+), 431 deletions(-) diff --git a/assets/css/mwdk-datatable.css b/assets/css/mwdk-datatable.css index 38b3354..fb0e748 100644 --- a/assets/css/mwdk-datatable.css +++ b/assets/css/mwdk-datatable.css @@ -1,4 +1,3 @@ - /* * Table */ @@ -6,9 +5,9 @@ table.dataTable { margin: 0 auto; clear: both; width: 100%; - padding:0; - border-spacing:0px; - font-size:13px; + padding: 0; + border-spacing: 0px; + font-size: 13px; } table.dataTable thead th { @@ -27,7 +26,7 @@ table.dataTable tfoot th { table.dataTable td { padding: 5px 10px; - margin:0; + margin: 0; position: relative; } @@ -36,8 +35,12 @@ table.dataTable td.dataTables_empty { text-align: center; } -table.dataTable tr.odd { background-color: #EEE; } -table.dataTable tr.even { background-color: white; } +table.dataTable tr.odd { + background-color: #eee; +} +table.dataTable tr.even { + background-color: white; +} /* * Table wrapper @@ -48,7 +51,6 @@ table.dataTable tr.even { background-color: white; } *zoom: 1; } - /* * Page length menu */ @@ -56,7 +58,6 @@ table.dataTable tr.even { background-color: white; } float: left; } - /* * Filter */ @@ -65,7 +66,6 @@ table.dataTable tr.even { background-color: white; } text-align: right; } - /* * Table information */ @@ -74,7 +74,6 @@ table.dataTable tr.even { background-color: white; } float: left; } - /* * Pagination */ @@ -121,13 +120,25 @@ table.dataTable tr.even { background-color: white; } margin-left: 10px; } -.paginate_enabled_previous { background: url(./../img/datatables/back_enabled.png) no-repeat top left; } -.paginate_enabled_previous:hover { background: url(./../img/datatables/back_enabled_hover.png) no-repeat top left; } -.paginate_disabled_previous { background: url(./../img/datatables/back_disabled.png) no-repeat top left; } +.paginate_enabled_previous { + background: url(./../img/datatables/back_enabled.png) no-repeat top left; +} +.paginate_enabled_previous:hover { + background: url(./../img/datatables/back_enabled_hover.png) no-repeat top left; +} +.paginate_disabled_previous { + background: url(./../img/datatables/back_disabled.png) no-repeat top left; +} -.paginate_enabled_next { background: url(./../img/datatables/forward_enabled.png) no-repeat top right; } -.paginate_enabled_next:hover { background: url(./../img/datatables/forward_enabled_hover.png) no-repeat top right; } -.paginate_disabled_next { background: url(./../img/datatables/forward_disabled.png) no-repeat top right; } +.paginate_enabled_next { + background: url(./../img/datatables/forward_enabled.png) no-repeat top right; +} +.paginate_enabled_next:hover { + background: url(./../img/datatables/forward_enabled_hover.png) no-repeat top right; +} +.paginate_disabled_next { + background: url(./../img/datatables/forward_disabled.png) no-repeat top right; +} /* Full number pagination */ .paging_full_numbers { @@ -135,7 +146,7 @@ table.dataTable tr.even { background-color: white; } line-height: 22px; } .paging_full_numbers a:active { - outline: none + outline: none; } .paging_full_numbers a:hover { text-decoration: none; @@ -164,10 +175,9 @@ table.dataTable tr.even { background-color: white; } } .paging_full_numbers a.paginate_active { - background-color: #99B3FF; + background-color: #99b3ff; } - /* * Processing indicator */ @@ -187,21 +197,27 @@ table.dataTable tr.even { background-color: white; } background-color: white; } - /* * Sorting */ -.sorting_asc { background: url(./../img/datatables/sort_asc.png) no-repeat center right; } -.sorting_desc { background: url(./../img/datatables/sort_desc.png) no-repeat center right; } +.sorting_asc { + background: url(./../img/datatables/sort_asc.png) no-repeat center right; +} +.sorting_desc { + background: url(./../img/datatables/sort_desc.png) no-repeat center right; +} -.sorting_asc_disabled { background: url(./../img/datatables/sort_asc_disabled.png) no-repeat center right; } -.sorting_desc_disabled { background: url(./../img/datatables/sort_desc_disabled.png) no-repeat center right; } +.sorting_asc_disabled { + background: url(./../img/datatables/sort_asc_disabled.png) no-repeat center right; +} +.sorting_desc_disabled { + background: url(./../img/datatables/sort_desc_disabled.png) no-repeat center right; +} table.dataTable th:active { outline: none; } - /* * Scrolling */ @@ -214,63 +230,57 @@ table.dataTable th:active { } body table.dataTable tr.row_selected, -body table.dataTable tr.row_selected td -{ - background-color:#ffcb68 !important; +body table.dataTable tr.row_selected td { + background-color: #ffcb68 !important; } body table.dataTable tr:hover, -body table.dataTable tr td:hover -{ - background-color:#ffe0a5; +body table.dataTable tr td:hover { + background-color: #ffe0a5; } -table.dataTable tr td span.q{ - margin-left:30px; - display:block; +table.dataTable tr td span.q { + margin-left: 30px; + display: block; } -table.dataTable tr td input[type="checkbox"] -{ - float:left; +table.dataTable tr td input[type='checkbox'] { + float: left; } -table.dataTable tr td .numeric -{ - float:right; - white-space:nowrap; +table.dataTable tr td .numeric { + float: right; + white-space: nowrap; } -body, html { +body, +html { font-family: 'Lato', arial, serif; } -.dataTables_wrapper -{ +.dataTables_wrapper { position: relative; clear: both; margin: 0px auto; background: #fff; - border: rgba(0,0,0,0.11) 1px solid; + border: rgba(0, 0, 0, 0.11) 1px solid; -moz-box-shadow: 1px 3px 10px #888; -webkit-box-shadow: 1px 3px 10px #888; box-shadow: 1px 3px 10px #888; } #import-form { - padding:10px 5px; - min-width:500px; + padding: 10px 5px; + min-width: 500px; } -#question-table_filter{ - background:#efefef; - padding:6px 10px; - float:none; - +#question-table_filter { + background: #efefef; + padding: 6px 10px; + float: none; } -#question-table_filter input[type="text"] -{ +#question-table_filter input[type='text'] { width: 124px; border: solid 1px #b0b0b0; -webkit-border-radius: 12px; @@ -283,8 +293,8 @@ body, html { outline: none; } -body#question_importer h1{ - position:absolute; +body#question_importer h1 { + position: absolute; font-size: 18px; font-weight: 550; text-shadow: 0 1px #fbfbfb; @@ -295,8 +305,7 @@ body#question_importer h1{ margin: 0px; } -.dataTables_scroll -{ +.dataTables_scroll { margin: 0px 5px; } @@ -310,7 +319,7 @@ body#question_importer h1{ color: #545454; } -.gray:hover{ +.gray:hover { background-image: -webkit-linear-gradient(top, #b8b8b8, #e4e4e4); background-image: -moz-linear-gradient(top, #b8b8b8, #e4e4e4); background-image: -o-linear-gradient(top, #b8b8b8, #e4e4e4); @@ -318,24 +327,23 @@ body#question_importer h1{ text-decoration: none; } -#upload-cancel-button{ +#upload-cancel-button { position: absolute; - z-index:3; + z-index: 3; font-size: 14px; padding: 10px 15px; } -#import-form .actions{ +#import-form .actions { margin: 0 auto; text-align: center; - } #import-form input.action_button { margin-top: 16px; } -.dataTables_info{ +.dataTables_info { clear: none; position: absolute; top: 13px; @@ -345,33 +353,33 @@ body#question_importer h1{ text-align: right; } -table.dataTable thead th{ - border-bottom:1px solid #DDD; - padding:10px 18px; +table.dataTable thead th { + border-bottom: 1px solid #ddd; + padding: 10px 18px; color: #666; } -#uploader-form{ +#uploader-form { display: block; position: absolute; bottom: 75px; left: 10px; right: 10px; - z-index:4; + z-index: 4; } -#modal-cover{ +#modal-cover { position: absolute; - top:0px; - left:0px; - bottom:0px; - right:0px; - background:rgba(0,0,0,.7); + top: 0px; + left: 0px; + bottom: 0px; + right: 0px; + background: rgba(0, 0, 0, 0.7); z-index: 2; - display:none; + display: none; } -#cancel-button{ +#cancel-button { color: #555; text-decoration: underline; margin-right: 15px; -} \ No newline at end of file +} diff --git a/assets/css/mwdk-download.css b/assets/css/mwdk-download.css index 88383c4..e9ae3c9 100644 --- a/assets/css/mwdk-download.css +++ b/assets/css/mwdk-download.css @@ -19,15 +19,15 @@ body#download hr { margin: 15px 50px 0; } -body#download #cancel-button{ +body#download #cancel-button { color: #555; text-decoration: underline; } -body#download #build-commands{ +body#download #build-commands { margin: 47px; } -body#download #download_button{ - margin-right:20px; -} \ No newline at end of file +body#download #download_button { + margin-right: 20px; +} diff --git a/assets/css/mwdk-main.css b/assets/css/mwdk-main.css index bf8495b..6dda7fd 100644 --- a/assets/css/mwdk-main.css +++ b/assets/css/mwdk-main.css @@ -87,10 +87,10 @@ body { } #modalbg { - background: rgba(0,0,0,.5); - position:fixed; - top:0; - left:0; + background: rgba(0, 0, 0, 0.5); + position: fixed; + top: 0; + left: 0; display: none; z-index: 1000; width: 100%; @@ -169,30 +169,28 @@ h2 { .widget .orange { padding: 10px; font-size: 30px; - text-decoration:none; + text-decoration: none; margin-top: 10px; margin-right: 10px; display: inline-block; } -.orange -{ - background:#ff8f11; +.orange { + background: #ff8f11; background-image: -webkit-linear-gradient(top, #ffbc78, #ff8f11); background-image: -o-linear-gradient(top, #ffbc78, #ff8f11); background-image: -moz-linear-gradient(top, #ffbc78, #ff8f11); background-image: -ms-linear-gradient(top, #ffbc78, #ff8f11); - border:#ff8f11 1px solid; + border: #ff8f11 1px solid; color: #694d28; } -.orange:hover -{ - background:#ffce8c; +.orange:hover { + background: #ffce8c; background-image: -webkit-linear-gradient(top, #ff8f11, #ffbc78); background-image: -o-linear-gradient(top, #ff8f11, #ffbc78); background-image: -moz-linear-gradient(top, #ff8f11, #ffbc78); background-image: -ms-linear-gradient(top, #ff8f11, #ffbc78); - text-decoration:none; + text-decoration: none; } .edit_button { @@ -204,16 +202,16 @@ h2 { -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; - font-weight:700; - color:#694d28; + font-weight: 700; + color: #694d28; text-shadow: 1px 1px 1px rgba(256, 256, 256, 0.75); -moz-box-shadow: 1px 2px 4px #888; -webkit-box-shadow: 1px 2px 4px #888; box-shadow: 1px 2px 4px #888; font-size: 15px; - position:relative; - cursor:pointer; - display:inline-block; + position: relative; + cursor: pointer; + display: inline-block; color: #333; } diff --git a/assets/css/mwdk-player.css b/assets/css/mwdk-player.css index 99590af..e5d07ca 100644 --- a/assets/css/mwdk-player.css +++ b/assets/css/mwdk-player.css @@ -2,15 +2,15 @@ color: #fff; } -#leftbar + .widget[ng-app="materia"] { +#leftbar + .widget[ng-app='materia'] { margin-left: 300px; } -#leftbar.shrink + .widget[ng-app="materia"] { +#leftbar.shrink + .widget[ng-app='materia'] { margin-left: 120px; } -#body.player_mwdk .widget[ng-app="materia"]{ +#body.player_mwdk .widget[ng-app='materia'] { display: block; width: 100%; height: 100%; diff --git a/express.js b/express.js index f4ecac8..9921827 100644 --- a/express.js +++ b/express.js @@ -1,58 +1,64 @@ -const path = require('path'); -const fs = require('fs') -const express = require('express') -const qsets = path.join(__dirname, 'qsets'); -const yaml = require('yamljs'); -const { execSync } = require('child_process'); -const waitUntil = require('wait-until-promise').default -const hoganExpress = require('hogan-express') -const uuid = require('uuid') - -var webPackMiddleware = false; -var hasCompiled = false; +const path = require('path') +const fs = require('fs') +const express = require('express') +const qsets = path.join(__dirname, 'qsets') +const yaml = require('yamljs') +const { execSync } = require('child_process') +const waitUntil = require('wait-until-promise').default +const hoganExpress = require('hogan-express') +const uuid = require('uuid') + +var webPackMiddleware = false +var hasCompiled = false // this will call next() once webpack is ready by trying to: // 1. talk to the middlware // 2. load the widget's install.yaml from webpack's in-memory files var waitForWebpack = (app, next) => { - if(process.env.TEST_MWDK) return next(); // short circuit for tests - if(hasCompiled) return next(); // short circuit if ready - - waitUntil(() => { - // check for the middleware first - if(!webPackMiddleware){ - // search express for the webpack middleware - var found = app._router.stack.filter(mw => mw && mw.handle && mw.handle.name === 'webpackDevMiddleware') - if(found.length == 0) return false // not ready - webPackMiddleware = found[0].handle // found! - } + if (process.env.TEST_MWDK) return next() // short circuit for tests + if (hasCompiled) return next() // short circuit if ready + + waitUntil( + () => { + // check for the middleware first + if (!webPackMiddleware) { + // search express for the webpack middleware + var found = app._router.stack.filter( + mw => mw && mw.handle && mw.handle.name === 'webpackDevMiddleware' + ) + if (found.length == 0) return false // not ready + webPackMiddleware = found[0].handle // found! + } - // then check to see if we can find install.yaml - try { - getInstall() - return true - } catch(e) { - console.log("waiting for 'install.yaml' to be served by webpack") - return false - } - }, 10000, 250) - .then(() => { - hasCompiled = true // so we don't check again - return next(); - }) - .catch((error) => { - throw "MWDK couldn't locate the widget's install.yaml. Make sure you have one and webpack is processing it." - }) + // then check to see if we can find install.yaml + try { + getInstall() + return true + } catch (e) { + console.log("waiting for 'install.yaml' to be served by webpack") + return false + } + }, + 10000, + 250 + ) + .then(() => { + hasCompiled = true // so we don't check again + return next() + }) + .catch(error => { + throw "MWDK couldn't locate the widget's install.yaml. Make sure you have one and webpack is processing it." + }) } // For whatever reason, the middleware isn't availible when this class -var getWebPackMiddleWare = (app) => { - if(webPackMiddleware) return webPackMiddleware +var getWebPackMiddleWare = app => { + if (webPackMiddleware) return webPackMiddleware - var t = app._router.stack.filter((layer) => { - return layer && layer.handle && layer.handle.name === 'webpackDevMiddleware'; + var t = app._router.stack.filter(layer => { + return layer && layer.handle && layer.handle.name === 'webpackDevMiddleware' }) - if(t.length > 0){ + if (t.length > 0) { webPackMiddleware = t[0].handle return webPackMiddleware } @@ -62,9 +68,9 @@ var getWebPackMiddleWare = (app) => { var getFileFromWebpack = (file, quiet = false) => { try { // pull the specified filename out of memory - return webPackMiddleware.fileSystem.readFileSync(path.resolve('build', file)); + return webPackMiddleware.fileSystem.readFileSync(path.resolve('build', file)) } catch (e) { - if(!quiet) console.error(e) + if (!quiet) console.error(e) throw `error trying to load ${file} from widget src, reload if you just started the server` } } @@ -72,28 +78,27 @@ var getFileFromWebpack = (file, quiet = false) => { // Widget creation/management support functions var getWidgetTitle = () => { const install = getInstall() - return yaml.parse(install.toString()).general.name; -}; + return yaml.parse(install.toString()).general.name +} var getDemoQset = () => { // generate a new instance with the given ID let qset try { - if(process.env.TEST_MWDK){ + if (process.env.TEST_MWDK) { qset = fs.readFileSync(path.resolve('views', 'sample-demo.json')) - } - else{ + } else { qset = getFileFromWebpack('demo.json') } } catch (e) { - console.log(e); + console.log(e) throw "Couldn't find demo.json file for qset data" } return performQSetSubsitutions(qset.toString()) } -var performQSetSubsitutions = (qset) => { +var performQSetSubsitutions = qset => { console.log('media and ids inserted into qset..') // convert media urls into usable ones qset = qset.replace(/"<%MEDIA='(.+?)'%>"/g, '"__$1__"') @@ -106,10 +111,9 @@ var performQSetSubsitutions = (qset) => { // create a widget instance data structure var createApiWidgetInstanceData = id => { - // attempt to load a previously saved instance with the given ID try { - return JSON.parse(fs.readFileSync(path.join(qsets, id+'.instance.json')).toString()); + return JSON.parse(fs.readFileSync(path.join(qsets, id + '.instance.json')).toString()) } catch (e) { console.log(`creating qset ${id}`) // console.error(e) @@ -117,61 +121,63 @@ var createApiWidgetInstanceData = id => { // generate a new instance with the given ID let qset = getDemoQset() - let widget = createApiWidgetData(id); - - return [{ - 'attempts': '-1', - 'clean_name': '', - 'close_at': '-1', - 'created_at': Math.floor(Date.now() / 1000), - 'embed_url': '', - 'height': 0, - 'id': '', - 'is_draft': true, - 'name': qset.name, - 'open_at': '-1', - 'play_url': '', - 'preview_url': '', - 'qset': { - 'version': null, - 'data': null - }, - 'user_id': '1', - 'widget': widget, - 'width': 0 - }]; -}; + let widget = createApiWidgetData(id) + + return [ + { + attempts: '-1', + clean_name: '', + close_at: '-1', + created_at: Math.floor(Date.now() / 1000), + embed_url: '', + height: 0, + id: '', + is_draft: true, + name: qset.name, + open_at: '-1', + play_url: '', + preview_url: '', + qset: { + version: null, + data: null + }, + user_id: '1', + widget: widget, + width: 0 + } + ] +} // Build a mock widget data structure -var createApiWidgetData = (id) => { - let widget = yaml.parse(getInstall().toString()); +var createApiWidgetData = id => { + let widget = yaml.parse(getInstall().toString()) //provide default values where necessary - if ( ! widget.meta_data.features) widget.meta_data.features = []; - if ( ! widget.meta_data.supported_data) widget.meta_data.features = []; + if (!widget.meta_data.features) widget.meta_data.features = [] + if (!widget.meta_data.supported_data) widget.meta_data.features = [] - widget.player = widget.files.player; - widget.creator = widget.files.creator; - widget.clean_name = getWidgetCleanName(); + widget.player = widget.files.player + widget.creator = widget.files.creator + widget.clean_name = getWidgetCleanName() // widget.dir = widget.clean_name + '/'; widget.dir = '' - widget.width = widget.general.width; - widget.height = widget.general.height; - return widget; -}; + widget.width = widget.general.width + widget.height = widget.general.height + return widget +} // run yarn build in production mode to build the widget var buildWidget = () => { - try{ + try { console.log('Building production ready widget') let output = execSync('yarn run build -- -p') - } catch(e) { + } catch (e) { console.error(e) console.log(output.toString()) - return res.send("There was an error building the widget") + return res.send('There was an error building the widget') } - let widgetData = createApiWidgetData(); + let widgetData = createApiWidgetData() let widgetPath = path.resolve('build', '_output', `${widgetData.clean_name}.wigt`) return { @@ -182,9 +188,9 @@ var buildWidget = () => { var getInstall = () => { try { - if(process.env.TEST_MWDK) return fs.readFileSync(path.resolve('views', 'sample-install.yaml')); // short circuit for tests - return getFileFromWebpack('install.yaml', true); - } catch(e) { + if (process.env.TEST_MWDK) return fs.readFileSync(path.resolve('views', 'sample-install.yaml')) // short circuit for tests + return getFileFromWebpack('install.yaml', true) + } catch (e) { console.error(e) throw "Can't find install.yaml" } @@ -192,55 +198,63 @@ var getInstall = () => { var getWidgetCleanName = () => { try { - let packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json'))); - return packageJson.materia.cleanName.toLowerCase(); - } catch(e) { + let packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json'))) + return packageJson.materia.cleanName.toLowerCase() + } catch (e) { console.error(e) throw "Can't resolve clean name from package.json!" } } // goes through the master list of default questions and filters according to a given type/types -var getAllQuestions = (type) => { - type = type.replace('Multiple%20Choice', 'MC'); - type = type.replace('Question%2FAnswer', 'QA'); - const types = type.split(','); +var getAllQuestions = type => { + type = type.replace('Multiple%20Choice', 'MC') + type = type.replace('Question%2FAnswer', 'QA') + const types = type.split(',') - const qlist = []; + const qlist = [] - const obj = JSON.parse(fs.readFileSync(path.join(__dirname, 'src', 'mwdk_questions.json')).toString()); - let i = 1; + const obj = JSON.parse( + fs.readFileSync(path.join(__dirname, 'src', 'mwdk_questions.json')).toString() + ) + let i = 1 - const qarr = obj.set; + const qarr = obj.set for (let q of Array.from(qarr)) { - q.id = i++; - if (!Array.from(types).includes(q.type)) { continue; } + q.id = i++ + if (!Array.from(types).includes(q.type)) { + continue + } qlist.push({ id: q.id, type: q.type, text: q.questions[0].text, uses: Math.round(Math.random() * 1000), created_at: Date.now() - }); + }) } - return qlist; -}; + return qlist +} // pulls a question/questions out of the master list of default questions according to specified ID/IDs -var getQuestion = (ids) => { +var getQuestion = ids => { // convert the given ids to numbers - ids = ids.map(id => +id); + ids = ids.map(id => +id) - const qlist = []; + const qlist = [] - const obj = JSON.parse(fs.readFileSync(path.join(__dirname, 'src', 'mwdk_questions.json')).toString()); - let i = 1; + const obj = JSON.parse( + fs.readFileSync(path.join(__dirname, 'src', 'mwdk_questions.json')).toString() + ) + let i = 1 - const qarr = obj.set; + const qarr = obj.set for (let q of Array.from(qarr)) { - q.id = i++; - if (!Array.from(ids).includes(+q.id)) { continue; } + q.id = i++ + if (!Array.from(ids).includes(+q.id)) { + continue + } qlist.push({ id: q.id, type: q.type, @@ -249,28 +263,29 @@ var getQuestion = (ids) => { answers: q.answers, options: q.options, assets: q.assets - }); + }) } - return qlist; -}; + return qlist +} // app is passed a reference to the webpack dev server (Express.js) -module.exports = (app) => { - +module.exports = app => { // ============= ASSETS and SETUP ======================= app.set('view engine', 'html') // set file extension to html app.set('layout', 'layout') // set layout to layout.html app.engine('html', hoganExpress) // set the layout engine for html - app.set('views', path.join(__dirname , 'views')); // set the views directory + app.set('views', path.join(__dirname, 'views')) // set the views directory // the web pack middlewere takes time to show up - app.use([/^\/$/, '/mwdk/*', '/api/*'], (req, res, next) => { waitForWebpack(app, next) }) + app.use([/^\/$/, '/mwdk/*', '/api/*'], (req, res, next) => { + waitForWebpack(app, next) + }) // allow express to parse a JSON post body that ends up in req.body.data - app.use(express.json()); // for parsing application/json - app.use(express.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded + app.use(express.json()) // for parsing application/json + app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded // serve the static files from devmateria let clientAssetsPath = require('materia-server-client-assets/path') @@ -279,9 +294,8 @@ module.exports = (app) => { app.use('/mwdk/mwdk-assets/js', express.static(path.join(__dirname, 'build'))) app.use('/mwdk/assets/', express.static(path.join(clientAssetsPath, 'dist'))) - // insert the port into the res.locals - app.use( (req, res, next) => { + app.use((req, res, next) => { // console.log(`request to ${req.url}`) res.locals.port = process.env.PORT || 8118 next() @@ -291,15 +305,15 @@ module.exports = (app) => { // Display index page app.get('/', (req, res) => { - res.locals = Object.assign(res.locals, {template: 'index', title: getWidgetTitle()}) + res.locals = Object.assign(res.locals, { template: 'index', title: getWidgetTitle() }) res.render(res.locals.template) - }); + }) // ============= MWDK ROUTES ======================= app.get('/mwdk/my-widgets', (req, res) => { res.redirect('/') - }); + }) // Match any MEDIA URLS that get build into our demo.jsons // worth noting the is converted to __dfdf__ @@ -310,210 +324,231 @@ module.exports = (app) => { }) app.get('/mwdk/media/import', (req, res) => { - res.locals = Object.assign(res.locals, { template: 'media_importer'}) + res.locals = Object.assign(res.locals, { template: 'media_importer' }) res.render(res.locals.template) }) // If asking for a media item by id, determine action based on requested type app.get('/mwdk/media/:id', (req, res) => { - const filetype = (req.params.id).match(/\.[0-9a-z]+$/i) + const filetype = req.params.id.match(/\.[0-9a-z]+$/i) // TODO: have a small library of assets for each file type and pull a random one when needed? switch (filetype[0]) { case '.mp4': - res.redirect('https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyVideo.mp4') + res.redirect( + 'https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyVideo.mp4' + ) break case '.mp3': // audio: serve up a generic .mp3 file res.sendFile(path.join(__dirname, 'assets', 'media', 'birds.mp3')) - break; + break case '.png': case '.jpg': case '.jpeg': case '.gif': default: // images: grab a random image from Lorem Picsum - res.redirect(`https://picsum.photos/800/600/?c=${req.params.id}`); - break; + res.redirect(`https://picsum.photos/800/600/?c=${req.params.id}`) + break } }) // route to list the saved qsets app.use('/mwdk/saved_qsets', (req, res) => { - const saved_qsets = {}; + const saved_qsets = {} - const files = fs.readdirSync(qsets); + const files = fs.readdirSync(qsets) for (let i in files) { const file = files[i] - if (!file.includes('instance')){ - continue; + if (!file.includes('instance')) { + continue } - const actual_path = path.join(qsets, file); - const qset_data = JSON.parse(fs.readFileSync(actual_path).toString())[0]; - saved_qsets[qset_data.id] = qset_data.name; + const actual_path = path.join(qsets, file) + const qset_data = JSON.parse(fs.readFileSync(actual_path).toString())[0] + saved_qsets[qset_data.id] = qset_data.name } - res.json(saved_qsets); - }); + res.json(saved_qsets) + }) // The play page frame that loads the widget player in an iframe app.get(['/mwdk/player/:instance?', '/mwdk/preview/:instance?'], (req, res) => { - res.locals = Object.assign(res.locals, { template: 'player_mwdk', instance: req.params.instance || 'demo'}) + res.locals = Object.assign(res.locals, { + template: 'player_mwdk', + instance: req.params.instance || 'demo' + }) res.render(res.locals.template) - }); + }) // Play Score page app.get(['/mwdk/scores/demo', '/mwdk/scores/preview/:id'], (req, res) => { - res.locals = Object.assign(res.locals, { template: 'score_mwdk'}) + res.locals = Object.assign(res.locals, { template: 'score_mwdk' }) res.render(res.locals.template) }) // The create page frame that loads the widget creator app.get('/mwdk/widgets/1-mwdk/:instance?', (req, res) => { - res.locals = Object.assign(res.locals, {template: 'creator_mwdk', instance: req.params.instance || null}) + res.locals = Object.assign(res.locals, { + template: 'creator_mwdk', + instance: req.params.instance || null + }) res.render(res.locals.template) - }); + }) // Show the package options app.get('/mwdk/package', (req, res) => { - res.locals = Object.assign(res.locals, {template: 'download'}) + res.locals = Object.assign(res.locals, { template: 'download' }) res.render(res.locals.template) }) // Build and download the widget file app.get('/mwdk/download', (req, res) => { let { widgetPath, widgetData } = buildWidget() - res.set('Content-Disposition', `attachment; filename=${widgetData.clean_name}.wigt`); - res.send(fs.readFileSync(widgetPath)); - }); + res.set('Content-Disposition', `attachment; filename=${widgetData.clean_name}.wigt`) + res.send(fs.readFileSync(widgetPath)) + }) // Question importer for creator app.get('/mwdk/questions/import/', (req, res) => { - res.locals = Object.assign(res.locals, {template: 'question_importer'}) + res.locals = Object.assign(res.locals, { template: 'question_importer' }) res.render(res.locals.template) - }); + }) // A default preview blocked template if a widget's creator doesnt have one // @TODO im not sure this is used? app.get('/mwdk/preview_blocked/:instance?', (req, res) => { - res.locals = Object.assign(res.locals, {template: 'preview_blocked', instance: req.params.instance || 'demo'}) + res.locals = Object.assign(res.locals, { + template: 'preview_blocked', + instance: req.params.instance || 'demo' + }) res.render(res.locals.template) - }); + }) app.get('/mwdk/install', (req, res) => { - res.write('
');
+		res.write('
')
 		// Find the docker-compose container for materia-web
 		// 1. lists all containers
 		// 2. filter for materia-web image and named xxxx_phpfpm_1 name
 		// 3. pick the first line
 		// 4. pick the container name
-		let targetImage = execSync('docker ps -a --format "{{.Image}} {{.Names}}" | grep -e ".*materia-web-base:.* .*phpfpm_\\d" | head -n 1 | cut -d" " -f2');
-		if(!targetImage){
+		let targetImage = execSync(
+			'docker ps -a --format "{{.Image}} {{.Names}}" | grep -e ".*materia-web-base:.* .*phpfpm_\\d" | head -n 1 | cut -d" " -f2'
+		)
+		if (!targetImage) {
 			throw "MWDK Couldn't find a docker container using a 'materia-web' image named 'phpfpm'."
 		}
-		targetImage = targetImage.toString().trim();
-		res.write(`> Using Docker image '${targetImage}' to install widgets
`); + targetImage = targetImage.toString().trim() + res.write(`> Using Docker image '${targetImage}' to install widgets
`) // get the image information - let containerInfo = execSync(`docker inspect ${targetImage}`); - containerInfo = JSON.parse(containerInfo.toString()); + let containerInfo = execSync(`docker inspect ${targetImage}`) + containerInfo = JSON.parse(containerInfo.toString()) // Find mounted volume that will tell us where materia is on the host system let found = containerInfo[0].Mounts.filter(m => m.Destination === '/var/www/html') - if(!found){ - res.write(`

Cant Find Materia

`); + if (!found) { + res.write(`

Cant Find Materia

`) throw `MWDK Couldn't find the Materia mount on the host system'` } - let materiaPath = found[0].Source; + let materiaPath = found[0].Source let serverWidgetPath = `${materiaPath}/fuel/app/tmp/widget_packages` // make sure the dir exists - if(!fs.existsSync(serverWidgetPath)){ - fs.mkdirSync(serverWidgetPath); + if (!fs.existsSync(serverWidgetPath)) { + fs.mkdirSync(serverWidgetPath) } // Build! - res.write(`> Building widget
`); + res.write(`> Building widget
`) let { widgetPath, widgetData } = buildWidget() // create a file name with a timestamp in it - const filename = `${widgetData.clean_name}-${new Date().getTime()}.wigt`; + const filename = `${widgetData.clean_name}-${new Date().getTime()}.wigt` // get the widget I just built let widgetPacket = fs.readFileSync(widgetPath) // write the built widget to that path let target = path.join(serverWidgetPath, filename) - res.write(`> Writing to ${target}
`); - fs.writeFileSync(target, widgetPacket); + res.write(`> Writing to ${target}
`) + fs.writeFileSync(target, widgetPacket) // run the install command - res.write(`> Running run_widgets_install.sh script
`); - let installResult = execSync(`cd ${materiaPath}/docker/ && ./run_widgets_install.sh ${filename}`); - installResult = installResult.toString(); - res.write(installResult.replace("\n", "
")); - console.log(installResult); + res.write(`> Running run_widgets_install.sh script
`) + let installResult = execSync( + `cd ${materiaPath}/docker/ && ./run_widgets_install.sh ${filename}` + ) + installResult = installResult.toString() + res.write(installResult.replace('\n', '
')) + console.log(installResult) // search for success in the output - const match = installResult.match(/Widget installed\:\ ([A-Za-z0-9\-\/]+)/); + const match = installResult.match(/Widget installed\:\ ([A-Za-z0-9\-\/]+)/) - res.write(""); - if(match && match[1]) { - res.write("

SUCCESS!

"); - } - else{ - res.write("

Something failed!

"); + res.write('') + if (match && match[1]) { + res.write('

SUCCESS!

') + } else { + res.write('

Something failed!

') } - res.write(''); + res.write( + '' + ) res.end() - }); + }) // ============= MOCK API ROUTES ======================= // API endpoint for getting the widget instance data app.use('/api/json/widget_instances_get', (req, res) => { - const id = JSON.parse(req.body.data)[0][0]; - res.json(createApiWidgetInstanceData(id)); - }); + const id = JSON.parse(req.body.data)[0][0] + res.json(createApiWidgetInstanceData(id)) + }) app.use('/api/json/widget_publish_perms_verify', (req, res) => { - res.json(true); + res.json(true) }) app.use('/api/json/widgets_get', (req, res) => { - const id = JSON.parse(req.body.data); - res.json([createApiWidgetData(id)]); - }); + const id = JSON.parse(req.body.data) + res.json([createApiWidgetData(id)]) + }) app.use('/api/json/question_set_get', (req, res) => { - res.set('Content-Type', 'application/json') // load instance, fallback to demo try { - const id = JSON.parse(req.body.data)[0]; - let qset = fs.readFileSync(path.join(qsets, id+'.json')).toString() + const id = JSON.parse(req.body.data)[0] + let qset = fs.readFileSync(path.join(qsets, id + '.json')).toString() qset = performQSetSubsitutions(qset) qset = JSON.stringify(qset) - res.send(qset.toString()); + res.send(qset.toString()) } catch (e) { - res.json(getDemoQset().qset); + res.json(getDemoQset().qset) } - }); + }) - app.use(['/api/json/session_play_verify', '/api/json/session_author_verify'] , (req, res) => res.send('true')); + app.use(['/api/json/session_play_verify', '/api/json/session_author_verify'], (req, res) => + res.send('true') + ) app.use('/api/json/play_logs_save', (req, res) => { - const logs = JSON.parse(req.body.data)[1]; - console.log("========== Play Logs Received ==========\r\n", logs, "\r\n============END PLAY LOGS================"); - res.json({score: 0}); - }); + const logs = JSON.parse(req.body.data)[1] + console.log( + '========== Play Logs Received ==========\r\n', + logs, + '\r\n============END PLAY LOGS================' + ) + res.json({ score: 0 }) + }) // api mock for saving widget instances // creates files in our qset directory (probably should use a better thing)session app.use(['/api/json/widget_instance_new', '/api/json/widget_instance_update'], (req, res) => { - const data = JSON.parse(req.body.data); + const data = JSON.parse(req.body.data) // sweep through the qset items and make sure there aren't any nonstandard question properties const standard_props = [ @@ -526,44 +561,49 @@ module.exports = (app) => { 'options', 'assets', 'items' //some widgets double-nest 'items' - ]; + ] - const nonstandard_props = []; + const nonstandard_props = [] for (let index in data[2].data.items) { - const item = data[2].data.items[index]; + const item = data[2].data.items[index] for (let prop in item) { if (!Array.from(standard_props).includes(prop)) { - nonstandard_props.push(`"${prop}"`); - console.log(`Nonstandard property found in qset: ${prop}`); + nonstandard_props.push(`"${prop}"`) + console.log(`Nonstandard property found in qset: ${prop}`) } } } - const id = data[0] || new Date().getTime(); - fs.writeFileSync(path.join(qsets, id + '.json'), JSON.stringify(data[2])); + const id = data[0] || new Date().getTime() + fs.writeFileSync(path.join(qsets, id + '.json'), JSON.stringify(data[2])) - const instance = createApiWidgetInstanceData(data[0])[0]; - instance.id = id; - instance.name = data[1]; + const instance = createApiWidgetInstanceData(data[0])[0] + instance.id = id + instance.name = data[1] - fs.writeFileSync(path.join(qsets, id + '.instance.json'), JSON.stringify([instance])); + fs.writeFileSync(path.join(qsets, id + '.instance.json'), JSON.stringify([instance])) // send a warning back to the creator if any nonstandard question properties were detected if (nonstandard_props.length > 0) { - const plurals = nonstandard_props.length > 1 ? ['properties', 'were'] : ['property', 'was']; - console.log ('Warning: Nonstandard qset item ' + - plurals[0] + ' ' + nonstandard_props.join(', ') + ' ' + - plurals[1]); + const plurals = nonstandard_props.length > 1 ? ['properties', 'were'] : ['property', 'was'] + console.log( + 'Warning: Nonstandard qset item ' + + plurals[0] + + ' ' + + nonstandard_props.join(', ') + + ' ' + + plurals[1] + ) } - res.json(instance); - }); + res.json(instance) + }) // API mock for getting questions for the question importer app.use('/api/json/questions_get/', (req, res) => { - const given = JSON.parse(req.body.data); + const given = JSON.parse(req.body.data) let questions if (given[0]) { // we selected specific questions @@ -574,6 +614,5 @@ module.exports = (app) => { } res.json(questions) - }); - + }) } diff --git a/package.json b/package.json index 0bf1c07..a6a33a1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "echo 'No tests yet'", "start": "env TEST_MDK=true webpack-dev-server --open --config webpack.config.widget.js", "postinstall": "yarn build", - "prettier:run": "prettier --write 'src/*.js' --write 'assets/**/*.{js,css}' --write '*.js", + "prettier:run": "prettier --write 'src/*.js' --write 'assets/**/*.{js,css}' --write '*.js'", "clientAssets:link": "cd ../materia-server-client-assets && yarn link && cd - && yarn link materia-server-client-assets" }, "materia": { diff --git a/src/mwdk.package.js b/src/mwdk.package.js index bfb32dc..153436a 100644 --- a/src/mwdk.package.js +++ b/src/mwdk.package.js @@ -1,34 +1,33 @@ Namespace('MWDK').Package = (() => { - var showPackageDownload = () => { - var embed; - embed = document.createElement('iframe'); - embed.id = 'mwdk_dialog'; - embed.setAttribute('frameborder', 0); - embed.setAttribute('src', '/mwdk/package'); - document.getElementById('modalbg').appendChild(embed); - document.getElementById('modalbg').classList.add('visible'); - }; + var embed + embed = document.createElement('iframe') + embed.id = 'mwdk_dialog' + embed.setAttribute('frameborder', 0) + embed.setAttribute('src', '/mwdk/package') + document.getElementById('modalbg').appendChild(embed) + document.getElementById('modalbg').classList.add('visible') + } var closeDialog = () => { - var dialog; - dialog = document.getElementById('mwdk_dialog'); - dialog.parentNode.removeChild(dialog); - document.getElementById('modalbg').classList.remove('visible'); - }; + var dialog + dialog = document.getElementById('mwdk_dialog') + dialog.parentNode.removeChild(dialog) + document.getElementById('modalbg').classList.remove('visible') + } - var build = (url) => { - window.location.href = url; - closeDialog(); - }; + var build = url => { + window.location.href = url + closeDialog() + } var cancel = () => { - closeDialog(); - }; + closeDialog() + } return { build: build, cancel: cancel, showPackageDownload: showPackageDownload - }; -})(); + } +})() diff --git a/src/mwdk.splash.js b/src/mwdk.splash.js index 658891f..3dfa794 100644 --- a/src/mwdk.splash.js +++ b/src/mwdk.splash.js @@ -1,20 +1,24 @@ window.API_LINK = '' fetch('mwdk/saved_qsets') -.then(res => res.json()) -.then(data => { - const qsets = document.getElementById('qsets') + .then(res => res.json()) + .then(data => { + const qsets = document.getElementById('qsets') - for (let id in data) { - let name = data[id] - let newOption = document.createElement("option") - newOption.text = name - newOption.value = id - qsets.add(newOption) - } + for (let id in data) { + let name = data[id] + let newOption = document.createElement('option') + newOption.text = name + newOption.value = id + qsets.add(newOption) + } - qsets.onchange = (e) => { - document.getElementById('player_button').setAttribute('href', "/mwdk/player/" + e.target.value) - document.getElementById('creator_button').setAttribute('href', "/mwdk/widgets/1-mwdk/#" + e.target.value) - } -}) + qsets.onchange = e => { + document + .getElementById('player_button') + .setAttribute('href', '/mwdk/player/' + e.target.value) + document + .getElementById('creator_button') + .setAttribute('href', '/mwdk/widgets/1-mwdk/#' + e.target.value) + } + }) diff --git a/webpack-generate-widget-hash.js b/webpack-generate-widget-hash.js index 61086d0..48b43ad 100644 --- a/webpack-generate-widget-hash.js +++ b/webpack-generate-widget-hash.js @@ -5,21 +5,31 @@ const execSync = require('child_process').execSync function GenerateWidgetHash(options) { const apply = function(compiler) { compiler.plugin('emit', function(compilation, callback) { - // if widget isnt in options or it isnt in the output, just warn and exit - if (typeof options.widget == 'undefined' || typeof compilation.assets[options.widget] == 'undefined') { + if ( + typeof options.widget == 'undefined' || + typeof compilation.assets[options.widget] == 'undefined' + ) { console.warn('Widget Hash generator couldnt locate ' + options.widget) callback() return } - const wigtData = compilation.assets[options.widget].source() // calculate hashes based on the wigt file - var hashmd5 = crypto.createHash('md5').update(wigtData).digest('hex') - var hashSha1 = crypto.createHash('sha1').update(wigtData).digest('hex') - var hashsha256 = crypto.createHash('sha256').update(wigtData).digest('hex') + var hashmd5 = crypto + .createHash('md5') + .update(wigtData) + .digest('hex') + var hashSha1 = crypto + .createHash('sha1') + .update(wigtData) + .digest('hex') + var hashsha256 = crypto + .createHash('sha256') + .update(wigtData) + .digest('hex') // get some build environment information var date = new Date() diff --git a/webpack-widget.js b/webpack-widget.js index d2b4a7f..64f6dd7 100644 --- a/webpack-widget.js +++ b/webpack-widget.js @@ -5,16 +5,17 @@ const CleanWebpackPlugin = require('clean-webpack-plugin') const CopyPlugin = require('copy-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin') const ZipPlugin = require('zip-webpack-plugin') -const MateriaDevServer = require('./express'); +const MateriaDevServer = require('./express') const GenerateWidgetHash = require('./webpack-generate-widget-hash') - // creators and players may reference materia core files directly // To do so rather than hard-coding the actual location of those files // the build process will replace those references with the current relative paths to those files const packagedJSPath = 'src=\\"../../../js/$3\\"' const devServerJSPath = 'src=\\"/mwdk/assets/js/$3\\"' -const isRunningDevServer = process.argv.find((v) => {return v.includes('webpack-dev-server')} ) +const isRunningDevServer = process.argv.find(v => { + return v.includes('webpack-dev-server') +}) const replaceTarget = isRunningDevServer ? devServerJSPath : packagedJSPath // common paths used here @@ -35,42 +36,30 @@ const browserList = [ ] // when copying files, always ignore these -const copyIgnore = [ - '.gitkeep' -] +const copyIgnore = ['.gitkeep'] // regex rules needed for replacing scripts loaded from materia const materiaJSReplacements = [ - { search: /src=(\\?("|')?)(materia.enginecore.js)(\\?("|')?)/g, replace: replaceTarget }, - { search: /src=(\\?("|')?)(materia.scorecore.js)(\\?("|')?)/g, replace: replaceTarget }, + { search: /src=(\\?("|')?)(materia.enginecore.js)(\\?("|')?)/g, replace: replaceTarget }, + { search: /src=(\\?("|')?)(materia.scorecore.js)(\\?("|')?)/g, replace: replaceTarget }, { search: /src=(\\?("|')?)(materia.creatorcore.js)(\\?("|')?)/g, replace: replaceTarget }, - { search: /src=(\\?("|')?)(materia.scorecore.js)(\\?("|')?)/g, replace: replaceTarget }, -]; + { search: /src=(\\?("|')?)(materia.scorecore.js)(\\?("|')?)/g, replace: replaceTarget } +] // webpack entries const getDefaultEntries = () => ({ - 'creator.js': [ - `${srcPath}creator.coffee` - ], - 'player.js': [ - `${srcPath}player.coffee` - ], - 'creator.css': [ - `${srcPath}creator.html`, - `${srcPath}creator.scss` - ], - 'player.css': [ - `${srcPath}player.html`, - `${srcPath}player.scss` - ] + 'creator.js': [`${srcPath}creator.coffee`], + 'player.js': [`${srcPath}player.coffee`], + 'creator.css': [`${srcPath}creator.html`, `${srcPath}creator.scss`], + 'player.css': [`${srcPath}player.html`, `${srcPath}player.scss`] }) // Load the materia configuration settings from the package.json file const configFromPackage = () => { - let packagePath = path.join(process.cwd(), 'package.json') - let packageJson = require(packagePath) + let packagePath = path.join(process.cwd(), 'package.json') + let packageJson = require(packagePath) return { - cleanName : packageJson.materia.cleanName.toLowerCase(), + cleanName: packageJson.materia.cleanName.toLowerCase() } } @@ -104,12 +93,12 @@ const getDefaultCopyList = () => { { flatten: true, from: `${srcPath}demo.json`, - to: `${outputPath}demo.json`, + to: `${outputPath}demo.json` }, { flatten: true, from: `${srcPath}install.yaml`, - to: outputPath, + to: outputPath }, { from: `${srcPath}_icons`, @@ -224,9 +213,9 @@ const getDefaultRules = () => ({ loader: 'postcss-loader', options: { // add autoprefixer, tell it what to prefix - plugins: [require('autoprefixer')({browsers: browserList})] + plugins: [require('autoprefixer')({ browsers: browserList })] } - }, + } ] }) }, @@ -243,7 +232,7 @@ const getDefaultRules = () => ({ loader: 'postcss-loader', options: { // add autoprefixer, tell it what to prefix - plugins: [require('autoprefixer')({browsers: browserList})] + plugins: [require('autoprefixer')({ browsers: browserList })] } }, 'sass-loader' @@ -280,17 +269,17 @@ const getLegacyWidgetBuildConfig = (config = {}) => { let cfg = combineConfig(config) return { - stats: {children: false}, + stats: { children: false }, devServer: { contentBase: outputPath, - headers:{ + headers: { // allow iframes to talk to their parent containers 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept', + 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' }, port: process.env.PORT || 8118, setup: MateriaDevServer, - stats: {children: false}, + stats: { children: false } }, // These are the default js and css files @@ -303,14 +292,14 @@ const getLegacyWidgetBuildConfig = (config = {}) => { publicPath: '' }, - module: {rules: cfg.moduleRules}, + module: { rules: cfg.moduleRules }, plugins: [ // clear the build directory new CleanWebpackPlugin(), // copy all the common resources to the build directory - new CopyPlugin(cfg.copyList, {ignore: copyIgnore}), + new CopyPlugin(cfg.copyList, { ignore: copyIgnore }), // extract css from the webpack output - new ExtractTextPlugin({filename: '[name]'}), + new ExtractTextPlugin({ filename: '[name]' }), // zip everything in the build path to zip dir new ZipPlugin({ path: `${outputPath}_output`, @@ -322,7 +311,7 @@ const getLegacyWidgetBuildConfig = (config = {}) => { output: `_output/${cfg.cleanName}-build-info.yml` }) ] - }; + } } module.exports = { diff --git a/webpack.config.js b/webpack.config.js index 1b9ffc0..522c9a2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,18 +3,14 @@ const CleanWebpackPlugin = require('clean-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin') const CopyPlugin = require('copy-webpack-plugin') -const mwdkSrcPath = path.resolve(__dirname, 'src'); -const buildPath = path.resolve(__dirname, 'build') + path.sep +const mwdkSrcPath = path.resolve(__dirname, 'src') +const buildPath = path.resolve(__dirname, 'build') + path.sep module.exports = [ { entry: { - 'mwdk-splash.js': [ - path.join(mwdkSrcPath, 'mwdk.splash.js') - ], - 'mwdk-package.js': [ - path.join(mwdkSrcPath, 'mwdk.package.js'), - ], + 'mwdk-splash.js': [path.join(mwdkSrcPath, 'mwdk.splash.js')], + 'mwdk-package.js': [path.join(mwdkSrcPath, 'mwdk.package.js')] }, // write files to the outputPath (default = ./build) using the object keys from 'entry' above @@ -37,7 +33,7 @@ module.exports = [ plugins: [ new CleanWebpackPlugin(), - new ExtractTextPlugin({filename: '[name]'}), + new ExtractTextPlugin({ filename: '[name]' }), new CopyPlugin([ { from: path.resolve(__dirname, 'assets', 'img'), @@ -46,7 +42,7 @@ module.exports = [ } ]) ] - }, + } // this used to be here to enable a single webpack to build // both MSCA and this project at the same time // I think it's less usefull now that npm packages come with pre-built assets