2017-08-28 3 views
1

私は現在オープンソースでなければならないプロジェクトに取り組んでおり、各ファイルの先頭にApacheライセンス文字列を追加する必要があります。ファイルの先頭に特定の文字列がある場合、各ファイルをチェックするtslint

私のtslintは、特定の文字列が各typescriptファイルの先頭にあるかどうかをチェックし、その文字列が存在しない場合はエラーを表示します。

/* 
* Copyright 2017 proje*** contributors 
* 
* Licensed 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 
* 

文字列が存在するかどうかを確認するためのTSリント設定がありませんでした。

私はそれを達成する方法はありますか?

答えて

0

私は多くのオプションを見直した後、私たちのコードにpre-commitフックを置き、リポジトリでコミットを試みる前に実行するノードスクリプトを設定しました。

それがより簡単になりますし、あなたが簡単に実行するスクリプト2.develop

1.installモジュール

npm i --save-dev pre-commit 

を行うことができますnpmjsで利用可能なモジュールがありますあなたのコードに特定の痕跡を見つけるためのプロコミットフックとして。 package.json

{ 
    "name": "project-name", 
    "version": 1.0.0", 
    "license": "Apache 2.0", 
    "scripts": { 
    "license-check": "node license-check", 
    }, 
    "private": true, 
    "dependencies": { 
    }, 
    "devDependencies": { 
    "pre-commit": "1.2.2", 
    }, 
    "pre-commit": [ 
    "license-check" 
    ] 
} 
で実行されるフック3.place

// code to find specific string 
(function() { 
    var fs = require('fs'); 
    var glob = require('glob-fs')(); 
    var path = require('path'); 
    var result = 0; 
    var exclude = ['LICENSE', 
    path.join('e2e', 'util', 'db-ca', 'rds-combined-ca-bundle.pem'), 
    path.join('src', 'favicon.ico')]; 
    var files = []; 
    files = glob.readdirSync('**'); 
    files.map((file) => { 
    try { 
     if (!fs.lstatSync(file).isDirectory() && file.indexOf('.json') === -1 
      && exclude.indexOf(file) === -1) { 
     var data = fs.readFileSync(file, 'utf8'); 

     if (data.indexOf('Copyright 2017 candifood contributors') === -1) { 
      console.log('Please add License text in coment in the file ' + file); 
      result = 1; 
     } 
     } 
    } catch (e) { 
     console.log('Error:', e.stack); 
    } 
    }); 
    process.exit(result); 
})(); 

関連する問題