Compare commits
3 Commits
c8c57c8772
...
7bd4224a05
Author | SHA1 | Date | |
---|---|---|---|
|
7bd4224a05 | ||
|
d680bf4c5e | ||
|
d53641ea1b |
46
Jenkinsfile
vendored
Normal file
46
Jenkinsfile
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.1.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
publish = 0
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Setup') {
|
||||
steps {
|
||||
echo 'Setting up test environment'
|
||||
sh 'npm ci'
|
||||
sh 'nodejs jenkins.js ${VERSION}'
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Testing') {
|
||||
steps {
|
||||
echo 'Running tests...'
|
||||
sh 'npm test'
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
script {
|
||||
publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true
|
||||
if (publish != 0) {
|
||||
echo 'Deploying'
|
||||
sh 'npm publish'
|
||||
} else {
|
||||
echo 'Build successful, Commit not marked for deploying'
|
||||
currentBuild.result = "UNSTABLE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
index.js
4
index.js
@ -8,11 +8,11 @@ const path = require('path');
|
||||
* @param {string} modulefolder
|
||||
* @param {any} opts object to pass to the handlers (for example database access)
|
||||
*/
|
||||
module.exports = function (app, modulefolder, opts) {
|
||||
module.exports = function (app, modulefolder, opts = {}, subdir = '') {
|
||||
for (const f of fs.readdirSync(modulefolder)) {
|
||||
const regex = /(.*?)-(.*?)\.js/;
|
||||
let [, method, url] = regex.exec(f);
|
||||
url = '/' + url + '/';
|
||||
url = '/' + subdir + '/' + url + '/';
|
||||
url = url
|
||||
.replace(/^\/root/i, '/')
|
||||
.replace(/\./g, '/')
|
||||
|
5
jenkins.js
Normal file
5
jenkins.js
Normal file
@ -0,0 +1,5 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
||||
pkg.version = process.argv[2];
|
||||
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
|
19
test/main.js
19
test/main.js
@ -28,7 +28,7 @@ describe('requestor', () => {
|
||||
});
|
||||
|
||||
it('should detect all requests on root', () => {
|
||||
requestor(mock, './test/root', {});
|
||||
requestor(mock, './test/root');
|
||||
expect(mock.registered).to.have.all.keys([
|
||||
'post-/',
|
||||
'get-/',
|
||||
@ -39,7 +39,7 @@ describe('requestor', () => {
|
||||
});
|
||||
|
||||
it('should detect requests on root.subfolder', () => {
|
||||
requestor(mock, './test/root.sub', {});
|
||||
requestor(mock, './test/root.sub');
|
||||
expect(mock.registered).to.have.all.keys([
|
||||
'post-/sub/',
|
||||
'get-/sub/',
|
||||
@ -50,7 +50,7 @@ describe('requestor', () => {
|
||||
});
|
||||
|
||||
it('should detect requests on subfolder', () => {
|
||||
requestor(mock, './test/sub', {});
|
||||
requestor(mock, './test/sub');
|
||||
expect(mock.registered).to.have.all.keys([
|
||||
'post-/sub/',
|
||||
'get-/sub/',
|
||||
@ -61,4 +61,17 @@ describe('requestor', () => {
|
||||
'all-/sub/root/'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should build requests with subdirectory', () => {
|
||||
requestor(mock, './test/sub', {}, 'test');
|
||||
expect(mock.registered).to.have.all.keys([
|
||||
'post-/test/sub/',
|
||||
'get-/test/sub/',
|
||||
'put-/test/sub/',
|
||||
'delete-/test/sub/',
|
||||
'all-/test/sub/',
|
||||
'get-/test/sub/lv1/lv2/lv3/',
|
||||
'all-/test/sub/root/'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user