Skip to content

Commit

Permalink
add license for build files (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanganjuan authored Feb 7, 2023
1 parent 06002e2 commit 76e2732
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
74 changes: 74 additions & 0 deletions hugegraph-hubble/hubble-fe/add-license.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

var fs = require('fs')
var path = require('path')
const license = `/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements; and to You under the Apache License, Version 2.0.
*/
`
const license_html = `<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements; and to You under the Apache License, Version 2.0.
-->`

const full_license = `/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
`
// str 以 key 结尾
function _endWith(str, key){
var reg = new RegExp(key + '$')
return reg.test(str)
}
function walkSync(currentDirPath, callback){
fs.readdirSync(currentDirPath, { withFileTypes: true }).forEach(function(dirent) {
var filePath = path.join(currentDirPath, dirent.name)
if (dirent.isFile()) {
callback(filePath, dirent)
} else if (dirent.isDirectory()) {
walkSync(filePath, callback)
}
});
}
walkSync('build', function(a, b) {
if (_endWith(b.name, '.js') || _endWith(b.name, '.html') || _endWith(b.name, '.css')) {
var data = fs.readFileSync(a).toString().split('\n')
let _license = _endWith(b.name, '.html') ? license_html : license
if (b.name === 'service-worker.js') {
_license = full_license
}
data.splice(0, 0, _license)
var text = data.join("\n")
fs.writeFileSync(a, text)
}
})

5 changes: 3 additions & 2 deletions hugegraph-hubble/hubble-fe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
"build": "react-app-rewired build && npm run license",
"test": "react-app-rewired test",
"license": "node add-license.js"
},
"browserslist": {
"production": [
Expand Down

0 comments on commit 76e2732

Please sign in to comment.