Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor enhancements #801

Merged
merged 10 commits into from
Apr 27, 2022
Merged
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ npm i
npm link
```

In case the above doesn't work use:

```shell
yo PATH/TO/generator-exist
```

from inside the directory where you want to run the local copy of the generator.

## Using the Generator

Then generate your new project: Create a new project folder and navigate to it in you CLI.
Expand Down
4 changes: 2 additions & 2 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ module.exports = class extends Generator {
})

this.fs.copyTpl(
this.templatePath('xq/view.xql'),
this.destinationPath('modules/view.xql'), {
this.templatePath('xq/view.xq'),
this.destinationPath('modules/view.xq'), {
short: this.props.short,
defcoll: this.props.defcoll,
defuri: this.props.defuri,
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 data-template="config:app-title">Generated page</h1>
</div>
<div class="row">
<div class="col-md-6">
<p>The page template uses the <a href="http://twitter.github.com/bootstrap/">Bootstrap</a> CSS library for the page layout.</p>
<p>The page template uses the <a href="https://github.com/twbs/bootstrap">Bootstrap</a> CSS library for the page layout.</p>
</div>
<div class="col-md-6">
<div data-template="app:test" />
Expand Down
52 changes: 32 additions & 20 deletions generators/app/templates/specs/xqs/xqSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const Mocha = require('mocha')
const http = require('http')
const expect = require('chai').expect
const xmldoc = require('xmldoc')


// Dynamically generate a mocha testsuite for xqsuite tests. Requires its own process, hence && in package.json
let Test = Mocha.Test
Expand All @@ -22,31 +24,41 @@ http.get(url, (res) => {

// called when the complete response is received.
res.on('end', () => {
let xqsReport = JSON.parse(data)
let xqsPkg = xqsReport.testsuite.package
let xqstCount = xqsReport.testsuite.tests
let xqstCase = xqsReport.testsuite.testcase
// NOTE(DP): XQTS errors on testsuite, will be returned as application/xml
// The initial check will display the XQTS error, and run the test suite otherwise
// see #800
if (res.headers['content-type'].includes("application/json")) {
let xqsReport = JSON.parse(data)
let xqsPkg = xqsReport.testsuite.package
let xqstCount = xqsReport.testsuite.tests
let xqstCase = xqsReport.testsuite.testcase

// TODO: get rid of first "0 passing message"
// TODO(DP): get rid of first "0 passing message"

let mochaInstance = new Mocha()
let mochaInstance = new Mocha()

if (Array.isArray(xqsReport.testsuite)) {
let xqsSuites = xqsReport.testsuite
console.warn('support for multiple testsuites per run is experimental')
xqsSuites.forEach((entry) => {
xqsTests(mochaInstance, entry.package, entry.tests, entry.testcase)
if (Array.isArray(xqsReport.testsuite)) {
let xqsSuites = xqsReport.testsuite
console.warn('support for multiple testsuites per run is experimental')
xqsSuites.forEach((entry) => {
xqsTests(mochaInstance, entry.package, entry.tests, entry.testcase)
})
} else {
xqsTests(mochaInstance, xqsPkg, xqstCount, xqstCase)
}
// enable repeated runs
// see https://github.com/mochajs/mocha/issues/995
// see https://mochajs.org/api/mocha#unloadFiles
let suiteRun = mochaInstance.cleanReferencesAfterRun(true).run()
process.on('exit', () => {
process.exit(suiteRun.stats.failures > 0)
})
} else {
xqsTests(mochaInstance, xqsPkg, xqstCount, xqstCase)
}
// enable repeated runs
// see https://github.com/mochajs/mocha/issues/995
// see https://mochajs.org/api/mocha#unloadFiles
let suiteRun = mochaInstance.cleanReferencesAfterRun(true).run()
process.on('exit', () => {
process.exit(suiteRun.stats.failures > 0)
})
else {
try { let doc = new xmldoc.XmlDocument(data)
throw new Error(doc.childNamed("message").val) }
catch (e) { console.log(e.message) }
}
})
}).on('error', (err) => {
console.log('Error: ', err.message)
Expand Down
10 changes: 5 additions & 5 deletions generators/app/templates/xq/admin/controller.xq
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ return
</dispatch>

else if (ends-with($exist:resource, ".html")) then
(: the html page is run through view.xql to expand templates :)
(: the html page is run through view.xq to expand templates :)
if (request:get-attribute("org.exist-db.mysec.user")) then
(: secured area checks user status :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/../modules/view.xql">
<forward url="{$exist:controller}/../modules/view.xq">
<set-attribute name="isAdmin" value="true"/>
<set-attribute name="$exist:prefix" value="{$exist:prefix}"/>
<set-attribute name="$exist:controller" value="{$exist:controller}"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/../error-page.html" method="get"/>
<forward url="{$exist:controller}/../modules/view.xql"/>
<forward url="{$exist:controller}/../modules/view.xq"/>
</error-handler>
</dispatch>
else
Expand All @@ -52,14 +52,14 @@ return
<forward url="{$exist:controller}/security.html"/>
<!-- This send the page through the templating process -->
<view>
<forward url="{$exist:controller}/../modules/view.xql">
<forward url="{$exist:controller}/../modules/view.xq">
<set-attribute name="$exist:prefix" value="{$exist:prefix}"/>
<set-attribute name="$exist:controller" value="{$exist:controller}"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/../error-page.html" method="get"/>
<forward url="{$exist:controller}/../modules/view.xql"/>
<forward url="{$exist:controller}/../modules/view.xq"/>
</error-handler>
</dispatch>
else if (starts-with($exist:path, "/resources")) then
Expand Down
6 changes: 3 additions & 3 deletions generators/app/templates/xq/controller.xq
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ if ($exist:path eq '') then
</dispatch>

else if (ends-with($exist:resource, ".html")) then (
(: the html page is run through view.xql to expand templates :)
(: the html page is run through view.xq to expand templates :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
<forward url="{$exist:controller}/modules/view.xq"/>
</view>
<error-handler>
<forward url="{$exist:controller}/error-page.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
<forward url="{$exist:controller}/modules/view.xq"/>
</error-handler>
</dispatch>)
else
Expand Down
Loading