[フレーム]
Last Updated: February 25, 2016
·
1.695K
· mhdaljuboori

Use ng-annotate for all files in directory and its contents recursively

Into

This is a simple script to run ng-annotate for all files in specific directory and all contents of directories inside that directory

NG-Annotate Uses

Adds and removes AngularJS dependency injection annotations. It is non-intrusive so your source code stays exactly the same otherwise. No lost comments or moved lines. (from GitHub)

Code

var sh = require('shelljs');

function annotateFile (filePath) {
 console.log('annotate ' + filePath);
 sh.exec('ng-annotate -a ' + filePath + ' -o ' + filePath);
}

function annotateFolder (folderPath) {
 console.log("annotate Folder " + folderPath);
 sh.cd(folderPath);
 var files = sh.ls() || [];

 for (var i=0; i<files.length; i++) {
 var file = files[i];
 if (file.match(/.*\.js$/))
 annotateFile(file);
 else if (!file.match(/.*\..*/)) {
 annotateFolder(file);
 sh.cd('../');
 }
 }
}
if (process.argv.slice(2)[0])
 annotateFolder(process.argv.slice(2)[0]);
else {
 console.log('There is no folder');
 console.log('--- node FILENAME.js FOLDER_PATH');
}

You also can find the code in this gist

Usage

You must installed NodeJS, ShellJS and ng-annotate of course.

$ npm install shelljs
$ npm install -g ng-annotate

Then you can simply run the script

$ node SCRIPT_FILE_NAME FOLDER_PATH

AltStyle によって変換されたページ (->オリジナル) /