1 | npm install bower-license --save-dev |
1 | var license = require('bower-license'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | var license = require('bower-license'), fs = require('fs'); module.exports = function (grunt) { 'use strict'; grunt.registerMultiTask('run_bower_license', 'Gather bower license report', function () { var options = this.options({ directory: 'bower_components', output: 'bower-license.csv' }), entry, item, prop, done, dependency; done = this.async(); console.log('Executing run_bower_license task'); // If output file already exists, will delete it if(grunt.file.exists(options.output)) { console.log('Output file already exists. Will delete it'); grunt.file.delete(options.output); } license.init(options, function (data) { for (entry in data) { item = { licenses: "", repository: "", homepage: "" }; for (prop in data[entry]) { if (prop === 'licenses') { item.licenses = data[entry][prop]; } else if (prop === 'repository') { item.repository = data[entry][prop]; if (item.repository.constructor === Object) { item.repository = item.repository.url; } } else if (prop === 'homepage') { item.homepage = data[entry][prop]; } } item.version = entry.substring(entry.indexOf('@') + 1, entry.length); item.name = entry.substring(0, entry.indexOf('@')); dependency = item.name + ',' + item.version + ',' + item.repository + ',' + item.licenses; if(item.homepage) { dependency += ',' + item.homepage; } fs.appendFileSync(options.output, dependency + '\r\n'); } console.log('End of run_bower_license task'); done(); }); }); }; |
1 | grunt.registerTask('client-side-license', ['run_bower_license:all']); |
1 | grunt client-side-license |
1 2 3 4 5 6 | Running "run_bower_license:all" (run_bower_license) task Executing run_bower_license task Output file already exists. Will delete it End of run_bower_license task Done, without errors. |
1 | grunt.registerTask('client-side-license', ['run_bower_license:all']); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), license_finder: { dev: { options: { production: false, out: 'npm-dev-licenses.csv', csv: true } }, prod: { options: { production: true, out: 'npm-prod-licenses.csv', csv: true } } }, run_bower_license: { all: { options: { directory: 'bower_components', output: 'bower-license.csv' } } } }); grunt.task.loadTasks('build_tasks'); grunt.loadNpmTasks('grunt-license-finder'); grunt.registerTask('server-side-license', ['license_finder:dev', 'license_finder:prod']); grunt.registerTask('client-side-license', ['run_bower_license:all']); grunt.registerTask('get-licenses', ['server-side-license', 'client-side-license']); }; |
1 | grunt get-licenses |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Running "license_finder:dev" (license_finder) task Retrieved license information License information written to: npm-dev-licenses.csv Running "license_finder:prod" (license_finder) task Retrieved license information License information written to: npm-prod-licenses.csv Running "run_bower_license:all" (run_bower_license) task Executing run_bower_license task Output file already exists. Will delete it End of run_bower_license task Done, without errors. |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |