1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

synx v0.1.1でXcodeのファイル整理を自動化する

Last updated at Posted at 2015-10-21

目的

  • synx を利用し、コマンドを実行することで自動的にファイルを整理する
  • Xcode と同じ OpenStateFormat の pbxproj ファイルを出力する
  • pbxproj 内のファイルの順序は変更しない

課題

synx v0.1.1

  • NG: pbxproj 内のファイルの順序がアルファベット順になる
    • ファイルシステムと同じ順序になり、自由に順序を変更できるという利点がなくなる
    • アルファベット順にしないオプションは提供されていない
    • https://github.com/venmo/synx/issues/26
  • OK: pbxproj ファイルは OpenStateFormat で出力される

synx v0.0.61

  • NG: pbxproj ファイルがXMLFormatで出力される
    • Xcode で pbxproj ファイルを更新すると OpenStateFormat に書き換わる
    • コマンド実行後に手動で修正する必要がある
    • うっかり修正を忘れてコミットすると悲しいことになる
  • OK: pbxproj 内のファイルの順序はそのまま保持される
差分イメージ
diff --git SampleProject.xcodeproj/project.pbxproj SampleProject.xcodeproj/project.pbxproj
index 71cf5d5..5f29e86 100644
--- SampleProject.xcodeproj/project.pbxproj
+++ SampleProject.xcodeproj/project.pbxproj
@@ -1,402 +1,751 @@
-// !$*UTF8*$!
-{
-	archiveVersion = 1;
-	classes = {
-	};
-	objectVersion = 46;
-	objects = {
...
-	rootObject = 6DD1BA9E1BD54C9A00159F69 /* Project object */;
-}
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>archiveVersion</key>
+	<string>1</string>
+	<key>classes</key>
+	<dict/>
+	<key>objectVersion</key>
+	<string>46</string>
+	<key>objects</key>
...
+	<key>rootObject</key>
+	<string>6DD1BA9E1BD54C9A00159F69</string>
+</dict>
+</plist>

対策

v0.1.1 のソート処理部分を上書きする

  • 最新版である v0.1.1 を採用する
  • ソート部分だけ上書きする

スクリプトを書く

sync.rb
# sync.rb

require 'synx'

#
# override
#
module Xcodeproj
  class Project
    module Object
      class PBXGroup
        def sort_by_name
          return
        end
      end
    end
  end
end

#
# execute
#
Synx::Project.open('./SampleProject.xcodeproj').sync

実行する

$ ruby ./sync.rb
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?