Example #1
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);
            }
        }
Example #2
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);
        }