public override void Run() { this.Init(); PluginLinker.CopyNativeCode(this.SourcePath, new[] { "c3p", "cordova" }, this.TargetOutputPath); string scriptOutputPath = Path.Combine(this.TargetOutputPath, "www"); this.CopyLibTypeScript(scriptOutputPath); File.Copy( Path.Combine(this.SourcePath, "ts", "node_modules", "cordova.d.ts"), Path.Combine(scriptOutputPath, "cordova.d.ts")); File.Copy( Path.Combine(this.SourcePath, "ts", "node_modules", "es6-promise.d.ts"), Path.Combine(scriptOutputPath, "es6-promise.d.ts")); this.FixTSModuleReferences(scriptOutputPath, false); Utils.CompileTypeScript(scriptOutputPath); this.GeneratePluginXml(this.TargetOutputPath, scriptOutputPath); this.CopyPackageJson(); Utils.PackNpmPackage(this.TargetOutputPath); }
public override void Run() { this.Init(); PluginLinker.CopyNativeProjects(this.SourcePath, new[] { "c3p", "reactnative" }, this.TargetOutputPath); string scriptOutputPath = Path.Combine(this.TargetOutputPath, "js"); this.CopyLibTypeScript(scriptOutputPath); string modulesOutputPath = Path.Combine(scriptOutputPath, "node_modules"); Directory.CreateDirectory(modulesOutputPath); File.Copy( Path.Combine(this.SourcePath, "ts", "node_modules", "react-native.d.ts"), Path.Combine(modulesOutputPath, "react-native.d.ts")); // React Native supports (most) ES6 language features, particularly Promises. string tsconfigFilePath = Path.Combine(scriptOutputPath, "tsconfig.json"); File.WriteAllText(tsconfigFilePath, File.ReadAllText(tsconfigFilePath).Replace("\"es5\"", "\"es6\"")); this.FixTSModuleReferences(scriptOutputPath, true); Utils.CompileTypeScript(scriptOutputPath); this.CopyPackageJson(); Utils.PackNpmPackage(this.TargetOutputPath); }
internal static void CopyNativeCode(string sourcePath, string[] sourceSubdirectories, string targetPath) { foreach (string platform in new[] { PluginInfo.AndroidPlatformName, PluginInfo.IOSPlatformName, }) { string platformSourcePath = Path.Combine(sourcePath, platform); if (!Directory.Exists(platformSourcePath)) { continue; } string platformTargetPath = Path.Combine(targetPath, platform); if (!Directory.Exists(platformTargetPath)) { Directory.CreateDirectory(platformTargetPath); } ICollection <string> includeExtensions = GetFileExtensionsForNativeCode(platform); ICollection <string> excludeDirectories = new List <string>(new[] { "build" }); if (sourceSubdirectories != null) { foreach (string sourceSubdirectory in sourceSubdirectories) { string sourceSubPath = Path.Combine(platformSourcePath, sourceSubdirectory); PluginLinker.CopyFiles( sourceSubPath, platformTargetPath, false, includeExtensions, excludeDirectories); } } else { foreach (string frameworkSourceDirectory in Directory.GetDirectories(platformSourcePath, "*.framework")) { string frameworkName = Path.GetFileName(frameworkSourceDirectory); excludeDirectories.Add(frameworkName); string frameworkTargetDirectory = Path.Combine(platformTargetPath, frameworkName); if (!Directory.Exists(frameworkTargetDirectory)) { Directory.CreateDirectory(frameworkTargetDirectory); } PluginLinker.CopyFiles(frameworkSourceDirectory, frameworkTargetDirectory, true); } PluginLinker.CopyFiles( platformSourcePath, platformTargetPath, false, includeExtensions, excludeDirectories); } } }
internal static void CollectSourceFilesInfo(string sourceDirectoryPath, PluginInfo pluginInfo) { foreach (string platform in new[] { PluginInfo.AndroidPlatformName, PluginInfo.IOSPlatformName, PluginInfo.WindowsPlatformName }) { PluginInfo.PlatformInfo platformInfo = pluginInfo.Platforms.FirstOrDefault(p => p.Name == platform); if (platformInfo == null) { continue; } string platformSourcePath = Path.Combine(sourceDirectoryPath, platform); if (Directory.Exists(platformSourcePath)) { ICollection <string> extensions = PluginLinker.GetFileExtensionsForNativeCode(platform); foreach (string sourceFilePath in Directory.GetFiles(platformSourcePath)) { string relativeFilePath = Path.GetFullPath(sourceFilePath) .Substring(Path.GetFullPath(sourceDirectoryPath).Length + 1); if (extensions.Any(e => sourceFilePath.EndsWith(e, StringComparison.OrdinalIgnoreCase))) { PluginInfo.SourceFileInfo sourceFileInfo = new PluginInfo.SourceFileInfo { SourceFilePath = relativeFilePath.Replace("\\", "/"), }; if (sourceFilePath.EndsWith(".java", StringComparison.OrdinalIgnoreCase)) { string javaPackage = CordovaPluginLinker.GetJavaSourceFilePackage(sourceFilePath); if (javaPackage != null) { sourceFileInfo.TargetDirectoryPath = "src/" + javaPackage.Replace('.', '/'); } } if (!platformInfo.ResourceFiles.Any(r => String.Equals( r.SourceFilePath, sourceFileInfo.SourceFilePath, StringComparison.OrdinalIgnoreCase))) { platformInfo.SourceFiles.Add(sourceFileInfo); } } } } } }
protected static void CopyFiles( string sourcePath, string targetPath, bool preserveDirectories, ICollection <string> includeExtensions = null, ICollection <string> excludeDirectories = null) { PluginLinker.CopyFiles(sourcePath, targetPath, preserveDirectories, relativePath => { if (excludeDirectories != null) { char slash = Path.DirectorySeparatorChar; foreach (string excludeDirectory in excludeDirectories) { if (relativePath.StartsWith(excludeDirectory + slash, StringComparison.OrdinalIgnoreCase) || relativePath.IndexOf(slash + excludeDirectory + slash, StringComparison.OrdinalIgnoreCase) > 0) { return(false); } } } if (includeExtensions != null) { foreach (string includeExtension in includeExtensions) { if (relativePath.EndsWith(includeExtension, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); } return(true); }); }
public override void Run() { this.Init(); ClrApi pluginApi = this.MergeApis(this.LoadApis()); PluginLinker.CopyNativeProjects(this.SourcePath, null, this.TargetOutputPath); string scriptOutputPath = Path.Combine(this.TargetOutputPath, "js"); if (!Directory.Exists(scriptOutputPath)) { Directory.CreateDirectory(scriptOutputPath); } this.CreateTypeScriptBindings( pluginApi, true, true, c3pReactNativePackageName, scriptOutputPath); string modulesDirectoryPath = Path.Combine(scriptOutputPath, "node_modules"); Directory.CreateDirectory(modulesDirectoryPath); this.CreateBridgeModuleTypeScriptDefinition(modulesDirectoryPath); Utils.ExtractResource("NativeObject.ts", modulesDirectoryPath); Utils.ExtractResource("NativeBridge.ts", modulesDirectoryPath); Utils.ExtractResource("react-native.d.ts", modulesDirectoryPath); Utils.ExtractResource("tsconfig.json", scriptOutputPath); this.GeneratePluginModule(pluginApi, scriptOutputPath); this.RemoveES6PromiseImports(scriptOutputPath); Utils.CompileTypeScript(scriptOutputPath); Log.Message(Utils.EnsureTrailingSlash(Path.GetFullPath(this.TargetOutputPath))); this.GeneratePackageJson(c3pReactNativePackageName, new[] { " \"main\": \"js/plugin.js\"" }); Utils.PackNpmPackage(this.TargetOutputPath); }
public override void Run() { this.Init(); ClrApi pluginApi = this.MergeApis(this.LoadApis()); PluginLinker.CopyNativeCode(this.SourcePath, null, this.TargetOutputPath); if (this.PluginInfo.WindowsPlatform != null) { string windowsSourcePath = Path.Combine( this.SourcePath, "windows" + (this.windowsLanguage != null ? "-" + this.windowsLanguage : null)); if (Directory.Exists(windowsSourcePath)) { string windowsOutputPath = Path.Combine(this.TargetOutputPath, "windows"); if (!Directory.Exists(windowsOutputPath)) { Directory.CreateDirectory(windowsOutputPath); } PluginLinker.CopyProjectDirectory(windowsSourcePath, windowsOutputPath); } } CordovaPluginLinker.CollectSourceFilesInfo(this.TargetOutputPath, this.PluginInfo); this.CreateAndroidConfigFileInfo(); this.CreateIOSConfigFileInfo(); this.CreateWindowsConfigFileInfo(); this.AddProjectReferences(); string scriptOutputPath = Path.Combine(this.TargetOutputPath, "www"); if (Directory.Exists(scriptOutputPath)) { Directory.Delete(scriptOutputPath, true); } Directory.CreateDirectory(scriptOutputPath); this.CreateTypeScriptBindings( pluginApi, true, false, c3pPluginId + "." + c3pCordovaModuleName, scriptOutputPath); string modulesDirectoryPath = Path.Combine(scriptOutputPath, "node_modules"); Directory.CreateDirectory(modulesDirectoryPath); // This is messy, because Cordova's implementation of module resolution // doesn't respect the 'main' property from the package.json. this.CreateBridgeModuleTypeScriptDefinition(Path.Combine( modulesDirectoryPath, c3pPluginId + "." + c3pCordovaModuleName + ".d.ts")); Utils.ExtractResource( "es6-promise.d.ts", modulesDirectoryPath, c3pPluginId + "." + "es6-promise.d.ts"); foreach (string tsFile in new[] { "NativeObject.ts", "NativeBridge.ts" }) { Utils.ExtractResource(tsFile, modulesDirectoryPath, c3pPluginId + "." + tsFile); string fixTsCode = File.ReadAllText(Path.Combine( modulesDirectoryPath, c3pPluginId + "." + tsFile)); fixTsCode = fixTsCode.Replace("\"es6-promise\"", "\"" + c3pPluginId + ".es6-promise\"") .Replace("\"./NativeObject\"", "\"" + c3pPluginId + ".NativeObject\""); File.WriteAllText( Path.Combine(modulesDirectoryPath, c3pPluginId + "." + tsFile), fixTsCode); } Utils.ExtractResource("tsconfig.json", scriptOutputPath); Utils.CompileTypeScript(scriptOutputPath); Log.Message(Utils.EnsureTrailingSlash(Path.GetFullPath(this.TargetOutputPath))); this.GeneratePluginXml(scriptOutputPath); this.GeneratePackageJson(c3pCordovaPackageName); Utils.PackNpmPackage(this.TargetOutputPath); }
internal static void CopyNativeProjects(string sourcePath, string[] includeProjects, string targetPath) { foreach (string platform in new[] { PluginInfo.AndroidPlatformName, PluginInfo.IOSPlatformName, PluginInfo.WindowsPlatformName }) { string platformSourcePath = Path.Combine(sourcePath, platform); if (!Directory.Exists(platformSourcePath)) { continue; } string platformTargetPath = Path.Combine(targetPath, platform); if (!Directory.Exists(platformTargetPath)) { Directory.CreateDirectory(platformTargetPath); } if (platform == PluginInfo.AndroidPlatformName) { Log.Message(Utils.EnsureTrailingSlash(Path.GetFullPath(platformTargetPath))); foreach (string projectFile in new[] { "build.gradle", "gradle.properties", "gradlew", "gradlew.bat", "settings.gradle", }) { Log.Message(" " + projectFile); File.Copy( Path.Combine(platformSourcePath, projectFile), Path.Combine(platformTargetPath, projectFile), true); } foreach (string projectDirectory in Directory.GetDirectories(platformSourcePath)) { string directoryName = Path.GetFileName(projectDirectory); if (directoryName != "build" && directoryName != ".idea" && directoryName != ".gradle" && (directoryName == "gradle" || includeProjects == null || includeProjects.Any(p => p.Equals(directoryName, StringComparison.OrdinalIgnoreCase)))) { PluginLinker.CopyProjectDirectory( projectDirectory, Path.Combine(platformTargetPath, directoryName)); } } } else if (platform == PluginInfo.IOSPlatformName) { foreach (string projectDirectory in Directory.GetDirectories(platformSourcePath)) { string directoryName = Path.GetFileName(projectDirectory); string projectName = directoryName; if (projectName.EndsWith(".xcodeproj")) { projectName = projectName.Substring(0, projectName.Length - ".xcodeproj".Length); } if (projectName.StartsWith("C3P") && projectName != "C3P") { projectName = projectName.Substring("C3P".Length); } if (directoryName != "build" && directoryName != "sharpie-build" && (includeProjects == null || includeProjects.Any(p => p.Equals(projectName, StringComparison.OrdinalIgnoreCase)))) { PluginLinker.CopyProjectDirectory( projectDirectory, Path.Combine(platformTargetPath, directoryName)); } } } else if (platform == PluginInfo.WindowsPlatformName) { // TODO: Copy Windows project files. } } }
public static int Main(string[] args) { try { Arguments parsedArgs = new Arguments(); if (!ParseArgs(args, parsedArgs) || parsedArgs.ShowHelp || (parsedArgs.CompilePlatform == null && parsedArgs.LinkTarget == null && parsedArgs.Pack == null)) { ShowHelp(parsedArgs.ShowHelp); return(parsedArgs.ShowHelp ? 0 : 1); } Log.IsVerboseOutputEnabled = parsedArgs.VerboseConsoleOutput; if (parsedArgs.CompilePlatform != null) { string[] compilePlatformParts = parsedArgs.CompilePlatform.Split('-'); ApiCompiler apiCompiler = ApiCompiler.Create(compilePlatformParts[0]); apiCompiler.SourcePath = parsedArgs.SourcePath; apiCompiler.DebugConfiguration = !parsedArgs.ReleaseConfiguration; apiCompiler.IntermediatePath = parsedArgs.IntermediatePaths.FirstOrDefault(); apiCompiler.SkipNativeBuild = parsedArgs.SkipNativeBuild; if (compilePlatformParts.Length == 2) { apiCompiler.Language = compilePlatformParts[1]; } apiCompiler.Run(); } if (parsedArgs.LinkTarget != null) { PluginLinker pluginLinker = PluginLinker.Create(parsedArgs.LinkTarget); pluginLinker.SourcePath = parsedArgs.SourcePath; pluginLinker.IntermediatePaths = parsedArgs.IntermediatePaths; pluginLinker.OutputPath = parsedArgs.OutputPath; pluginLinker.DebugConfiguration = !parsedArgs.ReleaseConfiguration; pluginLinker.Run(); } if (parsedArgs.Pack != null) { PluginLibPackager packager = PluginLibPackager.Create(parsedArgs.Pack); packager.SourcePath = parsedArgs.SourcePath; packager.OutputPath = parsedArgs.OutputPath; packager.Run(); } return(0); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(ex); Console.ResetColor(); return(1); } finally { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Press enter to quit."); Console.ResetColor(); Console.ReadLine(); } #endif } }