forked from alibaba/LuaViewSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,043 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env ruby | ||
|
||
SDK_DIR = 'lv-sdk' | ||
SRC_DIR = 'lv-src' | ||
|
||
def exec_init(name) | ||
if Dir.exist? name then | ||
`rm -rf #{name}` | ||
end | ||
Dir.mkdir(name) | ||
Dir.chdir(name) | ||
|
||
Dir.mkdir(SRC_DIR) | ||
File.open("#{SRC_DIR}/main.lua", "w") { |f| | ||
f.write('print ("hello world!")') | ||
} | ||
|
||
# `git clone https://github.com/alibaba/LuaViewSDK.git lv-sdk` | ||
`cp -R ~/WorkSpace/LuaViewSDK lv-sdk` | ||
|
||
require "./lv-sdk/cli/generators/xcode" | ||
|
||
Generator::Xcode.generate(name) | ||
end | ||
|
||
command = ARGV[0] | ||
params = ARGV[1..-1] | ||
|
||
INIT_USAGE = 'init <ProjectName>' | ||
|
||
case command | ||
when 'commands' then puts INIT_USAGE | ||
when 'init' then | ||
proj_name = params[0] | ||
if proj_name == nil then | ||
puts "Usage: lv-cli #{INIT_USAGE}" | ||
else | ||
exec_init params[0] | ||
end | ||
else puts 'Usage: lv-cli <command> [<args>]' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'erb' | ||
|
||
module Generator | ||
|
||
class Xcode | ||
|
||
REL_PATH = "lv-sdk/cli/generators/xcode/template" | ||
|
||
class << self | ||
|
||
def render(src, target) | ||
renderer = ERB.new(File.read(src)) | ||
tf = File.open(target, "w") | ||
tf.write(renderer.result(binding)) | ||
|
||
tf.close | ||
|
||
File.delete(src) unless src == target | ||
end | ||
|
||
def generate(name) | ||
@proj_name = name | ||
|
||
Dir.mkdir('ios') | ||
`cp -R #{REL_PATH}/app ios/#{name}` | ||
|
||
proj = "ios/#{name}.xcodeproj" | ||
`cp -R #{REL_PATH}/xcodeproj #{proj}` | ||
|
||
pbx = "#{proj}/project.pbxproj" | ||
render(pbx, pbx) | ||
scheme = "#{proj}/xcshareddata/_xcscheme" | ||
render(scheme, scheme) | ||
|
||
ut = "ios/#{name}Tests" | ||
`cp -R #{REL_PATH}/tests #{ut}` | ||
render("#{ut}/Tests.m", "#{ut}/#{name}Tests.m") | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AppDelegate.h | ||
// Awesome | ||
// | ||
// Created by lv-cli on 16/1/20. | ||
// Copyright © 2016年 juhuasuan. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//#define ENABLE_NETWORK_DEBUG 1 | ||
#define ENABLE_LOCAL_DEBUG 1 | ||
|
||
#if !TARGET_IPHONE_SIMULATOR || ENABLE_NETWORK_DEBUG | ||
#undef ENABLE_LOCAL_DEBUG | ||
#endif | ||
|
||
extern NSString * const LVReloadPackageNotification; | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
#if TARGET_IPHONE_SIMULATOR | ||
|
||
- (NSString *)lvSourcePath; | ||
|
||
#endif | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// AppDelegate.m | ||
// | ||
// Created by lv-cli on 16/1/20. | ||
// Copyright © 2016年 juhuasuan. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
#import "LView.h" | ||
#import "LVPkgManager.h" | ||
|
||
NSString * const LVReloadPackageNotification = @"LVReloadPackageNotification"; | ||
|
||
@interface AppDelegate () | ||
|
||
#if ENABLE_NETWORK_DEBUG | ||
@property(nonatomic, copy) NSString *packageURL; | ||
#endif | ||
@property(nonatomic, strong) LView *lv; | ||
|
||
@end | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application | ||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
|
||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
self.window.backgroundColor = [UIColor whiteColor]; | ||
[self.window makeKeyAndVisible]; | ||
|
||
[self rebuildLView]; | ||
UIViewController *vc = [UIViewController new]; | ||
vc.view = self.lv; | ||
self.window.rootViewController = vc; | ||
|
||
#if ENABLE_NETWORK_DEBUG | ||
self.packageURL = @""; | ||
[self reloadPackage]; | ||
#else | ||
[self.lv runFile:@"main.lua"]; | ||
#endif | ||
|
||
return YES; | ||
} | ||
|
||
- (void)rebuildLView { | ||
self.lv = [[LView alloc] initWithFrame:self.window.bounds]; | ||
|
||
#if ENABLE_LOCAL_DEBUG | ||
NSString *localSrcPath = [self lvSourcePath]; | ||
NSMutableArray *paths = [self.lv.bundleSearchPath mutableCopy] ?: [NSMutableArray array]; | ||
if (paths.count == 0) { | ||
[paths addObject:localSrcPath]; | ||
} else { | ||
[paths insertObject:localSrcPath atIndex:0]; | ||
} | ||
|
||
[self.lv setBundleSearchPath:paths]; | ||
#endif // ENABLE_LOCAL_DEBUG | ||
} | ||
|
||
#if ENABLE_NETWORK_DEBUG || ENABLE_LOCAL_DEBUG | ||
|
||
- (NSArray<UIKeyCommand *> *)keyCommands { | ||
UIKeyCommand *reloadKeyCommand = [UIKeyCommand | ||
keyCommandWithInput:@"r" | ||
modifierFlags:UIKeyModifierCommand | ||
action:@selector(reloadPackage)]; | ||
|
||
return @[reloadKeyCommand]; | ||
} | ||
|
||
- (void)reloadPackage { | ||
[[NSNotificationCenter defaultCenter] | ||
postNotificationName:LVReloadPackageNotification object:nil]; | ||
|
||
#if ENABLE_NETWORK_DEBUG | ||
|
||
[LVUtil download:self.packageURL callback:^(NSData *data) { | ||
if (!data) { | ||
return; | ||
} | ||
|
||
NSString *pkgName = @"Main"; | ||
[LVPkgManager unpackageData:data packageName:pkgName localMode:NO]; | ||
|
||
[self rebuildLView]; | ||
self.window.rootViewController.view = self.lv; | ||
|
||
[self.lv runPackage:@"Main"]; | ||
}]; | ||
|
||
#else | ||
|
||
[self rebuildLView]; | ||
self.window.rootViewController.view = self.lv; | ||
|
||
[self.lv runFile:@"main.lua"]; | ||
|
||
#endif // ENABLE_NETWORK_DEBUG | ||
} | ||
|
||
#endif // ENABLE_NETWORK_DEBUG || ENABLE_LOCAL_DEBUG | ||
|
||
#if TARGET_IPHONE_SIMULATOR | ||
|
||
- (NSString *)lvSourcePath { | ||
NSString *filePath = [NSString stringWithUTF8String:__FILE__]; | ||
NSMutableArray *paths = [[filePath componentsSeparatedByString:@"/"] mutableCopy]; | ||
NSRange range = NSMakeRange([paths count] - 3, 3); | ||
[paths removeObjectsInRange:range]; | ||
return [[paths componentsJoinedByString:@"/"] stringByAppendingPathComponent:@"lv-src"]; | ||
} | ||
|
||
#endif | ||
|
||
@end |
38 changes: 38 additions & 0 deletions
38
cli/generators/xcode/template/app/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
cli/generators/xcode/template/app/Base.lproj/LaunchScreen.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/> | ||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<animations/> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// main.m | ||
// | ||
// Created by lv-cli on 16/1/20. | ||
// Copyright © 2016年 juhuasuan. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "AppDelegate.h" | ||
|
||
int main(int argc, char * argv[]) { | ||
@autoreleasepool { | ||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.