Merge pull request #35 from rancher/use-build-script

Remove gulp and use  build script
This commit is contained in:
Neil MacDougall 2023-04-17 18:44:32 +01:00 committed by GitHub
commit c61f2329a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 324 additions and 3237 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
.DS_Store .DS_Store
node_modules node_modules
npm-debug.log npm-debug.log
bower_components
dist dist
tmp tmp
.*.sw? .*.sw?

View File

@ -1,20 +1,174 @@
Copyright (c) 2013-2014 Go Daddy Operating Company, LLC Apache License
Copyright (c) 2014-2016 Rancher Labs, Inc. Version 2.0, January 2004
http://www.apache.org/licenses/
Permission is hereby granted, free of charge, to any person obtaining a TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in 1. Definitions.
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "License" shall mean the terms and conditions for use, reproduction,
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, and distribution as defined by Sections 1 through 9 of this document.
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "Licensor" shall mean the copyright owner or entity authorized by
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING the copyright owner that is granting the License.
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. "Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

View File

@ -12,7 +12,7 @@ Install
```bash ```bash
git clone https://github.com/rancherio/api-ui git clone https://github.com/rancherio/api-ui
cd api-ui cd api-ui
npm install yarn install
``` ```
Usage Usage
@ -25,14 +25,6 @@ This will write files to `./dist/{version}/`, suitable for publishing to a CDN.
./scripts/build ./scripts/build
``` ```
### Running as a standalone server
This will start a server on the given port number (default: 3000) that serves up the assets directly.
This mode is mostly suitable for development of this library itself.
```bash
./scripts/serve
```
Integrating with an API Integrating with an API
-------- --------
Wrap JSON responses with a bit of HTML (and return `Content-Type: text/html`): Wrap JSON responses with a bit of HTML (and return `Content-Type: text/html`):
@ -77,6 +69,6 @@ var bootstrap = "http://url/to/bootstrap/version";
``` ```
### Bugs & Issues ### Bugs & Issues
Please submit bugs and issues to [rancher/rancher](//github.com/rancher/rancher/issues) with a title starting with `[API UI] `. Please submit bugs and issues to [rancher/dashboard](//github.com/rancher/dashboard/issues) with a title starting with `[API UI] `.
Or just [click here](//github.com/rancher/rancher/issues/new?title=%5BAPI%20UI%5D%20) to create a new issue. Or just [click here](//github.com/rancher/dashboard/issues/new?title=%5BAPI%20UI%5D%20) to create a new issue.

View File

@ -1,54 +0,0 @@
{
"staticFileDirs": {
"image": "public/image",
"fonts": "public/fonts"
},
/* a comment */
"groups": {
"base": {
"saveOutput": false,
"css": [
"main"
],
"js": [
"jquery",
"async", "json2", "polyfill",
"JSONFormatter", "URLParse", "Cookie",
"handlebars.runtime", "template"
]
},
"ui": {
"include": [
"base"
],
"css": [
"explorer"
],
"view": [
"body",
"filters", "filter",
"request", "response",
"edit", "field",
"modal",
"explorer",
"column",
"column-links",
"column-collection",
"column-resource"
],
"js": [
"HTMLApi",
"Explorer",
"jquery.scrollintoview",
"init"
]
}
}
}

View File

@ -1,140 +0,0 @@
var gulp = require('gulp');
var gulpConcat = require('gulp-concat');
var gulpConnect = require('gulp-connect');
var gulpExec = require('gulp-exec');
var gulpGzip = require('gulp-gzip');
var gulpMap = require('gulp-sourcemaps');
var gulpRename = require('gulp-rename');
var gulpReplace = require('gulp-replace');
var gulpSass = require('gulp-sass')(require('sass'));
var gulpTar = require('gulp-tar');
var gulpUglify = require('gulp-uglify');
var fs = require('fs-extra');
var pkg = require('./package.json');
var DIST = 'dist/';
var VERSION_DIST = DIST+pkg.version+'/';
var CDN = 'cdn.rancher.io/api-ui';
gulp.task('clean', function() {
return fs.emptyDir('./tmp').then(() => fs.emptyDir('./dist'));
});
gulp.task('server:reload', function() {
return gulpConnect.reload();
});
gulp.task('templates', function() {
return gulp.src('templates/*.hbs', {read: false})
.pipe(gulpExec(file => `./node_modules/.bin/handlebars "${file.path}"`, {pipeStdout: true}))
.pipe(gulpRename(function(path) {
path.extname = '.hbs.js';
}))
.pipe(gulp.dest('./tmp/tpl'));
});
gulp.task('partials', function() {
return gulp.src('partials/*.hbs', {read: false})
.pipe(gulpExec(file => `./node_modules/.bin/handlebars --partial "${file.path}"`, {pipeStdout: true}))
.pipe(gulpRename(function(path) {
path.extname = '.hbs.js';
}))
.pipe(gulp.dest('./tmp/tpl'));
});
gulp.task('js', gulp.series('templates','partials', function() {
return gulp.src([
'node_modules/jquery/dist/jquery.js',
'vendor/jquery.scrollintoview.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'vendor/async.js',
'vendor/json2.js',
'vendor/polyfill.js',
'vendor/JSONFormatter.js',
'src/URLParse.js',
'src/Cookie.js',
'node_modules/handlebars/dist/handlebars.runtime.js',
'src/template.js',
'tmp/tpl/**',
'src/HTMLApi.js',
'src/Explorer.js',
'src/init.js',
])
.pipe(gulpMap.init())
.pipe(gulpConcat('ui.js',{newLine: ';\n'}))
.pipe(gulpMap.write('./'))
.pipe(gulp.dest(VERSION_DIST));
}));
gulp.task('minjs', gulp.series('js', function() {
return gulp.src([VERSION_DIST+'/ui.js'], {base: VERSION_DIST})
.pipe(gulpRename({suffix: '.min'}))
.pipe(gulpMap.init({loadMaps: true}))
.pipe(gulpUglify())
.pipe(gulpMap.write('./'))
.pipe(gulp.dest(VERSION_DIST));
}));
gulp.task('css', function() {
return gulp.src([
'./node_modules/bootstrap/dist/css/bootstrap.css',
'styles/main.scss',
'styles/explorer.scss'
])
.pipe(gulpReplace("/*# sourceMappingURL=bootstrap.css.map */",""))
.pipe(gulpConcat('ui.css'))
.pipe(gulpMap.init())
.pipe(gulpSass())
.pipe(gulpMap.write('./'))
.pipe(gulp.dest(VERSION_DIST))
});
gulp.task('mincss', gulp.series('css', function() {
return gulp.src([VERSION_DIST+'/ui.css'], {base: VERSION_DIST})
.pipe(gulpRename({suffix: '.min'}))
.pipe(gulpMap.init({loadMaps: true}))
.pipe(gulpMap.write('./'))
.pipe(gulp.dest(VERSION_DIST));
}));
gulp.task('bootstrap', function() {
return gulp.src(['node_modules/bootstrap/dist/**'])
.pipe(gulp.dest(VERSION_DIST));
});
gulp.task('livereload', function(cb) {
gulp.watch('./gulpfile.js', gulp.series('server:reload'));
gulp.watch('styles/**', gulp.series('css'));
gulp.watch('src/**', gulp.series('js'));
gulp.watch('templates/**', gulp.series('js'));
gulp.watch('partials/**', gulp.series('js'));
cb();
})
gulp.task('src', gulp.series('minjs','mincss','bootstrap'));
gulp.task('tarball', gulp.series('src', function() {
return gulp.src([VERSION_DIST+'/**'], {base: DIST})
.pipe(gulpTar(pkg.version+'.tar'))
.pipe(gulpGzip())
.pipe(gulp.dest(DIST));
}));
gulp.task('build', gulp.series('tarball'), () => {});
gulp.task('default', gulp.series('build'));
gulp.task('server', gulp.series('build', 'livereload', function() {
var cors = function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
};
return gulpConnect.server({
root: [VERSION_DIST],
port: process.env.PORT || 3000,
middleware: function() {
return [cors];
},
});
}));

13
index.html.tmpl Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<!-- If you are reading this, there is a good chance you would prefer sending an
"Accept: application/json" header and receiving actual JSON responses. -->
<link rel="stylesheet" type="text/css" href="./VERSION/ui.min.css" />
<script src="./VERSION/ui.min.js"></script>
<script>
var user = "admin";
var curlUser='${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}';
var schemas="https://rancher-server/v1/schemas";
var data =
{"id":"default/test","type":"event","links":{"remove":"https://rancher-server/v1/events/default/test-resource","self":"https://rancher-server/v1/events/default/test-resource","update":"https://rancher-server/v1/events/default/test-resource","view":"https://rancher-server/api/v1/namespaces/default/events/test-resource"},"_type":"Normal","apiVersion":"v1","count":38866,"eventTime":null,"firstTimestamp":"2023-02-28T21:18:59Z","involvedObject":{"apiVersion":"v1","fieldPath":"spec.containers{busybox}","kind":"Pod","name":"test-pod","namespace":"default","resourceVersion":"2539317","uid":"88f9e0a4-854a-4a3a-a0fb-dccf3753ed42"},"kind":"Event","lastTimestamp":"2023-03-06T17:34:09Z","message":"Container image \"busybox\" already present on machine","metadata":{"creationTimestamp":"2023-02-28T21:18:59Z","managedFields":[{"apiVersion":"v1","fieldsType":"FieldsV1","fieldsV1":{"f:count":{},"f:firstTimestamp":{},"f:involvedObject":{},"f:lastTimestamp":{},"f:message":{},"f:reason":{},"f:source":{"f:component":{},"f:host":{}},"f:type":{}},"manager":"k3s","operation":"Update","time":"2023-03-06T17:34:09Z"}],"name":"test-resource","namespace":"default","relationships":null,"resourceVersion":"6406346","state":{"error":false,"message":"Resource is current","name":"active","transitioning":false},"uid":"1018c9dd-794a-4957-ac5a-9fb5e4f2312f"},"reason":"Pulled","reportingComponent":"","reportingInstance":"","source":{"component":"kubelet","host":"local-node"}}
</script>

View File

@ -2,13 +2,10 @@
"name": "api-ui", "name": "api-ui",
"version": "1.1.10", "version": "1.1.10",
"description": "Embedded UI for any service that implements the Rancher API spec", "description": "Embedded UI for any service that implements the Rancher API spec",
"contributors": [ "author": "SUSE",
"Go Daddy Operating Company, LLC. (http://godaddy.com)", "license": "Apache-2.0",
"Rancher Labs, Inc. (http://rancher.com)"
],
"license": "MIT",
"homepage": "http://github.com/rancherio/api-ui", "homepage": "http://github.com/rancherio/api-ui",
"bugs": "http://github.com/rancherio/api-ui/issues", "bugs": "http://github.com/rancherio/dashboard/issues",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/rancherio/api-ui.git" "url": "https://github.com/rancherio/api-ui.git"
@ -17,27 +14,18 @@
"node": ">= 14.14" "node": ">= 14.14"
}, },
"scripts": { "scripts": {
"start": "./node_modules/.bin/gulp server", "clean": "./scripts/clean",
"clean": "./node_modules/.bin/gulp clean", "build": "./scripts/build",
"build": "./node_modules/.bin/gulp build",
"upload": "./scripts/upload" "upload": "./scripts/upload"
}, },
"devDependencies": { "devDependencies": {
"clean-css-cli": "^5.6.2",
"sass": "1.58.3",
"uglify-js": "3.17.4"
},
"dependencies": {
"bootstrap": "3.4.1", "bootstrap": "3.4.1",
"fs-extra": "11.1.0",
"gulp": "4.0.2",
"gulp-concat": "2.6.1",
"gulp-connect": "5.7.0",
"gulp-exec": "5.0.0",
"gulp-gzip": "1.4.2",
"gulp-rename": "2.0.0",
"gulp-replace": "1.1.4",
"gulp-sass": "5.1.0",
"gulp-sourcemaps": "3.0.0",
"gulp-tar": "3.1.0",
"gulp-uglify": "3.0.2",
"handlebars": "4.7.7", "handlebars": "4.7.7",
"jquery": "3.6.3", "jquery": "3.6.3"
"sass": "1.58.3"
} }
} }

View File

@ -3,11 +3,89 @@ set -e
echo "Building api-ui" echo "Building api-ui"
echo $VERSION rm -rf ./dist
rm -rf ./tmp
npm install mkdir -p tmp/tpl
npm run build
ls -al dist HB_EXEC=./node_modules/.bin/handlebars
echo "Built" VERSION=$(npm pkg get version | tr -d '"')
echo "Version: ${VERSION}"
echo ""
DIST=./dist/${VERSION}
mkdir -p ${DIST}
echo "Compiling templates ..."
# Compile templates
for FILE in ./templates/*;
do
NAME=$(basename $FILE)
${HB_EXEC} $FILE -f ./tmp/tpl/${NAME}.js
done
# Compile partials
for FILE in ./partials/*;
do
NAME=$(basename $FILE)
${HB_EXEC} --partial $FILE -f ./tmp/tpl/${NAME}.js
done
echo "Building ..."
JS_FILES=(node_modules/jquery/dist/jquery.js \
vendor/jquery.scrollintoview.js \
node_modules/bootstrap/dist/js/bootstrap.js \
vendor/async.js \
vendor/json2.js \
vendor/polyfill.js \
vendor/JSONFormatter.js \
src/URLParse.js \
src/Cookie.js \
node_modules/handlebars/dist/handlebars.runtime.js \
src/template.js \
tmp/tpl/** \
src/HTMLApi.js \
src/Explorer.js \
src/init.js)
# Combine all javascript files together
# Need to add a semicolon between each file
for str in ${JS_FILES[@]}; do
cat $str >> ${DIST}/ui.js
echo ";" >> ${DIST}/ui.js
done
# Copy bootstrap files
cp -R node_modules/bootstrap/dist/** ${DIST}
# Patch bootstrap.css to remove source mapping URL comment
sed -i.bak -e "s@/\*# sourceMappingURL=bootstrap\.css\.map.*@@g" ${DIST}/css/bootstrap.css
# Generate css
cat ./node_modules/bootstrap/dist/css/bootstrap.css \
styles/main.scss \
styles/explorer.scss \
> ./tmp/ui.scss
# Compile sass
./node_modules/.bin/sass ./tmp/ui.scss ${DIST}/ui.css
# Minimise javascript
./node_modules/.bin/uglifyjs -c --source-map -o ${DIST}/ui.min.js ${DIST}/ui.js
# Minimise css
./node_modules/.bin/cleancss ${DIST}/ui.css -o ${DIST}/ui.min.css
# tar
echo "Creating tar file ..."
tar -cvzf ./dist/${VERSION}.tar.gz -C ${DIST} .
# Copy index.html for testing
sed -e "s/VERSION/"${VERSION}"/g" ./index.html.tmpl > ./dist/index.html
echo ""
echo "All done"
echo ""

5
scripts/clean Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
rm -rf ./dist
rm -rf ./tmp

3022
yarn.lock

File diff suppressed because it is too large Load Diff