-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic support for common languages
- Loading branch information
Showing
39 changed files
with
4,221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false | ||
|
||
[*.ts] | ||
indent_size = 4 | ||
quote_type = single | ||
curly_bracket_next_line = true | ||
indent_brace_style = Allman | ||
spaces_around_operators = true | ||
spaces_around_brackets = inside | ||
continuation_indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Automatically normalize line endings for all text-based files | ||
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion | ||
* text=auto | ||
|
||
# For the following file types, normalize line endings to LF on | ||
# checkin and prevent conversion to CRLF when they are checked out | ||
# (this is required in order to prevent newline related issues like, | ||
# for example, after the build script is run) | ||
.* text eol=lf | ||
*.css text eol=lf | ||
*.sass text eol=lf | ||
*.less text eol=lf | ||
*.scss text eol=lf | ||
*.html text eol=lf | ||
*.js text eol=lf | ||
*.ts text eol=lf | ||
*.json text eol=lf | ||
*.md text eol=lf | ||
*.sh text eol=lf | ||
*.txt text eol=lf | ||
*.xml text eol=lf | ||
*.yaml text eol=lf | ||
|
||
# Exclude the `.htaccess` file from GitHub's language statistics | ||
# https://github.com/github/linguist#using-gitattributes | ||
dist/.htaccess linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Node | ||
node_modules | ||
npm-debug.log | ||
|
||
# JetBrains | ||
.idea | ||
.project | ||
.settings | ||
*.iml | ||
|
||
# VS Code | ||
.vscode | ||
|
||
# Windows | ||
Thumbs.db | ||
Desktop.ini | ||
|
||
# Mac | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Build files | ||
dist | ||
|
||
yarn-error.log | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Node | ||
node_modules/* | ||
npm-debug.log | ||
docs/* | ||
# DO NOT IGNORE TYPESCRIPT FILES FOR NPM | ||
# TypeScript | ||
# *.js | ||
# *.map | ||
# *.d.ts | ||
|
||
# JetBrains | ||
.idea | ||
.project | ||
.settings | ||
.idea/* | ||
*.iml | ||
|
||
# VS Code | ||
.vscode/* | ||
|
||
# Windows | ||
Thumbs.db | ||
Desktop.ini | ||
|
||
# Mac | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Ngc generated files | ||
**/*.ngfactory.ts | ||
|
||
# Library files | ||
src/* | ||
src/ngx-tree/* | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
dist: trusty | ||
sudo: false | ||
|
||
language: node_js | ||
node_js: | ||
- "8" | ||
- "10" | ||
|
||
cache: | ||
yarn: true | ||
|
||
install: yarn | ||
|
||
script: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
"testMatch": ["**/test/*.test.js"], | ||
"testEnvironment": "node" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const gonzales = require('gonzales-pe'); | ||
|
||
const { generateBlockCommentContent } = require('./util') | ||
|
||
function render(source, template, syntax = 'css') { | ||
const parseTree = gonzales.parse(source, { | ||
syntax | ||
}); | ||
|
||
const commentNode = gonzales.createNode({ syntax, type: 'multilineComment', content: generateBlockCommentContent(template) }) | ||
const blankLineNode = gonzales.createNode({ | ||
type: 'space', | ||
content: '\n\n' | ||
}) | ||
parseTree.insert(0, blankLineNode) | ||
parseTree.insert(0, commentNode) | ||
|
||
|
||
return parseTree.toString() | ||
} | ||
|
||
module.exports = { | ||
render | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const recast = require('recast'); | ||
|
||
const {generateBlockCommentContent} = require('./util') | ||
|
||
const builders = recast.types.builders; | ||
|
||
function parse(source, parserType = 'babel') { | ||
return recast.parse(source, { | ||
parser: require(`recast/parsers/${parserType}`), | ||
}) | ||
} | ||
|
||
function print(ast) { | ||
return recast.print(ast, { | ||
lineTerminator: '\n' | ||
}).code | ||
} | ||
|
||
function appendCopyright(ast, crText) { | ||
const comment = builders.commentBlock(generateBlockCommentContent(crText)); | ||
|
||
const firstStatement = ast.program.body[0] | ||
|
||
if(firstStatement) { | ||
firstStatement.comments = firstStatement.leadingComments || [] | ||
|
||
firstStatement.comments.unshift(comment) | ||
} | ||
|
||
return ast | ||
} | ||
|
||
function detectCopyright(ast) { | ||
const leadingComment = ast.comments[0] | ||
|
||
if(leadingComment) { | ||
|
||
} | ||
} | ||
|
||
function render(source, template, parserType) { | ||
const ast = parse(source, parserType) | ||
|
||
const alteredAst = appendCopyright(ast, template) | ||
|
||
return addBlankLineBetweenCopyrightAndCode(print(alteredAst)); | ||
} | ||
|
||
function addBlankLineBetweenCopyrightAndCode(fileString) { | ||
return fileString.replace(/\*\/$/m, '*/\n'); | ||
} | ||
|
||
module.exports = { | ||
render | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function generateBlockCommentContent(text, lineChar = '*', needTopChar = true) { | ||
return `${needTopChar ? lineChar : ''}\n${text.trim().split('\n').map(line => (` ${lineChar} ${line}`).trimRight()).join('\n')}\n ` | ||
} | ||
|
||
module.exports = { | ||
generateBlockCommentContent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const xmlCommentRegexp = /$(<!--([\s\S]*?)-->)/g; | ||
|
||
const xmlCommentContentRegexp = /<!--([\s\S]*?)-->/g; | ||
|
||
const { generateBlockCommentContent } = require('./util'); | ||
|
||
function render(source, template) { | ||
const comment = `<!--${generateBlockCommentContent(template, '-', false)}-->\n\n` | ||
|
||
const matches = xmlCommentRegexp.exec(source.trim()) | ||
|
||
let result | ||
|
||
if (!matches) { | ||
result = comment + source | ||
} | ||
|
||
return result | ||
} | ||
|
||
module.exports = { | ||
render | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const yaml = require('yaml'); | ||
|
||
function render(source, template) { | ||
const templateLines = template.split('\n') | ||
const comment = templateLines.map(line => (' ' + line).trimRight()).join('\n') | ||
|
||
const doc = yaml.parseDocument(source, { | ||
keepCstNodes: true | ||
}) | ||
|
||
doc.commentBefore = comment | ||
|
||
const preout = doc.toString() | ||
|
||
const lastTemplateLine = templateLines[templateLines.length - 1] | ||
|
||
return preout.replace(lastTemplateLine, lastTemplateLine + '\n') | ||
} | ||
|
||
module.exports = { | ||
render | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "copyrightizen", | ||
"version": "1.0.0", | ||
"description": "A tool generates designated copyright notice to target files with scope support like Intellij IDEs.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha", | ||
"jest": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/e-cloud/copyrightizen.git" | ||
}, | ||
"keywords": [ | ||
"copyright", | ||
"generate", | ||
"license" | ||
], | ||
"author": "e-cloud <saintscott119@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/e-cloud/copyrightizen/issues" | ||
}, | ||
"homepage": "https://github.com/e-cloud/copyrightizen#readme", | ||
"dependencies": { | ||
"@babel/parser": "^7.1.3", | ||
"@babel/traverse": "^7.1.4", | ||
"@babel/types": "^7.1.3", | ||
"fs-extra": "^7.0.0", | ||
"glob": "^7.1.3", | ||
"gonzales-pe": "^4.2.3", | ||
"recast": "^0.16.0", | ||
"yaml": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"chai-files": "^1.4.0", | ||
"jest": "^23.6.0", | ||
"mocha": "^5.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (C) xxx Systems, Inc - All Rights Reserved | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* Written by John Doe <jdoe@heaven.com>, 1984 | ||
* | ||
* From https://softwareengineering.stackexchange.com/a/68150/266765 | ||
*/ | ||
|
||
body { | ||
background-color: lightblue; | ||
} | ||
|
||
h1 { | ||
color: navy; | ||
margin-left: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
- Copyright (C) xxx Systems, Inc - All Rights Reserved | ||
- Unauthorized copying of this file, via any medium is strictly prohibited | ||
- Proprietary and confidential | ||
- Written by John Doe <jdoe@heaven.com>, 1984 | ||
- | ||
- From https://softwareengineering.stackexchange.com/a/68150/266765 | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Page Title</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1>This is a Heading</h1> | ||
<p>This is a paragraph.</p> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (C) xxx Systems, Inc - All Rights Reserved | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* Written by John Doe <jdoe@heaven.com>, 1984 | ||
* | ||
* From https://softwareengineering.stackexchange.com/a/68150/266765 | ||
*/ | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
module.exports = add; |
Oops, something went wrong.