예제 #1
0
        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);
        }
예제 #2
0
파일: PluginLinker.cs 프로젝트: runt18/c3p
        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.
                }
            }
        }