Skip to content

Commit

Permalink
Merge pull request #120 from line-o/next-release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
line-o authored Oct 31, 2020
2 parents 16d8c31 + e71bbcd commit 7f6e130
Show file tree
Hide file tree
Showing 12 changed files with 687 additions and 398 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

Expand All @@ -28,3 +25,4 @@ node_modules

dev
.idea
.vscode
252 changes: 133 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
`gulp deploy` will store all files in the ```build``` directory to
**/db/apps/myapp** collection in eXist.


```js
const gulp = require('gulp'),
exist = require('@existdb/gulp-exist')
Expand All @@ -19,17 +18,19 @@ const gulp = require('gulp'),
const connectionOptions = {
basic_auth: {
user: "admin",
pass: "****************"
pass: ""
}
}

const exClient = exist.createClient(connectionOptions)

// send all
gulp.task('deploy', function() {
// deploy all
function deploy () {
return gulp.src('**/*', {cwd: 'build'})
.pipe(exClient.dest({target: '/db/apps/myapp/'});
})
.pipe(exClient.dest({target: '/db/apps/myapp/'})
}

exports.default = deploy
```
NOTE: Non-existing collections and sub-folders will be created automatically.
Expand Down Expand Up @@ -67,14 +68,34 @@ Default: `'/exist/xmlrpc'`
##### basic_auth
*Required*
The credentials used to authenticate requests.
What you can and cannot do depends on the permissions
this user has.
Type: `Object`
Default: ```{ user: 'guest', pass: 'guest' }```
Default:
```js
{ user: 'guest', pass: 'guest' }
```
##### secure
Use HTTPS to connect to the database instance.
Needs a valid certificate installed in the keystore of
exist.
Type: `Boolean`
Default: `false`
#### Example
```js
var exClient = exist.createClient()
const exClient = exist.createClient({
host: "my.server",
secure: true,
port: 443,
basic_auth: { user: "app", pass: "1 handmade eclectic eclaire" }
})
```
### existClient.dest(options)
Expand Down Expand Up @@ -120,15 +141,26 @@ Default: `{}`
#### Example
```js
const exClient = exist.createClient(connectionOptions)
const { src } = require('gulp')
const { createClient } = require('@existdb/gulp-exist')

gulp.task('deploy', function() {
return gulp.src('**/*', {cwd: 'build'})
.pipe(exClient.dest({
// override defaults
const exist = createClient({
basic_auth: {
user: 'admin',
pass: ''
}
})

function deployWithPermissions () {
return src('**/*', {cwd: '.'})
.pipe(exist.dest({
target: '/db/apps/myapp/',
permissions: { 'controller.xql': 'rwxr-xr-x' }
});
})
}))
}

exports.default = deployWithPermissions
```
### existClient.newer(options)
Expand All @@ -146,28 +178,28 @@ Which collection to compare the local files to.
Only upload modified files.
```js
const gulp = require('gulp'),
exist = require('@existdb/gulp-exist')
const { src } = require('gulp')
const { createClient } = require('@existdb/gulp-exist')

// override defaults
const connectionOptions = {
// override some default connection options
const exist = createClient({
basic_auth: {
user: 'admin',
pass: '****************'
pass: ''
}
}
})

const exClient = exist.createClient(connectionOptions)
const targetOptions = {
target: '/db/apps/myapp/', // the collection to write
html5AsBinary: true // upload HTML5 templates as binary
const target = '/db/apps/myapp/' // the collection to write to
const html5AsBinary = true // upload HTML5 templates as binary


function deployNewer () {
return src('**/*', {cwd: '.'})
.pipe(exist.newer({target}))
.pipe(exist.dest({target, html5AsBinary}));
}

gulp.task('deploy', function() {
return gulp.src('**/*', {cwd: 'build'})
.pipe(exClient.newer(targetOptions))
.pipe(exClient.dest(targetOptions));
});
exports.default = deployNewer
```
### existClient.query(options)
Expand Down Expand Up @@ -197,49 +229,48 @@ Default: `'xml'`
Upload a collection index configuration file and re-index the collection
*```scripts/reindex.xql```*
*```scripts/reindex.xq```*
```xquery
xquery version "3.1";
declare option exist:serialize "method=json media-type=text/javascript";
<result>
<success>{xmldb:reindex('/db/apps/myapp/data')}</success>
</result>

map { "success": xmldb:reindex('/db/apps/myapp/data') }
```
*```gulpfile.js```*
```js
const gulp = require('gulp'),
exist = require('@existdb/gulp-exist')
const { src, dest } = require('gulp')
const { createClient } = require('@existdb/gulp-exist')

// override defaults
const connectionOptions = {
// override some default connection options
const exist = createClient({
basic_auth: {
user: "admin",
pass: "****************"
pass: ""
}
}

const exClient = exist.createClient(connectionOptions)
})

const exist_config = {
target: '/db/system/config/db/apps/myapp/data',
const queryConfig = {
target: '/db/apps/myapp',
xqlOutputExt: 'json'
};
}

gulp.task('upload-index-conf', function() {
return gulp.src('collection.xconf', {cwd: '.'})
.pipe(exClient.dest(exist_config));
});
function deployCollectionXConf () {
return src('collection.xconf', {cwd: '.'})
.pipe(exist.dest({
target: `/db/system/config${queryConfig.target}`
}))
}

gulp.task('reindex', ['upload-index-conf'], function() {
return gulp.src('scripts/reindex.xql')
.pipe(exClient.query(exist_config))
function reindex () {
return src('scripts/reindex.xq', {cwd: '.'})
.pipe(exist.query(queryConfig))
.pipe(dest('logs'))
}

// optional: store the query result locally in 'logs'
.pipe(gulp.dest('logs'));
});
exports.default = series(deployCollectionXConf, reindex)
```
## Define Custom Mime Types
Expand All @@ -249,10 +280,12 @@ Override the mime type used to store files in exist based on their extension.
*NOTE:* attempt to redefine a registered **extension** will throw an error.
Extended by default:
`{
'application/xquery': ['xq', 'xql', 'xqm'],
```js
{
'application/xquery': ['xq', 'xquery', 'xqs', 'xql', 'xqm'],
'application/xml': ['xconf', 'odd']
}`
}
```
Type: `Object {mimetype: [extensions]}`
Expand All @@ -264,82 +297,63 @@ exist.defineMimeTypes({ 'text/foo': ['bar'] })
## More examples
### Watch
Have a look at the [example gulpfile](https://github.com/eXist-db/gulp-exist/tree/master/spec/examples/gulpfile.js)
### Watch File Changes
```gulp watch``` will automatically upload files on change
`watch` will report when a file has changed. `deployBuild` will run
each time that happens uploading all files that have changed since its
last execution.
```js
const { watch, src, dest, lastRun } = require('gulp')

const gulp = require('gulp'),
exist = require('@existdb/gulp-exist'),
sass = require('gulp-sass'),
watch = require('gulp-watch'),
newer = require('gulp-newer');

const exClient = exist.createClient({ /* some configuration */});

// compile SCSS styles and put them into 'build/app/css'
gulp.task('styles', function() {
return gulp.src('app/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('build/app/css'));
});

// copy html templates, XMLs and XQuerys to 'build'
gulp.task('copy', function() {
return gulp.src('app/**/*.{xml,html,xql,xqm,xsl,rng}')
.pipe(newer('build'))
.pipe(gulp.dest('build'))
});


gulp.task('deploy', function() {
return gulp.src('build/**/*', {base: 'build'})
.pipe(exClient.newer({target: "/db/apps/myapp"}))
.pipe(exClient.dest({target: "/db/apps/myapp"}));
});

gulp.task('watch-styles', function() {
gulp.watch('app/scss/**/*.scss', gulp.series('styles'))
});

gulp.task('watch-copy', function() {
gulp.watch([
'app/js/**/*',
'app/imgs/**/*',
'app/**/*.{xml,html,xql,xqm,xsl}'
],
gulp.series('copy'));
});

gulp.task('watch-deploy', function() {
gulp.watch('build/**/*', gulp.series('deploy'));
});

gulp.task('watch', gulp.parallel('watch-styles', 'watch-copy', 'watch-deploy'));
// override defaults
const connectionOptions = {
basic_auth: {
user: "admin",
pass: ""
}
}

const exClient = exist.createClient(connectionOptions)

function deployBuild () {
return src('build/**/*', {
base: 'build',
since: lastRun(deployBuild)
})
.pipe(exClient.dest({target}))
}

exports.deploy = deployBuild

function watchBuild () {
watch('build/**/*', series(deployBuild));
}
exports.watch = watchBuild

exports.default = series(deployBuild, watchDeploy)
```
### Make XAR Archive
```js
const { src, dest } = require('gulp'),
zip = require('gulp-zip'),
pkg = require('./package.json')

const gulp = require('gulp'),
exist = require('@existdb/gulp-exist'),
zip = require('gulp-zip')

gulp.task('build', function{} {
function build {
// compile everything into the 'build' directory
});

gulp.task('xar', gulp.series('build', function() {
const pkg = require('./package.json');
}

return gulp.src('build' + '**/*', {base: 'build'})
function xar () {
return src('build/**/*', {base: 'build'})
.pipe(zip(`${pkg.abbrev}-${pkg.version}.xar`))
.pipe(gulp.dest("."));
}));
.pipe(dest("."));
}

exports.default = series(build, xar)
```
## Test
Expand Down
Loading

0 comments on commit 7f6e130

Please sign in to comment.