From 19475eadd380a1fc11968f4e1849d6b5ce643154 Mon Sep 17 00:00:00 2001 From: Marcelo Portugal Date: Mon, 23 Jan 2023 10:36:29 -0500 Subject: [PATCH] chore(ui-grid): revert build tasks to rely on grunt --- grunt/aliases.js | 11 +- grunt/clean.js | 3 +- grunt/concat.js | 48 ++ grunt/copy.js | 10 +- grunt/less.js | 74 +++ grunt/replace.js | 19 + grunt/shell.js | 3 - grunt/uglify.js | 21 + grunt/uidocs-generator.js | 4 +- grunt/watch.js | 8 +- lib/grunt/utils.js | 8 +- misc/demo/col-swap.html | 2 +- misc/demo/filtertoggle.html | 2 +- misc/demo/grid-accessiblility.html | 2 +- misc/demo/grid-directive.html | 2 +- misc/demo/grid-in-tabs.html | 2 +- misc/demo/grid-save.html | 2 +- misc/demo/leak-testing.html | 2 +- misc/demo/modal.html | 2 +- misc/demo/overflow-problem.html | 2 +- misc/demo/pinning.html | 2 +- misc/demo/subgrid.html | 2 +- package-lock.json | 965 ++++++++++++++++++++++++++++- package.json | 6 +- 24 files changed, 1153 insertions(+), 49 deletions(-) create mode 100644 grunt/concat.js create mode 100644 grunt/less.js create mode 100644 grunt/replace.js create mode 100644 grunt/uglify.js diff --git a/grunt/aliases.js b/grunt/aliases.js index 5835eae0cb..a987f861c4 100644 --- a/grunt/aliases.js +++ b/grunt/aliases.js @@ -6,16 +6,17 @@ module.exports = function (grunt, options) { // register before and after test tasks so we don't have to change cli // options on the CI server 'before-test': [ - 'clean', 'shell:lint', 'ngtemplates' - ], + 'clean', 'shell:lint', 'ngtemplates', 'less', 'copy:font_dist','copy:packages_dist' + ], // Have to run less so CSS files are present 'after-test': ['build'], 'default': ['before-test', 'test:single', 'after-test'], // Build with no testing 'build': [ - 'shell:build', 'uidocs-generator', + 'ngtemplates', 'concat', 'uglify', 'less', 'uidocs-generator', 'copy:font_dist', 'copy:packages_dist', 'copy:site', 'copy:less_customizer', ], + 'build:less_dist': ['copy:less_dist', 'replace:less_dist'], // Auto-test tasks for development 'autotest:unit': ['karmangular:start'], @@ -53,10 +54,10 @@ module.exports = function (grunt, options) { var currentTag = semver.clean( util.getCurrentTag() ); if (currentTag) { - baseTasks['release'] = ['cut-release', 'gh-pages:ui-grid-site', 'update-bower-json', 'gh-pages:bower', 'npm-publish']; + baseTasks['release'] = ['clean', 'ngtemplates', 'build', 'build:less_dist', 'cut-release', 'gh-pages:ui-grid-site', 'update-bower-json', 'gh-pages:bower', 'npm-publish']; } else { - baseTasks['release'] = ['cut-release']; + baseTasks['release'] = ['clean', 'ngtemplates', 'build', 'build:less_dist', 'cut-release']; } return baseTasks; diff --git a/grunt/clean.js b/grunt/clean.js index 5caa2627d8..66661bd615 100644 --- a/grunt/clean.js +++ b/grunt/clean.js @@ -2,5 +2,6 @@ module.exports = // Clean the temp directory ['.tmp', '<%= dist %>', 'docs', 'coverage', 'packages/*/.npmignore', 'packages/*/LICENSE.md', - 'packages/*/css', 'packages/*/dist', 'packages/*/js', 'packages/*/index.js'] + 'packages/*/css', 'packages/*/js', 'packages/*/*.js', + 'packages/*/webpack.config.js'] ; diff --git a/grunt/concat.js b/grunt/concat.js new file mode 100644 index 0000000000..f4793d24bd --- /dev/null +++ b/grunt/concat.js @@ -0,0 +1,48 @@ +const fs = require('fs'); +const path = require('path'); + +const getDirectories = p => fs.readdirSync(p).filter(f => fs.statSync(path.join(p, f)).isDirectory()); +const getLanguages = p => fs.readdirSync(p).filter(f => fs.statSync(path.join(p, f)).isFile()); +const getTemplateDirectories = p => fs.readdirSync(p) +.filter(f => fs.statSync(path.join(p, f)).isDirectory() && fs.existsSync(path.join(p, f, 'src/templates'))); +const templateDirectories = getTemplateDirectories('packages/'); + +function getFiles() { + const files = { + '<%= dist %>/release/<%= pkg.name %>.js': ['packages/core/src/js/bootstrap.js', 'packages/*/src/js/**/*.js', '.tmp/template.js'], + 'packages/core/js/<%= pkg.name %>.core.js': ['src/js/core/bootstrap.js', 'packages/core/src/js/**/*.js', '.tmp/template-core.js'] + }; + const packages = getDirectories('packages/'); + + packages.forEach((feat) => { + if (feat === 'i18n') { + const languages = getLanguages('packages/i18n/src/js/'); + + files['packages/i18n/js/<%= pkg.name %>.language.all.js'] = languages.map((lang) => `packages/i18n/src/js/${lang}`); + + languages.forEach((lang) => { + files[`packages/i18n/js/<%= pkg.name %>.language.${lang}`] = [`packages/i18n/src/js/${lang}`]; + }); + } else if (feat !== 'core') { + let src = [`packages/${feat}/src/js/**/*.js`]; + + if (templateDirectories.includes(feat)) { + src.push(`.tmp/template-${feat}.js`); + } + + files[`packages/${feat}/js/<%= pkg.name %>.${feat}.js`] = src; + } + }); + + return files; +} + +module.exports = { + options: { + banner: '<%= banner %>', + stripBanners: true + }, + dist: { + files: getFiles() + } +}; diff --git a/grunt/copy.js b/grunt/copy.js index 84600f295c..1a7f4c0c07 100644 --- a/grunt/copy.js +++ b/grunt/copy.js @@ -17,7 +17,7 @@ module.exports = function ( grunt ) { packages.forEach(function(feat) { let featModuleName = '.' + _.camelCase(feat); - let featMainPath = `./dist/${package.name}.${feat}`; + let featMainPath = `./js/${package.name}.${feat}`; switch(feat) { case 'cellnav': @@ -185,17 +185,17 @@ module.exports = function ( grunt ) { expand: true, flatten: true, cwd: 'packages', - src: '*/dist/*.js', + src: ['*/js/*.js', '!**/index.js'], dest: '<%= dist %>/release', filter: function(filepath) { - return !filepath.includes('packages/i18n') + return !filepath.includes('packages/i18n') } }, { expand: true, flatten: true, cwd: 'packages', - src: '*/i18n/dist/*.js', + src: ['*/i18n/js/*.js', '!**/index.js'], dest: '<%= dist %>/release/i18n', filter: 'isFile' }, @@ -203,7 +203,7 @@ module.exports = function ( grunt ) { expand: true, flatten: true, cwd: 'packages', - src: '*/dist/*.css', + src: '*/css/*.css', dest: '<%= dist %>/release/css', filter: 'isFile' } diff --git a/grunt/less.js b/grunt/less.js new file mode 100644 index 0000000000..51e17d9b7b --- /dev/null +++ b/grunt/less.js @@ -0,0 +1,74 @@ +const fs = require('fs'); +const path = require('path'); + +const getDirectories = p => fs.readdirSync(p) +.filter(f => fs.statSync(path.join(p, f)).isDirectory() && fs.existsSync(path.join(p, f, 'less'))); + +function filterCoreLessFiles(filepath) { + return filepath === 'packages/core/less/main.less' || !filepath.includes('packages/core/less/'); +} + +function getFiles(compress) { + const suffix = compress ? 'min.css' : 'css'; + const files = [ + { + src: ['packages/core/less/main.less', 'packages/*/less/**/*.less', '.tmp/font/ui-grid-codes.css'], + dest: `dist/release/<%= pkg.name %>.${suffix}`, + filter: filterCoreLessFiles + } + ]; + const packages = getDirectories('packages/'); + + packages.forEach((feat) => { + if (feat !== 'core') { + files.push({ + src: `packages/${feat}/less/*.less`, + dest: `packages/${feat}/css/<%= pkg.name %>.${feat}.${suffix}`, + filter: filterCoreLessFiles + }); + } + }); + + return files; +} + +module.exports = { + core: { + options: { + banner: '<%= banner %>', + modifyVars: { + 'font-path': '../fonts/' + } + }, + files: [{ + src: 'packages/core/less/main.less', + dest: 'packages/core/css/<%= pkg.name %>.core.css' + }] + }, + core_min: { + options: { + banner: '<%= banner %>', + modifyVars: { + 'font-path': '../fonts/' + }, + compress: true + }, + files: [{ + src: 'packages/core/less/main.less', + dest: 'packages/core/css/<%= pkg.name %>.core.min.css' + }] + }, + dist: { + options: { + banner: '<%= banner %>' + }, + files: getFiles() + }, + min: { + options: { + banner: '<%= banner %>', + compress: true + }, + files: getFiles(true) + } +}; diff --git a/grunt/replace.js b/grunt/replace.js new file mode 100644 index 0000000000..7681fa0f1d --- /dev/null +++ b/grunt/replace.js @@ -0,0 +1,19 @@ +module.exports = { + less_dist: { + options: { + patterns: [ + { + match: /..\/..\/core\/less\//g, + replace: './' + } + ] + }, + files: [ + { + expand: true, + src: '<%= dist %>/release/less/*.less', + dest: './' + } + ] + } +}; \ No newline at end of file diff --git a/grunt/shell.js b/grunt/shell.js index a478a3fcde..1e34e8db27 100644 --- a/grunt/shell.js +++ b/grunt/shell.js @@ -15,9 +15,6 @@ module.exports = function() { async: true } }, - build: { - command: 'npm run build' - }, lint: { command: 'npm run lint' }, diff --git a/grunt/uglify.js b/grunt/uglify.js new file mode 100644 index 0000000000..52f9e40b73 --- /dev/null +++ b/grunt/uglify.js @@ -0,0 +1,21 @@ +const concat = require('./concat'); + +function getFiles() { + const files = {}; + const sources = Object.keys(concat.dist.files); + + sources.forEach((srcFile) => { + files[srcFile.replace('.js', '.min.js')] = srcFile; + }); + + return files; +} + +module.exports = { + options: { + banner: '<%= banner %>' + }, + concat: { + files: getFiles() + } +}; diff --git a/grunt/uidocs-generator.js b/grunt/uidocs-generator.js index b5e3273b8b..4ac710e31f 100644 --- a/grunt/uidocs-generator.js +++ b/grunt/uidocs-generator.js @@ -8,11 +8,11 @@ module.exports = { versions: { stable: [ { src: '/release/<%= pkg.name %>.js', type: 'script' }, - { src: '/release/css/<%= pkg.name %>.css', type: 'css' } + { src: '/release/<%= pkg.name %>.css', type: 'css' } ], unstable: [ { src: '/release/<%= pkg.name %>-unstable.js', type: 'script' }, - { src: '/release/css/<%= pkg.name %>-unstable.css', type: 'css' } + { src: '/release/<%= pkg.name %>-unstable.css', type: 'css' } ] } }, diff --git a/grunt/watch.js b/grunt/watch.js index 3a9abc5357..4944dbf168 100644 --- a/grunt/watch.js +++ b/grunt/watch.js @@ -6,18 +6,18 @@ module.exports = function( grunt, options ){ gruntfile: { files: ['packages/*/src/**/*.js', 'packages/*/test/**/*.spec.js', 'test/**/*.spec.js', 'grunt/*.js'], - tasks: ['shell:lint', 'shell:build', 'uidocs-generator'] + tasks: ['shell:lint', 'uidocs-generator'] }, ngtemplates: { // files: ['packages/*/src/templates/**/*.html'], files: '<%= ngtemplates.uigrid.src %>', - tasks: ['ngtemplates', 'shell:build'] + tasks: ['ngtemplates'] }, rebuild: { files: util.testFiles.unit, - tasks: ['shell:lint', 'karmangular:run', 'shell:build', 'uidocs-generator'], + tasks: ['shell:lint', 'karmangular:run', 'concat', 'uglify', 'uidocs-generator'], }, protractor: { @@ -27,7 +27,7 @@ module.exports = function( grunt, options ){ less: { files: 'src/**/*.less', - tasks: ['shell:less', 'uidocs-generator', 'concat:customizer_less'] + tasks: ['less', 'uidocs-generator', 'concat:customizer_less'] }, docs: { diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 38115eed6c..c95d710601 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -4,10 +4,13 @@ var grunt = require('grunt'); var semver = require('semver'); var shell = require('shelljs'); +// Get the list of angular files (angular.js, angular-mocks.js, etc) +var cachedAngularFiles = grunt.file.readJSON('lib/test/angular/files.json'); + var util = module.exports = { testDependencies: { - unit: ['bower_components/jquery/jquery.min.js', 'lib/test/jquery.simulate.js','lib/test/classList.polyFill.js', 'dist/release/css/ui-grid.css', 'bower_components/lodash/dist/lodash.min.js', 'bower_components/csv-js/csv.js'] + unit: ['bower_components/jquery/jquery.min.js', 'lib/test/jquery.simulate.js','lib/test/classList.polyFill.js', 'dist/release/ui-grid.css', 'bower_components/lodash/dist/lodash.min.js', 'bower_components/csv-js/csv.js'] }, testFiles: { @@ -25,9 +28,6 @@ var util = module.exports = { // Return a list of angular files for a specific version angularFiles: function (version) { - // Get the list of angular files (angular.js, angular-mocks.js, etc) - var cachedAngularFiles = grunt.file.readJSON('lib/test/angular/files.json'); - if (version === 'latest') { version = util.latestAngular(); } diff --git a/misc/demo/col-swap.html b/misc/demo/col-swap.html index 46773f7690..0345ad8474 100644 --- a/misc/demo/col-swap.html +++ b/misc/demo/col-swap.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/filtertoggle.html b/misc/demo/filtertoggle.html index a3366fe01a..04436ff4d5 100644 --- a/misc/demo/filtertoggle.html +++ b/misc/demo/filtertoggle.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/grid-accessiblility.html b/misc/demo/grid-accessiblility.html index a0709b736a..c031eff605 100644 --- a/misc/demo/grid-accessiblility.html +++ b/misc/demo/grid-accessiblility.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/grid-directive.html b/misc/demo/grid-directive.html index b6c449c0e2..5331e2e3d7 100644 --- a/misc/demo/grid-directive.html +++ b/misc/demo/grid-directive.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/grid-in-tabs.html b/misc/demo/grid-in-tabs.html index 9326a8dfda..2683af54ce 100644 --- a/misc/demo/grid-in-tabs.html +++ b/misc/demo/grid-in-tabs.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/grid-save.html b/misc/demo/grid-save.html index 9513d1a523..8a19c65df6 100644 --- a/misc/demo/grid-save.html +++ b/misc/demo/grid-save.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/leak-testing.html b/misc/demo/leak-testing.html index c04d685ad5..033398a13b 100644 --- a/misc/demo/leak-testing.html +++ b/misc/demo/leak-testing.html @@ -7,7 +7,7 @@ - + diff --git a/misc/demo/modal.html b/misc/demo/modal.html index 888b773909..60ebcc34ad 100644 --- a/misc/demo/modal.html +++ b/misc/demo/modal.html @@ -12,7 +12,7 @@ - +