mirror of https://github.com/portainer/portainer
chore(build-system): refactor gruntfile (#1447)
parent
728ef35cc1
commit
7922ecc4a1
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
binary="portainer-$1-$2"
|
binary="portainer-$1-$2"
|
||||||
|
|
||||||
|
|
172
gruntfile.js
172
gruntfile.js
|
@ -1,5 +1,4 @@
|
||||||
var autoprefixer = require('autoprefixer');
|
var gruntfile_cfg = {};
|
||||||
var cssnano = require('cssnano');
|
|
||||||
var loadGruntTasks = require('load-grunt-tasks');
|
var loadGruntTasks = require('load-grunt-tasks');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var arch = os.arch();
|
var arch = os.arch();
|
||||||
|
@ -52,7 +51,7 @@ module.exports = function (grunt) {
|
||||||
grunt.task.run(['config:prod', 'clean:all', 'shell:buildBinary:'+p+':'+a, 'shell:downloadDockerBinary:'+p+':'+a, 'before-copy', 'copy:assets', 'after-copy' ]);
|
grunt.task.run(['config:prod', 'clean:all', 'shell:buildBinary:'+p+':'+a, 'shell:downloadDockerBinary:'+p+':'+a, 'before-copy', 'copy:assets', 'after-copy' ]);
|
||||||
});
|
});
|
||||||
grunt.registerTask('lint', ['eslint']);
|
grunt.registerTask('lint', ['eslint']);
|
||||||
grunt.registerTask('run-dev', ['build', 'shell:run', 'watch:build']);
|
grunt.registerTask('run-dev', ['build', 'shell:run:'+arch, 'watch:build']);
|
||||||
grunt.registerTask('clear', ['clean:app']);
|
grunt.registerTask('clear', ['clean:app']);
|
||||||
|
|
||||||
// Load content of `vendor.yml` to src.jsVendor, src.cssVendor and src.angularVendor
|
// Load content of `vendor.yml` to src.jsVendor, src.cssVendor and src.angularVendor
|
||||||
|
@ -83,24 +82,52 @@ module.exports = function (grunt) {
|
||||||
distdir: 'dist/public',
|
distdir: 'dist/public',
|
||||||
shippedDockerVersion: '17.09.0-ce',
|
shippedDockerVersion: '17.09.0-ce',
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
pkg: grunt.file.readJSON('package.json'),
|
||||||
config: {
|
config: gruntfile_cfg.config,
|
||||||
|
src: gruntfile_cfg.src,
|
||||||
|
clean: gruntfile_cfg.clean,
|
||||||
|
useminPrepare: gruntfile_cfg.useminPrepare,
|
||||||
|
filerev: { files: { src: ['<%= distdir %>/js/*.js', '<%= distdir %>/css/*.css'] }},
|
||||||
|
usemin: { html: ['<%= distdir %>/index.html'] },
|
||||||
|
copy: gruntfile_cfg.copy,
|
||||||
|
eslint: gruntfile_cfg.eslint,
|
||||||
|
html2js: gruntfile_cfg.html2js,
|
||||||
|
concat: gruntfile_cfg.concat,
|
||||||
|
uglify: gruntfile_cfg.uglify,
|
||||||
|
postcss: gruntfile_cfg.postcss,
|
||||||
|
watch: gruntfile_cfg.watch,
|
||||||
|
shell: gruntfile_cfg.shell,
|
||||||
|
replace: gruntfile_cfg.replace
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/***/
|
||||||
|
|
||||||
|
var autoprefixer = require('autoprefixer');
|
||||||
|
var cssnano = require('cssnano');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
gruntfile_cfg.config = {
|
||||||
dev: { options: { variables: { 'environment': 'development' }}},
|
dev: { options: { variables: { 'environment': 'development' }}},
|
||||||
prod: { options: { variables: { 'environment': 'production' }}}
|
prod: { options: { variables: { 'environment': 'production' }}}
|
||||||
},
|
};
|
||||||
src: {
|
|
||||||
|
gruntfile_cfg.src = {
|
||||||
js: ['app/**/__module.js', 'app/**/*.js', '!app/**/*.spec.js'],
|
js: ['app/**/__module.js', 'app/**/*.js', '!app/**/*.spec.js'],
|
||||||
jsTpl: ['<%= distdir %>/templates/**/*.js'],
|
jsTpl: ['<%= distdir %>/templates/**/*.js'],
|
||||||
html: ['index.html'],
|
html: ['index.html'],
|
||||||
tpl: ['app/components/**/*.html', 'app/directives/**/*.html'],
|
tpl: ['app/components/**/*.html', 'app/directives/**/*.html'],
|
||||||
css: ['assets/css/app.css']
|
css: ['assets/css/app.css']
|
||||||
},
|
};
|
||||||
clean: {
|
|
||||||
|
gruntfile_cfg.clean = {
|
||||||
all: ['<%= distdir %>/../*'],
|
all: ['<%= distdir %>/../*'],
|
||||||
app: ['<%= distdir %>/*', '!<%= distdir %>/../portainer*', '!<%= distdir %>/../docker*'],
|
app: ['<%= distdir %>/*', '!<%= distdir %>/../portainer*', '!<%= distdir %>/../docker*'],
|
||||||
tmpl: ['<%= distdir %>/templates'],
|
tmpl: ['<%= distdir %>/templates'],
|
||||||
tmp: ['<%= distdir %>/js/*', '!<%= distdir %>/js/app.*.js', '<%= distdir %>/css/*', '!<%= distdir %>/css/app.*.css']
|
tmp: ['<%= distdir %>/js/*', '!<%= distdir %>/js/app.*.js', '<%= distdir %>/css/*', '!<%= distdir %>/css/app.*.css']
|
||||||
},
|
};
|
||||||
useminPrepare: {
|
|
||||||
|
gruntfile_cfg.useminPrepare = {
|
||||||
dev: {
|
dev: {
|
||||||
src: '<%= src.html %>',
|
src: '<%= src.html %>',
|
||||||
options: {
|
options: {
|
||||||
|
@ -120,10 +147,9 @@ module.exports = function (grunt) {
|
||||||
dest: '<%= distdir %>'
|
dest: '<%= distdir %>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
filerev: { files: { src: ['<%= distdir %>/js/*.js', '<%= distdir %>/css/*.css'] }},
|
|
||||||
usemin: { html: ['<%= distdir %>/index.html'] },
|
gruntfile_cfg.copy = {
|
||||||
copy: {
|
|
||||||
bundle: {
|
bundle: {
|
||||||
files: [
|
files: [
|
||||||
{dest:'<%= distdir %>/js/', src: ['app.js'], expand: true, cwd: '.tmp/concat/js/' },
|
{dest:'<%= distdir %>/js/', src: ['app.js'], expand: true, cwd: '.tmp/concat/js/' },
|
||||||
|
@ -139,20 +165,23 @@ module.exports = function (grunt) {
|
||||||
{dest: '<%= distdir %>/ico', src: '**', expand: true, cwd: 'assets/ico'}
|
{dest: '<%= distdir %>/ico', src: '**', expand: true, cwd: 'assets/ico'}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
eslint: {
|
|
||||||
|
gruntfile_cfg.eslint = {
|
||||||
src: ['gruntfile.js', '<%= src.js %>'],
|
src: ['gruntfile.js', '<%= src.js %>'],
|
||||||
options: { configFile: '.eslintrc.yml' }
|
options: { configFile: '.eslintrc.yml' }
|
||||||
},
|
};
|
||||||
html2js: {
|
|
||||||
|
gruntfile_cfg.html2js = {
|
||||||
app: {
|
app: {
|
||||||
options: { base: '.' },
|
options: { base: '.' },
|
||||||
src: ['<%= src.tpl %>'],
|
src: ['<%= src.tpl %>'],
|
||||||
dest: '<%= distdir %>/templates/app.js',
|
dest: '<%= distdir %>/templates/app.js',
|
||||||
module: '<%= pkg.name %>.templates'
|
module: '<%= pkg.name %>.templates'
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
concat: {
|
|
||||||
|
gruntfile_cfg.concat = {
|
||||||
vendor: {
|
vendor: {
|
||||||
files: {
|
files: {
|
||||||
'<%= distdir %>/css/<%= pkg.name %>.css': ['<%= src.cssVendor %>', '<%= src.css %>'],
|
'<%= distdir %>/css/<%= pkg.name %>.css': ['<%= src.cssVendor %>', '<%= src.css %>'],
|
||||||
|
@ -167,8 +196,9 @@ module.exports = function (grunt) {
|
||||||
'<%= distdir %>/index.html': ['index.html']
|
'<%= distdir %>/index.html': ['index.html']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
uglify: {
|
|
||||||
|
gruntfile_cfg.uglify = {
|
||||||
dist: {
|
dist: {
|
||||||
files: { '<%= distdir %>/js/<%= pkg.name %>.js': ['<%= src.js %>', '<%= src.jsTpl %>'] }
|
files: { '<%= distdir %>/js/<%= pkg.name %>.js': ['<%= src.js %>', '<%= src.jsTpl %>'] }
|
||||||
},
|
},
|
||||||
|
@ -178,8 +208,9 @@ module.exports = function (grunt) {
|
||||||
'<%= distdir %>/js/angular.js': ['<%= src.angularVendor %>']
|
'<%= distdir %>/js/angular.js': ['<%= src.angularVendor %>']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
postcss: {
|
|
||||||
|
gruntfile_cfg.postcss = {
|
||||||
build: {
|
build: {
|
||||||
options: {
|
options: {
|
||||||
processors: [
|
processors: [
|
||||||
|
@ -190,57 +221,21 @@ module.exports = function (grunt) {
|
||||||
src: '<%= distdir %>/css/<%= pkg.name %>.css',
|
src: '<%= distdir %>/css/<%= pkg.name %>.css',
|
||||||
dest: '<%= distdir %>/css/app.css'
|
dest: '<%= distdir %>/css/app.css'
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
watch: {
|
|
||||||
|
gruntfile_cfg.watch = {
|
||||||
build: {
|
build: {
|
||||||
files: ['<%= src.js %>', '<%= src.css %>', '<%= src.tpl %>', '<%= src.html %>'],
|
files: ['<%= src.js %>', '<%= src.css %>', '<%= src.tpl %>', '<%= src.html %>'],
|
||||||
tasks: ['build']
|
tasks: ['build']
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
shell: {
|
|
||||||
buildBinary: {
|
gruntfile_cfg.replace = {
|
||||||
command: function (p, a) {
|
|
||||||
var binfile = 'dist/portainer-'+p+'-'+a;
|
|
||||||
if (grunt.file.isFile( ( p === 'windows' ) ? binfile+'.exe' : binfile )) {
|
|
||||||
return 'echo "Portainer binary exists"';
|
|
||||||
} else {
|
|
||||||
return 'build/build_in_container.sh ' + p + ' ' + a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
run: {
|
|
||||||
command: [
|
|
||||||
'docker rm -f portainer',
|
|
||||||
'docker run -d -p 9000:9000 -v $(pwd)/dist:/app -v /tmp/portainer:/data -v /var/run/docker.sock:/var/run/docker.sock:z --name portainer portainer/base /app/portainer-linux-' + arch + ' --no-analytics'
|
|
||||||
].join(';')
|
|
||||||
},
|
|
||||||
downloadDockerBinary: {
|
|
||||||
command: function(p, a) {
|
|
||||||
if (p === 'windows') p = 'win';
|
|
||||||
if (p === 'darwin') p = 'mac';
|
|
||||||
if (a === 'amd64') a = 'x86_64';
|
|
||||||
if (a === 'arm') a = 'armhf';
|
|
||||||
if (a === 'arm64') a = 'aarch64';
|
|
||||||
if (grunt.file.isFile( ( p === 'win' ) ? 'dist/docker.exe' : 'dist/docker' )) {
|
|
||||||
return 'echo "Docker binary exists"';
|
|
||||||
} else {
|
|
||||||
return 'build/download_docker_binary.sh ' + p + ' ' + a + ' <%= shippedDockerVersion %>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
replace: {
|
|
||||||
concat: {
|
concat: {
|
||||||
options: {
|
options: {
|
||||||
patterns: [
|
patterns: [
|
||||||
{
|
{ match: 'ENVIRONMENT', replacement: '<%= grunt.config.get("environment") %>' },
|
||||||
match: 'ENVIRONMENT',
|
{ match: 'CONFIG_GA_ID', replacement: '<%= pkg.config.GA_ID %>' }
|
||||||
replacement: '<%= grunt.config.get("environment") %>'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
match: 'CONFIG_GA_ID',
|
|
||||||
replacement: '<%= pkg.config.GA_ID %>'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
files: [
|
files: [
|
||||||
|
@ -252,7 +247,42 @@ module.exports = function (grunt) {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
function shell_buildBinary(p, a) {
|
||||||
|
var binfile = 'dist/portainer-'+p+'-'+a;
|
||||||
|
return [
|
||||||
|
'if [ -f '+(( p === 'windows' ) ? binfile+'.exe' : binfile)+' ]; then',
|
||||||
|
'echo "Portainer binary exists";',
|
||||||
|
'else',
|
||||||
|
'build/build_in_container.sh ' + p + ' ' + a + ';',
|
||||||
|
'fi'
|
||||||
|
].join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function shell_run(arch) {
|
||||||
|
return [
|
||||||
|
'docker rm -f portainer',
|
||||||
|
'docker run -d -p 9000:9000 -v $(pwd)/dist:/app -v /tmp/portainer:/data -v /var/run/docker.sock:/var/run/docker.sock:z --name portainer portainer/base /app/portainer-linux-' + arch + ' --no-analytics'
|
||||||
|
].join(';');
|
||||||
|
}
|
||||||
|
|
||||||
|
function shell_downloadDockerBinary(p, a) {
|
||||||
|
var ps = { 'windows': 'win', 'darwin': 'mac' };
|
||||||
|
var as = { 'amd64': 'x86_64', 'arm': 'armhf', 'arm64': 'aarch64' };
|
||||||
|
var ip = ((ps[p] === undefined) ? p : ps[p]);
|
||||||
|
var ia = ((as[a] === undefined) ? a : as[a]);
|
||||||
|
return [
|
||||||
|
'if [ -f '+(( p === 'win' ) ? 'dist/docker.exe' : 'dist/docker')+' ]; then',
|
||||||
|
'echo "Docker binary exists";',
|
||||||
|
'else',
|
||||||
|
'build/download_docker_binary.sh ' + ip + ' ' + ia + ' <%= shippedDockerVersion %>;',
|
||||||
|
'fi'
|
||||||
|
].join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
gruntfile_cfg.shell = {
|
||||||
|
buildBinary: { command: shell_buildBinary },
|
||||||
|
run: { command: shell_run },
|
||||||
|
downloadDockerBinary: { command: shell_downloadDockerBinary }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue