node.js小工具--修改Xcode 'Create by'作者名称
2016-03-22 17:00
429 查看
简介
用Xcode创建源文件时会自动在文件开始位置加入如下注释:// // ISSImageCycleScrollView.m // SoftTravel // // Created by iss110302000283 on 16/2/26. // Copyright © 2016年 issuser. All rights reserved. //
原理
这个其实是通过Xcode的代码模板(Template)生成的,Xcode的Template目录在这个目录:/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source
打开这个目录,可以看到各种文件对应的模板文件,例如:
// // ___FILENAME___ // ___PROJECTNAME___ // // Created by ___FULLUSERNAME___ on ___DATE___. //___COPYRIGHT___ // #import <Foundation/Foundation.h> @protocol ___FILEBASENAMEASIDENTIFIER___ <NSObject> @end
___FULLUSERNAME___就是作者名,修改此模板后,在Xcode中创建相应文件时就会生效
批量脚本
这里提供一个node.js的脚本,批量修改Xcode的模板,将 ___FULLUSERNAME___作者名修改成我们想要的:// updateXcodeTemplate.js const fs = require('fs'); const path = require('path'); // 需要修改的模板文件后缀名 const extArray = [".h", ".m", ".cpp", ".hpp", ".swift", ".c"] function updateTemplateFile(filePath) { var stat = fs.statSync(filePath); if(stat.isFile()) { if(extArray.indexOf(path.extname(filePath)) != -1) { var str = fs.readFileSync(filePath).toString(); // 替换作者名 var newStr = str.replace(/___FULLUSERNAME___/g, '张学友(___FULLUSERNAME___)'); if(str != newStr) { fs.writeFileSync(filePath, newStr); console.log("update file: " + filePath); } } } else if(stat.isDirectory()) { // 如果是文件夹,则递归调用 var fileList = fs.readdirSync(filePath); for(var i = 0; i < fileList.length; i++) { updateTemplateFile(path.join(filePath, fileList[i])); } } } updateTemplateFile("/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source");
执行脚本:
// 注意需要用超级用户权限修改,否则会提示没有权限。 $ sudo node updateXcodeTemplate.js
相关文章推荐
- node.js 调试
- nodejs+express开发blog(1)
- Nodejs学习笔记(十三)— PM2
- hadoop启动报错-namenode无法启动-GC overhead limit exceeded
- NoNodeAvailableException[None of the configured nodes are available
- 安装node.js 及安装gulp步骤
- windows下搭建node.js及npm的工作环境
- Leetcode #19. Remove Nth Node From End of List 移除倒数第N个链表节点 解题小节
- node.js之回调函数示例
- DOM中所有节点类型(nodeType);(读书笔记)
- 222. Count Complete Tree Nodes
- nodejs aes加解密128算法,base64编码
- Node.js文件操作方法汇总
- 24. Swap Nodes in Pairs
- [Leetcode]237. Delete Node in a Linked List
- node本地分享web服务
- Modules-nodejs
- heroku安装和nodejs程序部署
- 路径 (Path)–nodejs
- 最好的简明NodeJS学习材料