Exemplo n.º 1
0
        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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void GeneratePluginXml(string nativeOutputPath, string scriptOutputPath)
        {
            Log.Message("    plugin.xml");

            PluginInfo pluginInfo;
            string     pluginXmlPath = Path.Combine(this.SourcePath, "ts", this.TargetName, "plugin.xml");

            using (StreamReader reader = File.OpenText(pluginXmlPath))
            {
                pluginInfo = PluginInfo.FromXml(reader, PluginInfo.C3PNamespaceUri);
            }

            CordovaPluginLinker.CollectSourceFilesInfo(nativeOutputPath, pluginInfo);

            foreach (string scriptFile in Directory.GetFiles(scriptOutputPath, "*.js"))
            {
                string scriptModuleName = Path.GetFileNameWithoutExtension(scriptFile);
                PluginInfo.JavaScriptModuleInfo jsModule = new PluginInfo.JavaScriptModuleInfo
                {
                    Name   = scriptModuleName,
                    Source = "www/" + scriptModuleName + ".js",
                };

                if (scriptModuleName == "CordovaWindowsBridge")
                {
                    jsModule.Runs = "true";
                    pluginInfo.WindowsPlatform.JavaScriptModules.Add(jsModule);
                }
                else
                {
                    pluginInfo.JavaScriptModules.Add(jsModule);
                }
            }

            using (StreamWriter writer = File.CreateText(Path.Combine(this.TargetOutputPath, "plugin.xml")))
            {
                pluginInfo.ToXml(writer, CordovaPluginLinker.cordovaPluginXmlNamespace);
            }
        }
Exemplo n.º 3
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);
        }