yptools 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/bin/yptools +4 -0
  3. data/lib/yptools/help/yp_help.rb +16 -0
  4. data/lib/yptools/install/mvvm/install-template.sh +15 -0
  5. data/lib/yptools/install/mvvm/kMVVM.xctemplate/NSObjectObjective-C/___FILEBASENAME___.h +11 -0
  6. data/lib/yptools/install/mvvm/kMVVM.xctemplate/NSObjectObjective-C/___FILEBASENAME___.m +7 -0
  7. data/lib/yptools/install/mvvm/kMVVM.xctemplate/NSObjectSwift/___FILEBASENAME___.swift +7 -0
  8. data/lib/yptools/install/mvvm/kMVVM.xctemplate/TemplateIcon.png +0 -0
  9. data/lib/yptools/install/mvvm/kMVVM.xctemplate/TemplateIcon@2x.png +0 -0
  10. data/lib/yptools/install/mvvm/kMVVM.xctemplate/TemplateInfo.plist +224 -0
  11. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewObjective-C/___FILEBASENAME___.h +11 -0
  12. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewObjective-C/___FILEBASENAME___.m +7 -0
  13. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewSwift/___FILEBASENAME___.swift +7 -0
  14. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewXIBObjective-C/___FILEBASENAME___.h +11 -0
  15. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewXIBObjective-C/___FILEBASENAME___.m +12 -0
  16. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewXIBObjective-C/___FILEBASENAME___.xib +17 -0
  17. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.swift +12 -0
  18. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.xib +17 -0
  19. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellObjective-C/___FILEBASENAME___.h +11 -0
  20. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellObjective-C/___FILEBASENAME___.m +7 -0
  21. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellSwift/___FILEBASENAME___.swift +7 -0
  22. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellXIBObjective-C/___FILEBASENAME___.h +11 -0
  23. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellXIBObjective-C/___FILEBASENAME___.m +12 -0
  24. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellXIBObjective-C/___FILEBASENAME___.xib +21 -0
  25. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.swift +12 -0
  26. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.xib +21 -0
  27. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerObjective-C/___FILEBASENAME___.h +11 -0
  28. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerObjective-C/___FILEBASENAME___.m +87 -0
  29. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerSwift/___FILEBASENAME___.swift +83 -0
  30. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerXIBObjective-C/___FILEBASENAME___.h +11 -0
  31. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerXIBObjective-C/___FILEBASENAME___.m +87 -0
  32. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerXIBObjective-C/___FILEBASENAME___.xib +31 -0
  33. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.swift +83 -0
  34. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.xib +31 -0
  35. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellObjective-C/___FILEBASENAME___.h +11 -0
  36. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellObjective-C/___FILEBASENAME___.m +26 -0
  37. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellSwift/___FILEBASENAME___.swift +18 -0
  38. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellXIBObjective-C/___FILEBASENAME___.h +11 -0
  39. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellXIBObjective-C/___FILEBASENAME___.m +18 -0
  40. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellXIBObjective-C/___FILEBASENAME___.xib +21 -0
  41. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.swift +18 -0
  42. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.xib +21 -0
  43. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerObjective-C/___FILEBASENAME___.h +11 -0
  44. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerObjective-C/___FILEBASENAME___.m +87 -0
  45. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerSwift/___FILEBASENAME___.swift +84 -0
  46. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerXIBObjective-C/___FILEBASENAME___.h +11 -0
  47. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerXIBObjective-C/___FILEBASENAME___.m +103 -0
  48. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerXIBObjective-C/___FILEBASENAME___.xib +26 -0
  49. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.swift +84 -0
  50. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.xib +26 -0
  51. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___FILEBASENAME___.h +11 -0
  52. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___FILEBASENAME___.m +94 -0
  53. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_Proxy___.h +15 -0
  54. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_Proxy___.m +39 -0
  55. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_TableViewCell___.h +11 -0
  56. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_TableViewCell___.m +30 -0
  57. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_ViewModel___.h +24 -0
  58. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerObjective-C/___VARIABLE_ViewModel___.m +51 -0
  59. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerSwift/___FILEBASENAME___.swift +24 -0
  60. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerXIBObjective-C/___FILEBASENAME___.h +9 -0
  61. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerXIBObjective-C/___FILEBASENAME___.m +61 -0
  62. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerXIBObjective-C/___FILEBASENAME___.xib +43 -0
  63. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.swift +24 -0
  64. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.xib +22 -0
  65. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewObjective-C/___FILEBASENAME___.h +11 -0
  66. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewObjective-C/___FILEBASENAME___.m +26 -0
  67. data/lib/yptools/install/mvvm/kMVVM.xctemplate/UIViewSwift/___FILEBASENAME___.swift +15 -0
  68. data/lib/yptools/install/yp_install.rb +40 -0
  69. data/lib/yptools/log/yp_log.rb +11 -0
  70. data/lib/yptools/mgc/yp_makegarbagecode.rb +278 -0
  71. data/lib/yptools.rb +68 -0
  72. metadata +156 -0
@@ -0,0 +1,61 @@
1
+ //___FILEHEADER___
2
+
3
+ #import "___FILEBASENAME___.h"
4
+ #import "KKLabelModel.h"
5
+ #import "KKLabelTableViewCell.h"
6
+
7
+ @interface ___FILEBASENAMEASIDENTIFIER___ ()
8
+ @property (strong, nonatomic) NSMutableArray <KKLabelModel *> *datas;
9
+ @property (weak , nonatomic) IBOutlet UITableView *tableView;
10
+
11
+ @end
12
+
13
+ @implementation ___FILEBASENAMEASIDENTIFIER___
14
+
15
+ - (void)viewDidLoad {
16
+ [super viewDidLoad];
17
+ // Do any additional setup after loading the view from its nib.
18
+ self.title = @"kk";
19
+ [self setupSubviews];
20
+ //异步处理消耗内存操作
21
+ [self reloadDatas];
22
+ }
23
+ - (void)setupSubviews{
24
+ [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
25
+ [self.tableView registerNib:[UINib nibWithNibName:@"KKLabelTableViewCell" bundle:nil] forCellReuseIdentifier:@"KKLabelTableViewCell"];
26
+ }
27
+ - (void)reloadDatas{
28
+ [self.datas removeAllObjects];
29
+ //构造cell
30
+ NSArray *items = [UIFont familyNames];
31
+ for (NSString *item in items) {
32
+ KKLabelModel *element = [[KKLabelModel alloc] initWithTitle:item value:nil];
33
+ [self.datas addObject:element];
34
+ }
35
+ [self.tableView reloadData];
36
+ }
37
+ #pragma mark - lazy load
38
+ - (NSMutableArray<KKLabelModel *> *)datas{
39
+ if (!_datas) {
40
+ _datas = [[NSMutableArray alloc] init];
41
+ }
42
+ return _datas;
43
+ }
44
+ #pragma mark - UITableViewDelegate,UITableViewDataSource
45
+ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
46
+ KKLabelModel *cellModel = self.datas[indexPath.row];
47
+ KKLabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KKLabelTableViewCell"];
48
+ cell.cellModel = cellModel;
49
+ return cell;
50
+ }
51
+ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
52
+ return self.datas.count;
53
+ }
54
+ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
55
+ return AdaptedWidth(44.f);
56
+ }
57
+ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
58
+ //to do
59
+ }
60
+ #pragma mark - aciton
61
+ @end
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3
+ <device id="retina6_1" orientation="portrait">
4
+ <adaptation id="fullscreen"/>
5
+ </device>
6
+ <dependencies>
7
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
8
+ <capability name="Safe area layout guides" minToolsVersion="9.0"/>
9
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10
+ </dependencies>
11
+ <objects>
12
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="___FILEBASENAMEASIDENTIFIER___">
13
+ <connections>
14
+ <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
15
+ <outlet property="tableView" destination="RgW-br-jlM" id="JSc-pB-5nQ"/>
16
+ </connections>
17
+ </placeholder>
18
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19
+ <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
20
+ <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
21
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
22
+ <subviews>
23
+ <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="RgW-br-jlM">
24
+ <rect key="frame" x="0.0" y="44" width="414" height="818"/>
25
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
26
+ <connections>
27
+ <outlet property="dataSource" destination="-1" id="idZ-U9-ceJ"/>
28
+ <outlet property="delegate" destination="-1" id="Y8b-7l-54f"/>
29
+ </connections>
30
+ </tableView>
31
+ </subviews>
32
+ <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
33
+ <constraints>
34
+ <constraint firstItem="RgW-br-jlM" firstAttribute="leading" secondItem="Q5M-cg-NOt" secondAttribute="leading" id="3vA-A9-GH5"/>
35
+ <constraint firstItem="RgW-br-jlM" firstAttribute="trailing" secondItem="Q5M-cg-NOt" secondAttribute="trailing" id="Jc6-5c-lfV"/>
36
+ <constraint firstItem="RgW-br-jlM" firstAttribute="bottom" secondItem="Q5M-cg-NOt" secondAttribute="bottom" id="Y6T-Nt-a38"/>
37
+ <constraint firstItem="RgW-br-jlM" firstAttribute="top" secondItem="Q5M-cg-NOt" secondAttribute="top" id="Zel-fQ-otC"/>
38
+ </constraints>
39
+ <viewLayoutGuide key="safeArea" id="Q5M-cg-NOt"/>
40
+ <point key="canvasLocation" x="-174" y="96"/>
41
+ </view>
42
+ </objects>
43
+ </document>
@@ -0,0 +1,24 @@
1
+ //___FILEHEADER___
2
+
3
+ import UIKit
4
+
5
+ class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ {
6
+
7
+ override func viewDidLoad() {
8
+ super.viewDidLoad()
9
+
10
+ // Do any additional setup after loading the view.
11
+ }
12
+
13
+
14
+ /*
15
+ // MARK: - Navigation
16
+
17
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
18
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
19
+ // Get the new view controller using segue.destination.
20
+ // Pass the selected object to the new view controller.
21
+ }
22
+ */
23
+
24
+ }
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3
+ <dependencies>
4
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
5
+ <capability name="Safe area layout guides" minToolsVersion="9.0"/>
6
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7
+ </dependencies>
8
+ <objects>
9
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="___FILEBASENAMEASIDENTIFIER___" customModuleProvider="target">
10
+ <connections>
11
+ <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
12
+ </connections>
13
+ </placeholder>
14
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15
+ <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
16
+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
17
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18
+ <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
19
+ <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
20
+ </view>
21
+ </objects>
22
+ </document>
@@ -0,0 +1,11 @@
1
+ //___FILEHEADER___
2
+
3
+ ___IMPORTHEADER_cocoaTouchSubclass___
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @interface ___FILEBASENAMEASIDENTIFIER___ : ___VARIABLE_cocoaTouchSubclass___
8
+
9
+ @end
10
+
11
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,26 @@
1
+ //___FILEHEADER___
2
+
3
+ #import "___FILEBASENAME___.h"
4
+
5
+ @interface ___FILEBASENAMEASIDENTIFIER___ ()
6
+
7
+ @end
8
+
9
+ @implementation ___FILEBASENAMEASIDENTIFIER___
10
+
11
+ - (instancetype)init{
12
+ if (self = [super init]) {
13
+ [self setupSubviews];
14
+ }
15
+ return self;
16
+ }
17
+
18
+ - (void)setupSubviews{
19
+ //to do
20
+ }
21
+
22
+ - (void)layoutSubviews{
23
+ [super layoutSubviews];
24
+ }
25
+
26
+ @end
@@ -0,0 +1,15 @@
1
+ //___FILEHEADER___
2
+
3
+ import UIKit
4
+
5
+ class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ {
6
+
7
+ /*
8
+ // Only override draw() if you perform custom drawing.
9
+ // An empty implementation adversely affects performance during animation.
10
+ override func draw(_ rect: CGRect) {
11
+ // Drawing code
12
+ }
13
+ */
14
+
15
+ }
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'colored'
5
+ require_relative '../mgc/yp_makegarbagecode'
6
+
7
+ class YPInstall
8
+
9
+ def self.install(name)
10
+
11
+ templates_url = "git@github.com:HansenCCC/kMVVM.git"
12
+ templates_path = Dir.pwd
13
+ templates_name = "kMVVM"
14
+
15
+ templates_path = templates_path + "/#{templates_name}"
16
+ yp_log_doing "生成临时文件#{templates_path}"
17
+
18
+ # 删除旧库
19
+ yp_method_rmdir templates_path
20
+
21
+ system("git clone #{templates_url}")
22
+ FileUtils.cd 'kMVVM'
23
+ system("sh install-template.sh")
24
+ FileUtils.cd '..'
25
+
26
+ # 删除缓存
27
+ yp_method_rmdir templates_path
28
+ yp_log_doing "移除临时文件#{templates_path}"
29
+ yp_log_success "安装#{templates_url}完成,重新打开Xcode才能生效"
30
+
31
+ end
32
+
33
+ end
34
+
35
+
36
+ #mkdir -p ~/Library/Developer/Xcode/Templates/Source/
37
+ #
38
+ #rm -rf dir ~/Library/Developer/Xcode/Templates/Source/kMVVM.xctemplate
39
+ #
40
+ #cp -R kMVVM.xctemplate ~/Library/Developer/Xcode/Templates/Source/kMVVM.xctemplate
@@ -0,0 +1,11 @@
1
+ def yp_log_success (log)
2
+ puts log.green
3
+ end
4
+
5
+ def yp_log_fail (log)
6
+ puts log.red
7
+ end
8
+
9
+ def yp_log_doing (log)
10
+ puts log.yellow
11
+ end
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/ruby
2
+ require 'pathname'
3
+ require 'colored'
4
+ require_relative '../log/yp_log'
5
+
6
+ ## 需要忽略的文件或者文件夹
7
+ def yp_method_ignoringFiles
8
+ return ".", "..", ".DS_Store", "Pods", "LocalPods", "main.m", "doc"
9
+ end
10
+
11
+ # 正则查询文件列表,path:传路径 script:正则表达式 ignoringFiles:忽略的文件或者文件夹 retun [{文件名:文件路径},{文件名2:文件路径2}]
12
+ def yp_method_fileList (path,script,ignoringFiles)
13
+
14
+ unless File.directory?(path)
15
+ return
16
+ end
17
+
18
+ unless path =~ /(\/$)/
19
+ path = path + "/"
20
+ end
21
+
22
+ fileList = Array.new
23
+ Dir.entries(path).each do |sub|
24
+ unless ignoringFiles.include?(sub)
25
+ subPath = path + sub;
26
+ if File.directory?(subPath)
27
+ subFileList = yp_method_fileList subPath, script, ignoringFiles
28
+ fileList = fileList + subFileList;
29
+ else
30
+ if subPath =~ script
31
+ obj = Hash.new
32
+ obj[sub] = subPath
33
+ fileList.push(obj)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ return fileList
41
+ end
42
+
43
+ # 删除文件夹(包括文件夹下面的文件)
44
+ def yp_method_rmdir (path)
45
+ if File.exists?(path)
46
+ if File.directory?(path)
47
+ Dir.foreach(path) do |subPath|
48
+ if subPath != '.' and subPath != '..'
49
+ tempSubPath = File.join(path, subPath)
50
+ yp_method_rmdir(tempSubPath)
51
+ end
52
+ end
53
+ Dir.rmdir(path)
54
+ else
55
+ File.delete(path)
56
+ end
57
+ end
58
+ end
59
+
60
+ # 创建文件夹
61
+ def yp_method_mkdir (path)
62
+ Dir.mkdir(path)
63
+ end
64
+
65
+
66
+
67
+ # 根据.m文件创建垃圾代码
68
+ def yp_method_ceateGarbageCodeByObjC_m(path,outPath,suffix)
69
+
70
+ pathFile = File.open(path, "r")
71
+
72
+ maxLineThreshold = 10000
73
+ fileLine = 0
74
+
75
+ fileName = File.basename(path,".*")
76
+
77
+ mainStringH = "@interface " + fileName + " (#{suffix})"
78
+ mainStringM = "@implementation " + fileName + " (#{suffix})"
79
+
80
+ importStringsH = Array.new
81
+ importStringsM = Array.new
82
+
83
+ methodStringsH = Array.new
84
+ methodStringsM = Array.new
85
+
86
+ pathFileStrings = Array.new
87
+
88
+ isClass = 0
89
+
90
+ while textLine = pathFile.gets
91
+ fileLine += 1
92
+
93
+ if pathFileStrings.include?(textLine)
94
+ next
95
+ end
96
+
97
+ if textLine.include?("@implementation #{fileName}")
98
+ isClass = 1
99
+ end
100
+
101
+ pathFileStrings.push(textLine)
102
+
103
+ if textLine.include?("#import")
104
+ importStringsH.push(textLine)
105
+ elsif textLine.start_with?("-(") | textLine.start_with?("- (")
106
+
107
+ if textLine.include?("API_AVAILABLE")
108
+ next
109
+ end
110
+
111
+ textLine = textLine.sub(" \{","\{")
112
+ textLine = textLine.sub("\n","")
113
+
114
+ unless textLine.include?("{")
115
+ textLine = textLine + "{"
116
+ end
117
+
118
+ returnStringM = ""
119
+ if textLine.include?("-(void") | textLine.include?("- (void")
120
+ returnStringM = " return;"
121
+ elsif textLine.include?("- (IBAction") | textLine.include?("-(IBAction")
122
+ returnStringM = " return;"
123
+ elsif textLine.include?("- (CGFloat") | textLine.include?("-(CGFloat")
124
+ returnStringM = " return 0.f;"
125
+ elsif textLine.include?("- (CGRect") | textLine.include?("-(CGRect")
126
+ returnStringM = " return CGRectZero;"
127
+ elsif textLine.include?("- (CGSize") | textLine.include?("-(CGSize")
128
+ returnStringM = " return CGSizeZero;"
129
+ elsif textLine.include?("- (UIEdgeInsets") | textLine.include?("-(UIEdgeInsets")
130
+ returnStringM = " return UIEdgeInsetsZero;"
131
+ else
132
+ next
133
+ end
134
+
135
+ # .h 文件生成
136
+ replaceStringH = ""
137
+ if textLine.include?(":")
138
+ replaceStringH = " " + suffix + ":(NSString *)" + suffix + ";"
139
+ else
140
+ replaceStringH = suffix + ":(NSString *)" + suffix + ";"
141
+ end
142
+
143
+ tempTextLineH = textLine.sub("\{",replaceStringH)
144
+ methodStringsH.push("/// " + suffix)
145
+ methodStringsH.push("\n")
146
+ methodStringsH.push(tempTextLineH)
147
+ methodStringsH.push("\n")
148
+ methodStringsH.push("\n")
149
+
150
+ # .m 文件生成
151
+ replaceStringM = ""
152
+ if textLine.include?(":")
153
+ replaceStringM = " " + suffix + ":(NSString *)" + suffix + "\ {"
154
+ else
155
+ replaceStringM = suffix + ":(NSString *)" + suffix + "\ {"
156
+ end
157
+
158
+ tempTextLineM = textLine.sub("\{",replaceStringM)
159
+ methodStringsM.push("/// " + suffix)
160
+ methodStringsM.push("\n")
161
+ methodStringsM.push(tempTextLineM)
162
+ methodStringsM.push("\n")
163
+ methodStringsM.push(" NSLog(@\"%@\",#{suffix});")
164
+ methodStringsM.push("\n")
165
+ methodStringsM.push(returnStringM)
166
+ methodStringsM.push("\n")
167
+ methodStringsM.push("}")
168
+ methodStringsM.push("\n")
169
+ methodStringsM.push("\n")
170
+ end
171
+
172
+ end
173
+
174
+ if isClass != 1
175
+ return
176
+ end
177
+
178
+ importStringsH.push("\n")
179
+ importStringsH.push(mainStringH)
180
+ importStringsH.push("\n")
181
+ importStringsH.push("\n")
182
+ methodStringsH.push("@end")
183
+
184
+ file_h = importStringsH + methodStringsH
185
+
186
+
187
+ importStringsM.push("#import \"#{fileName}+#{suffix}.h\"")
188
+ importStringsM.push("\n")
189
+ importStringsM.push("\n")
190
+ importStringsM.push(mainStringM)
191
+ importStringsM.push("\n")
192
+ importStringsM.push("\n")
193
+ methodStringsM.push("@end")
194
+
195
+ file_m = importStringsM + methodStringsM
196
+
197
+ unless outPath =~ /(\/$)/
198
+ outPath = outPath + "/"
199
+ end
200
+
201
+ filePathH = outPath + fileName + "+#{suffix}.h"
202
+ filePathM = outPath + fileName + "+#{suffix}.m"
203
+
204
+ createFileH = File.new(filePathH,"w+")
205
+ file_h.each {|lineTest|
206
+ createFileH.syswrite(lineTest)
207
+ }
208
+
209
+ createFileM = File.new(filePathM,"w+")
210
+ file_m.each {|lineTest|
211
+ createFileM.syswrite(lineTest)
212
+ }
213
+
214
+ pathFile.close
215
+ end
216
+
217
+ # 生成垃圾数据
218
+ def yp_method_makeGarbage (path, outPath, suffix)
219
+ # 筛选文件的正则
220
+ script = /^(?!.*(\+)).*.(\.m)$/
221
+ # 配置忽略文件
222
+ ignoringFiles = yp_method_ignoringFiles
223
+ # 获取符合条件的文件列表
224
+ fileList = yp_method_fileList path, script, ignoringFiles
225
+
226
+ fileList.each { |fileDic|
227
+ fileDic.each { |key, value|
228
+ createTime = Time.new
229
+ fileName = File.basename(value,".*")
230
+ filePathH = fileName + "+#{suffix}.h"
231
+ filePathM = fileName + "+#{suffix}.m"
232
+ yp_log_success createTime.inspect + " 生成 " + filePathH + "、" + filePathM + " 完成"
233
+
234
+ yp_method_ceateGarbageCodeByObjC_m(value,outPath,suffix)
235
+ }
236
+ }
237
+ end
238
+
239
+
240
+ # 生成垃圾数据
241
+ def yp_tools_method_makeGarbage (suffix)
242
+
243
+ yp_log_doing "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀";
244
+
245
+ yp_path = `pwd`
246
+ yp_path = yp_path.sub("\n","")
247
+ yp_outPath = "#{yp_path}/" + suffix
248
+
249
+ yp_log_doing "当前目录 #{yp_path}"
250
+ yp_log_doing "垃圾代码生成目录 #{yp_outPath}"
251
+ yp_log_doing "后缀 #{suffix}"
252
+
253
+ if suffix.length == 0
254
+ yp_log_fail "后缀不能为空"
255
+ return
256
+ end
257
+
258
+ yp_isTruePath = 0
259
+ Dir.entries(yp_path).each do |subFile|
260
+ if subFile.include?(".xcodeproj") | subFile.include?(".xcworkspace")
261
+ yp_isTruePath = 1
262
+ break
263
+ end
264
+ end
265
+
266
+ if yp_isTruePath == 0
267
+ yp_log_fail "#{yp_path} " + "此目录没有工程,请切换到项目目录下再执行 'yptools mgc ..' 命令"
268
+ return
269
+ end
270
+
271
+ yp_method_rmdir yp_outPath
272
+ yp_method_mkdir yp_outPath
273
+ yp_method_makeGarbage yp_path, yp_outPath, suffix
274
+
275
+ yp_log_doing "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀";
276
+ end
277
+
278
+ #yp_tools_method_makeGarbage "suffix"
data/lib/yptools.rb ADDED
@@ -0,0 +1,68 @@
1
+ require_relative 'yptools/mgc/yp_makegarbagecode'
2
+ require_relative 'yptools/help/yp_help'
3
+ require_relative 'yptools/log/yp_log'
4
+ require_relative 'yptools/install/yp_install'
5
+
6
+ class YPTools
7
+
8
+ def self.cmd_dispatch(argvs)
9
+ cmd = argvs[0]
10
+ case cmd
11
+ when 'help'
12
+ YPTools.help
13
+ when 'mgc'
14
+ if argvs.size > 1
15
+ suffix = argvs[1]
16
+ YPTools.mgc suffix
17
+ else
18
+ yp_log_fail "'yptools mgc ..' 参数缺失"
19
+ self.help
20
+ end
21
+ when 'install'
22
+ if argvs.size > 1
23
+ name = argvs[1]
24
+ YPTools.install name
25
+ else
26
+ yp_log_fail "'yptools install ..' 参数缺失"
27
+ self.help
28
+ end
29
+ when 'mvvm'
30
+ YPTools.mvvm
31
+ else
32
+ YPTools.help
33
+ end
34
+
35
+ end
36
+
37
+ def self.help
38
+ YPHelp.message
39
+ end
40
+
41
+ def self.mgc(suffix)
42
+ yp_tools_method_makeGarbage suffix
43
+ end
44
+
45
+ def self.install(name)
46
+ YPInstall.install(name)
47
+ end
48
+
49
+ end
50
+
51
+ #puts "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀";
52
+ #
53
+ #path = "/Users/Hansen/Desktop/QMKKXProduct"
54
+ #outPath = "/Users/Hansen/Desktop/QMKKXProduct/CHS"
55
+ #suffix = "YPYP"
56
+ #
57
+ #yp_method_rmdir outPath
58
+ #yp_method_mkdir outPath
59
+ #yp_method_makeGarbage path, outPath, suffix
60
+ #
61
+ #puts "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀";
62
+
63
+ #yptools = YPTools.new
64
+ #
65
+
66
+
67
+ #YPTools.cmd_dispatch(ARGV)
68
+