Skip to content

Commit d7eb822

Browse files
committed
完善生成最终文件
1 parent 3121dd4 commit d7eb822

22 files changed

+515
-315
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CreateJSONFile.xcodeproj/project.pbxproj

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
2A13BBA723C1F9BD00463B23 /* FileDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A13BBA623C1F9BD00463B23 /* FileDataModel.swift */; };
11+
2A314EBA2491327B00C07461 /* RequestInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A314EB92491327B00C07461 /* RequestInputCell.swift */; };
12+
2A314F32249259A100C07461 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A314F31249259A100C07461 /* WindowController.swift */; };
1113
2A32CABF23C784E800E573A2 /* ContentSplitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A32CABE23C784E800E573A2 /* ContentSplitView.swift */; };
1214
2A33201B23C8A7E300A2F33B /* MainRightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33201A23C8A7E300A2F33B /* MainRightView.swift */; };
1315
2A33201D23C8E2E700A2F33B /* ContentBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33201C23C8E2E700A2F33B /* ContentBottomView.swift */; };
@@ -62,6 +64,8 @@
6264
/* Begin PBXFileReference section */
6365
2677991920C25402836F22F3 /* Pods-CreateJSONFileTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CreateJSONFileTests.debug.xcconfig"; path = "Target Support Files/Pods-CreateJSONFileTests/Pods-CreateJSONFileTests.debug.xcconfig"; sourceTree = "<group>"; };
6466
2A13BBA623C1F9BD00463B23 /* FileDataModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileDataModel.swift; sourceTree = "<group>"; };
67+
2A314EB92491327B00C07461 /* RequestInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestInputCell.swift; sourceTree = "<group>"; };
68+
2A314F31249259A100C07461 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
6569
2A32CABE23C784E800E573A2 /* ContentSplitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentSplitView.swift; sourceTree = "<group>"; };
6670
2A33201A23C8A7E300A2F33B /* MainRightView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainRightView.swift; sourceTree = "<group>"; };
6771
2A33201C23C8E2E700A2F33B /* ContentBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBottomView.swift; sourceTree = "<group>"; };
@@ -156,6 +160,7 @@
156160
2A2FE56F248E8BC300D7FCEE /* TopView */ = {
157161
isa = PBXGroup;
158162
children = (
163+
2A314EB82491325000C07461 /* Cell */,
159164
2A2FE576248E8F1500D7FCEE /* View */,
160165
2A33201E23C9C9B500A2F33B /* ContentTopView.swift */,
161166
);
@@ -258,6 +263,14 @@
258263
path = Model;
259264
sourceTree = "<group>";
260265
};
266+
2A314EB82491325000C07461 /* Cell */ = {
267+
isa = PBXGroup;
268+
children = (
269+
2A314EB92491327B00C07461 /* RequestInputCell.swift */,
270+
);
271+
path = Cell;
272+
sourceTree = "<group>";
273+
};
261274
2A32CA7C23C77A2900E573A2 /* Modules */ = {
262275
isa = PBXGroup;
263276
children = (
@@ -312,6 +325,7 @@
312325
CA55FF5223BF0CA700A00C97 /* GenerateModel */,
313326
CA301A7123BB21BE00F27C26 /* AppDelegate.swift */,
314327
CA301A7323BB21BE00F27C26 /* ViewController.swift */,
328+
2A314F31249259A100C07461 /* WindowController.swift */,
315329
CA301A7523BB21C300F27C26 /* Assets.xcassets */,
316330
CA301A7723BB21C300F27C26 /* Main.storyboard */,
317331
CA301A7A23BB21C300F27C26 /* Info.plist */,
@@ -611,6 +625,8 @@
611625
CA00A67623D01206003D8E41 /* RequestParamsViewController.swift in Sources */,
612626
2A13BBA723C1F9BD00463B23 /* FileDataModel.swift in Sources */,
613627
2A32CABF23C784E800E573A2 /* ContentSplitView.swift in Sources */,
628+
2A314F32249259A100C07461 /* WindowController.swift in Sources */,
629+
2A314EBA2491327B00C07461 /* RequestInputCell.swift in Sources */,
614630
CAEDC92923C87F7C00DC3617 /* MainSplitView.swift in Sources */,
615631
CA55FF5C23BF34A600A00C97 /* HomeData+Extension.swift in Sources */,
616632
CA00A67A23D0121A003D8E41 /* RequestHeadersViewController.swift in Sources */,

CreateJSONFile/AppDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2525
// window?.makeKeyAndOrderFront(nil)
2626
// window?.center()
2727
// window?.contentViewController = HomeSplitViewController()
28+
2829
//
2930
}
3031

CreateJSONFile/Base.lproj/Main.storyboard

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="5AO-7l-2Ld">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="5AO-7l-2Ld">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097"/>
55
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
66
</dependencies>
77
<scenes>
@@ -688,7 +688,7 @@
688688
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
689689
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
690690
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
691-
<rect key="screenRect" x="0.0" y="0.0" width="2048" height="1129"/>
691+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
692692
<connections>
693693
<outlet property="delegate" destination="5AO-7l-2Ld" id="MMx-JS-XbX"/>
694694
</connections>
@@ -699,7 +699,7 @@
699699
</windowController>
700700
<customObject id="Oyw-C7-Htp" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
701701
</objects>
702-
<point key="canvasLocation" x="61" y="90"/>
702+
<point key="canvasLocation" x="63" y="118"/>
703703
</scene>
704704
<!--Home View Controller-->
705705
<scene sceneID="52Y-Pl-lmp">
@@ -712,7 +712,7 @@
712712
</viewController>
713713
<customObject id="zlx-fP-DAZ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
714714
</objects>
715-
<point key="canvasLocation" x="58" y="495"/>
715+
<point key="canvasLocation" x="669" y="41"/>
716716
</scene>
717717
</scenes>
718718
</document>

CreateJSONFile/Const/AboutApp.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public enum DataType {
117117
return "Int"
118118
case .string:
119119
return "String"
120-
case .array(let name):
121-
return name.isEmpty ? "Array" : "\(name.localizedCapitalized)ArrModel"
120+
case .array(_):
121+
return "Array"
122122
case .dictionary(let name):
123123
return name.isEmpty ? "Dictionary" : "\(name.localizedCapitalized)DicModel"
124124

CreateJSONFile/Const/HomeData+Extension.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ extension Date {
114114
return "yyyy-MM-dd 'T'HH:mm:ss.SSS+SSSS'Z'"
115115
}
116116

117+
static var dateForematYear: String {
118+
return "yyyy"
119+
}
120+
117121
// 格式化时间
118122
func formattingDate(_ dateFormat: String = dateFormatDay) -> String {
119123
let dateformatter = DateFormatter()
120124
dateformatter.dateFormat = dateFormat
121-
return dateformatter.string(from: self)
125+
print(dateFormat)
126+
return dateformatter.string(from: Date())
122127
}
123128

124129
static func dateWithStr(time: String) -> Date {
+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict>
5-
<key>com.apple.security.app-sandbox</key>
6-
<false/>
7-
<key>com.apple.security.files.downloads.read-write</key>
8-
<true/>
9-
<key>com.apple.security.files.user-selected.read-write</key>
10-
<true/>
11-
</dict>
4+
<dict/>
125
</plist>

CreateJSONFile/GenerateModel/FileDataModel.swift

+72-60
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,55 @@
88

99
import Cocoa
1010

11-
class HomeDataSource {
11+
struct HomeDataSource {
1212
/** 头部注释 */
1313
var fileHeaderArr: Array = [String]()
14-
/** json数据 */
15-
var jsonDic: Dictionary = [String: Any]()
1614
/** 继承 */
17-
var inheritanceStr: String = ""
18-
/** 内容 */
19-
var contentArr: Array = [HomeContentModel]()
20-
/** struct名称 */
21-
var structName: String = ""
15+
var inheritanceStr: String
16+
/* 内容 */
17+
var contentArr: Array<HomeContentModel>
18+
/** 文件名称 */
19+
var fileName: String
20+
/** 项目名称 */
21+
var productName: String
2222

23-
init() {
23+
init(inheritanceStr: String, contentArr: [HomeContentModel], fileName: String, productName: String) {
24+
self.inheritanceStr = inheritanceStr
25+
self.contentArr = contentArr
26+
self.fileName = fileName
27+
self.productName = productName
28+
2429
let keyword = APPKeyword()
2530
fileHeaderArr.removeAll()
2631
fileHeaderArr.append(keyword.annotationStr)
27-
fileHeaderArr.append("")
28-
fileHeaderArr.append("\(keyword.annotationStr)\(App.appName)")
32+
fileHeaderArr.append("\(keyword.annotationStr)\(fileName).swift")
33+
let product = productName.isEmpty ? "__projectName__" : productName
34+
fileHeaderArr.append("\(keyword.annotationStr)\(product)")
2935
fileHeaderArr.append(keyword.annotationStr)
30-
fileHeaderArr.append("")
31-
fileHeaderArr.append("\(keyword.annotationStr)\(App.copyright)")
36+
fileHeaderArr.append("\(keyword.annotationStr)Created by \(NSUserName()) on \(Date().formattingDate(Date.dateFormatSlashDay))")
37+
fileHeaderArr.append("\(keyword.annotationStr)Copyright © \(Date().formattingDate(Date.dateForematYear))\(NSUserName()). All rights reserved.")
3238
fileHeaderArr.append(keyword.annotationStr)
3339
}
40+
}
41+
42+
// struct模型
43+
struct HomeStructModel {
44+
/** 名称 */
45+
var structName: String
46+
/** 继承 */
47+
var inheritanceStr: String
48+
/** 内容 */
49+
var contentArr: Array<HomeContentModel>
3450

51+
init(structName: String, contentArr: [HomeContentModel], inheritanceStr: String = "") {
52+
self.structName = structName
53+
self.contentArr = contentArr
54+
self.inheritanceStr = inheritanceStr
55+
}
3556
}
3657

58+
59+
// 内容
3760
class HomeContentModel {
3861
/** key */
3962
var key: String
@@ -73,22 +96,31 @@ class HomeContentModel {
7396

7497
struct FileDataModel {
7598

99+
// MARK:- public
76100
// 创建
77-
static public func createFileSwift(_ name: String, homeData: HomeDataSource, success: (Bool) ->()) {
101+
static public func createFileSwift(_ fileUrl: URL, homeData: HomeDataSource, success: (Bool) ->()) {
78102
let manager = FileManager.default
79-
let fileName = "\(name).swift"
80-
let fileUrl = getFilePath().appendingPathComponent(fileName)
81103
if manager.fileExists(atPath: fileUrl.path) {
82104
// 新增数据
83105
let fileHandle = FileHandle(forUpdatingAtPath: fileUrl.path)
84106
fileHandle?.seekToEndOfFile()
85107

86108
// 添加模型
87-
wirteStructModel(fileHandle, dataArray: flatStructModel(homeData))
109+
let structModel = HomeStructModel(structName: homeData.fileName, contentArr: homeData.contentArr, inheritanceStr: homeData.inheritanceStr)
110+
wirteStructModel(fileHandle, dataArray: flatStructModel(structModel))
88111

89112
fileHandle?.closeFile()
90113
return
91114
}
115+
116+
do {
117+
var arr = fileUrl.path.components(separatedBy: "/")
118+
arr.removeLast()
119+
let path = arr.joined(separator: "/")
120+
try manager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
121+
} catch {
122+
}
123+
92124
if manager.createFile(atPath: fileUrl.path, contents: nil, attributes: nil) {
93125
let fileHandle = FileHandle(forUpdatingAtPath: fileUrl.path)
94126
let appKeyword = APPKeyword()
@@ -110,7 +142,8 @@ struct FileDataModel {
110142
}
111143

112144
// 添加模型
113-
wirteStructModel(fileHandle, dataArray: flatStructModel(homeData))
145+
let structModel = HomeStructModel(structName: homeData.fileName, contentArr: homeData.contentArr, inheritanceStr: homeData.inheritanceStr)
146+
wirteStructModel(fileHandle, dataArray: flatStructModel(structModel))
114147

115148
// 关闭文件
116149
fileHandle?.closeFile()
@@ -151,48 +184,43 @@ struct FileDataModel {
151184
return array
152185
}
153186

154-
// 扁平数据处理
155-
static fileprivate func flatStructModel(_ homeData: HomeDataSource) -> [HomeDataSource] {
156-
var array = [HomeDataSource]()
157-
158-
let dataSource = HomeDataSource()
159-
dataSource.structName = homeData.structName
160-
dataSource.contentArr = homeData.contentArr
161-
dataSource.inheritanceStr = homeData.inheritanceStr
162-
array.append(dataSource)
187+
// MARK: - fileprivate
188+
// 数据处理
189+
static fileprivate func flatStructModel(_ structData: HomeStructModel) -> [HomeStructModel] {
190+
var array = [HomeStructModel]()
191+
array.append(structData)
163192

164-
for item in homeData.contentArr {
165-
if item.childArr.count > 0 {
166-
let source = HomeDataSource()
167-
source.structName = item.outputType.writeStr
168-
source.contentArr = item.childArr
169-
source.inheritanceStr = homeData.inheritanceStr
170-
array += flatStructModel(source)
193+
for item in structData.contentArr {
194+
if item.childArr.count > 0 && !item.isIgnore {
195+
let model = HomeStructModel(structName: item.childName, contentArr: item.childArr, inheritanceStr: structData.inheritanceStr)
196+
array += flatStructModel(model)
171197
}
172-
}
198+
}
199+
173200
return array
174201
}
175202

176203
// 添加结构体
177-
static fileprivate func wirteStructModel(_ fileHandle: FileHandle?, dataArray: [HomeDataSource]) {
204+
static fileprivate func wirteStructModel(_ fileHandle: FileHandle?, dataArray: [HomeStructModel]) {
178205
dataArray.forEach {
179-
addStructModel(fileHandle, homeData: $0)
206+
addStructModel(fileHandle, structModel: $0)
180207
}
181208
}
182209

183-
static fileprivate func addStructModel(_ fileHandle: FileHandle?, homeData: HomeDataSource) {
210+
// 写文件
211+
static fileprivate func addStructModel(_ fileHandle: FileHandle?, structModel: HomeStructModel) {
184212
let appKeyword = APPKeyword()
185213
// 机构体开头
186214
fileHandle?.write(Data.newlineData())
187215
var structStart: String = ""
188-
if homeData.inheritanceStr == appKeyword.handy {
189-
structStart = "\(appKeyword.uct) \(homeData.structName)\(appKeyword.colon) \(appKeyword.handy) \(appKeyword.lPar)"
216+
if structModel.inheritanceStr == appKeyword.handy {
217+
structStart = "\(appKeyword.uct) \(structModel.structName)\(appKeyword.colon) \(appKeyword.handy) \(appKeyword.lPar)"
190218
}else {
191-
structStart = "\(appKeyword.uct) \(homeData.structName) \(appKeyword.lPar)"
219+
structStart = "\(appKeyword.uct) \(structModel.structName) \(appKeyword.lPar)"
192220
}
193221
fileHandle?.write(structStart.wirteData)
194-
195-
for model in homeData.contentArr {
222+
223+
for model in structModel.contentArr {
196224
if !model.isIgnore {
197225
if !model.annotation.isEmpty {
198226
fileHandle?.write(Data.newlineData())
@@ -207,23 +235,7 @@ struct FileDataModel {
207235
fileHandle?.write(Data.newlineData())
208236
fileHandle?.write("\(appKeyword.rPar)".wirteData)
209237
fileHandle?.write(Data.newlineData())
210-
211-
}
212-
213-
// 获取桌面路径 创建时间文件夹
214-
static fileprivate func getFilePath() -> URL {
215-
let manager = FileManager.default
216-
let urlForDocument = manager.urls(for: .desktopDirectory, in: .userDomainMask)
217-
let url = urlForDocument[0]
218-
let folderUrl = url.appendingPathComponent(Date().formattingDate())
219-
if !manager.fileExists(atPath: folderUrl.path) {
220-
do {
221-
try manager.createDirectory(at: folderUrl, withIntermediateDirectories: true, attributes: nil)
222-
} catch {
223-
return url
224-
}
225-
}
226-
return folderUrl
238+
227239
}
228240

229241
}

CreateJSONFile/MainController/HomeViewController.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ class HomeViewController: NSViewController {
4444

4545

4646
}
47+
4748

4849
}
4950

50-
51-
52-
5351
extension HomeViewController: NSSplitViewDelegate, NSOutlineViewDelegate, NSOutlineViewDataSource {
5452

5553
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {

CreateJSONFile/Modules/RightView/BottomView/Cell/HomeIgnoreTableViewCell.swift

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import Cocoa
1010

1111
class HomeIgnoreTableViewCell: NSTableCellView {
12-
13-
// public var didSelectClosure = { }
1412

1513
public lazy var checkButton: NSButton = {
1614
let button = NSButton(checkboxWithTitle: "", target: self, action: #selector(checkButtonClick))

0 commit comments

Comments
 (0)