progressively-enhance-web-components 1.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -3
- package/CONFIGURATION.md +16 -0
- package/README.md +11 -185
- package/USAGE.md +300 -0
- package/package.json +20 -14
- package/progressively-enhance-web-components.js +447 -84
- package/.github/workflows/ci.yml +0 -18
- package/renovate.json +0 -9
- package/sampleApps/express/browser.js +0 -23
- package/sampleApps/express/mvc/routes.js +0 -17
- package/sampleApps/express/mvc/views/index.html +0 -5
- package/sampleApps/express/mvc/views/layouts/main.html +0 -49
- package/sampleApps/express/mvc/views/pageWithForm.html +0 -21
- package/sampleApps/express/mvc/views/secondPage.html +0 -5
- package/sampleApps/express/package-lock.json +0 -1981
- package/sampleApps/express/package.json +0 -13
- package/sampleApps/express/server.js +0 -53
- package/test/test.js +0 -39
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra')
|
|
2
|
-
|
|
3
|
-
// load progressively-enhance-web-components.js
|
|
4
|
-
const editedFiles = require('../../progressively-enhance-web-components')({
|
|
5
|
-
templatesDir: './mvc/views'
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
// copy unmodified templates to a modified templates directory
|
|
9
|
-
fs.copySync('mvc/views', 'mvc/.preprocessed_views')
|
|
10
|
-
|
|
11
|
-
// update the relevant templates
|
|
12
|
-
for (const file in editedFiles) {
|
|
13
|
-
fs.writeFileSync(file.replace('mvc/views', 'mvc/.preprocessed_views'), editedFiles[file])
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// configure express
|
|
17
|
-
const path = require('path')
|
|
18
|
-
const express = require('express')
|
|
19
|
-
const app = express()
|
|
20
|
-
app.use(require('body-parser').urlencoded({ extended: true })) // populates req.body on requests
|
|
21
|
-
app.engine('html', require('teddy').__express) // set teddy as view engine that will load html files
|
|
22
|
-
app.set('views', 'mvc/.preprocessed_views') // set template dir
|
|
23
|
-
app.set('view engine', 'html') // set teddy as default view engine
|
|
24
|
-
if (!fs.existsSync('public')) fs.mkdirSync('public') // make the public folder if it does not exist
|
|
25
|
-
app.use(express.static('public')) // make public folder serve static files
|
|
26
|
-
|
|
27
|
-
// load express routes
|
|
28
|
-
require('./mvc/routes')(app)
|
|
29
|
-
|
|
30
|
-
// bundle frontend js
|
|
31
|
-
const webpack = require('webpack')
|
|
32
|
-
const webpackConfig = {
|
|
33
|
-
mode: 'production',
|
|
34
|
-
entry: './browser.js',
|
|
35
|
-
output: {
|
|
36
|
-
filename: 'bundle.js',
|
|
37
|
-
path: path.resolve(__dirname, 'public'),
|
|
38
|
-
libraryTarget: 'umd'
|
|
39
|
-
},
|
|
40
|
-
devtool: 'source-map'
|
|
41
|
-
}
|
|
42
|
-
const compiler = webpack(webpackConfig)
|
|
43
|
-
compiler.run((err, stats) => {
|
|
44
|
-
if (err || stats.hasErrors()) {
|
|
45
|
-
console.error('Webpack build failed:', err || stats.toJson().errors)
|
|
46
|
-
} else {
|
|
47
|
-
// start express server
|
|
48
|
-
const port = 3000
|
|
49
|
-
app.listen(port, () => {
|
|
50
|
-
console.log(`🎧 express sample app server is running on http://localhost:${port}`)
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
})
|
package/test/test.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
const assert = require('assert')
|
|
3
|
-
const { exec } = require('child_process')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const sampleAppDir = path.join(__dirname, '..', 'sampleApps', 'express')
|
|
7
|
-
|
|
8
|
-
before(async function () {
|
|
9
|
-
await new Promise((resolve, reject) => {
|
|
10
|
-
const serverProcess = exec('npm start', { cwd: sampleAppDir })
|
|
11
|
-
serverProcess.stdout.on('data', (data) => {
|
|
12
|
-
if (data.toString().includes('express sample app server is running')) resolve()
|
|
13
|
-
})
|
|
14
|
-
serverProcess.stderr.on('data', (data) => {
|
|
15
|
-
console.error(data.toString())
|
|
16
|
-
console.error('Make sure to `npm ci` in the sampleApp/express directory first!')
|
|
17
|
-
})
|
|
18
|
-
serverProcess.on('error', (error) => reject(error))
|
|
19
|
-
this.serverProcess = serverProcess
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
after(async function () {
|
|
24
|
-
if (this.serverProcess) this.serverProcess.kill()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('progressively-enhance-web-components tests', function () {
|
|
28
|
-
it('should progressively enhance the <word-count> invocation in the sample app', async function () {
|
|
29
|
-
const filePath = path.join(sampleAppDir, 'mvc', '.preprocessed_views', 'pageWithForm.html')
|
|
30
|
-
const fileContent = fs.readFileSync(filePath, 'utf8')
|
|
31
|
-
assert(fileContent.includes(`<word-count text="Once upon a time... " elid="story">
|
|
32
|
-
<div>
|
|
33
|
-
<textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
|
|
34
|
-
<span class="word-count"></span>
|
|
35
|
-
</div>
|
|
36
|
-
<p slot="description">Type your story in the box above!</p>
|
|
37
|
-
</word-count>`), 'Expected markup not found')
|
|
38
|
-
})
|
|
39
|
-
})
|