Beispiel #1
0
        public static AngularWorkspace Create(StandardGlobalInfo globalInfo, NPMSolution npmSolution, NormalizedPath path)
        {
            NormalizedPath packageJsonPath = path.AppendPart("package.json");
            NormalizedPath angularJsonPath = path.AppendPart("angular.json");

            JObject packageJson = JObject.Parse(File.ReadAllText(packageJsonPath));
            JObject angularJson = JObject.Parse(File.ReadAllText(angularJsonPath));

            if (!(packageJson["private"]?.ToObject <bool>() ?? false))
            {
                throw new InvalidDataException("A workspace project should be private.");
            }
            List <NPMProject> projects = new List <NPMProject>();
            var jsonProject            = angularJson["projects"].ToObject <JObject>();

            foreach (var project in jsonProject.Properties())
            {
                var projectPath = project.Value["root"].ToString();
                var outputPath  = project.Value["architect"]?["build"]?["options"]?["outputPath"]?.Value <string>()
                                  ?? projectPath;
                projects.Add(
                    NPMPublishedProject.Create(
                        globalInfo,
                        npmSolution,
                        path.Combine(projectPath),
                        path.Combine(outputPath)
                        )
                    );
            }
            return(new AngularWorkspace(NPMPublishedProject.Create(globalInfo, npmSolution, path, path), projects));
        }
        public static AngularWorkspace Create(StandardGlobalInfo globalInfo, NPMSolution npmSolution, NormalizedPath path)
        {
            NormalizedPath packageJsonPath = path.AppendPart("package.json");
            NormalizedPath angularJsonPath = path.AppendPart("angular.json");

            JObject packageJson = JObject.Parse(File.ReadAllText(packageJsonPath));
            JObject angularJson = JObject.Parse(File.ReadAllText(angularJsonPath));

            if (!(packageJson["private"]?.ToObject <bool>() ?? false))
            {
                throw new InvalidDataException("A workspace project should be private.");
            }
            List <NPMProject> projects = new List <NPMProject>();
            var jsonProject            = angularJson["projects"].ToObject <JObject>();

            foreach (var project in jsonProject.Properties())
            {
                var    projectPath       = project.Value["root"].ToString();
                var    options           = project.Value["architect"]["build"]["options"];
                string outputPathJson    = options["outputPath"]?.Value <string>();
                bool   havePath          = outputPathJson != null;
                string ngPackagePath     = options["project"]?.Value <string>();
                bool   haveNgPackageJson = ngPackagePath != null;
                if (havePath && haveNgPackageJson)
                {
                    throw new NotImplementedException();                                //I don't know what to do in this case.
                }
                NormalizedPath outputPath;
                NormalizedPath ngPackagePathFullPath = path.Combine(ngPackagePath);
                if (haveNgPackageJson)
                {
                    JObject ngPackage = JObject.Parse(File.ReadAllText(ngPackagePathFullPath));
                    string  dest      = ngPackage["dest"]?.Value <string>();
                    if (dest == null)
                    {
                        throw new InvalidDataException("ng package does not contain dest path.");
                    }
                    outputPath = ngPackagePathFullPath.RemoveLastPart().Combine(dest).ResolveDots();
                }
                else if (havePath)
                {
                    outputPath = path.Combine(outputPathJson);
                }
                else
                {
                    globalInfo.Cake.Warning($"No path found for angular project '{path}'.");
                    outputPath = path.Combine(projectPath);
                }

                projects.Add(
                    NPMPublishedProject.Create(
                        globalInfo,
                        npmSolution,
                        path.Combine(projectPath),
                        outputPath
                        )
                    );
            }
            return(new AngularWorkspace(NPMPublishedProject.Create(globalInfo, npmSolution, path, path), projects));
        }
Beispiel #3
0
        public static AngularWorkspace Create(StandardGlobalInfo globalInfo, NPMSolution npmSolution, NormalizedPath path, NormalizedPath outputFolder)
        {
            NormalizedPath packageJsonPath = path.AppendPart("package.json");
            NormalizedPath angularJsonPath = path.AppendPart("angular.json");

            JObject packageJson = JObject.Parse(File.ReadAllText(packageJsonPath));
            JObject angularJson = JObject.Parse(File.ReadAllText(angularJsonPath));

            if (!(packageJson["private"]?.ToObject <bool>() ?? false))
            {
                throw new InvalidDataException("A workspace project should be private.");
            }
            string            solutionName  = packageJson["name"].ToString();
            List <string>     unscopedNames = angularJson["projects"].ToObject <JObject>().Properties().Select(p => p.Name).ToList();
            List <NPMProject> projects      = unscopedNames.Select(
                p => NPMPublishedProject.Create(
                    globalInfo,
                    npmSolution,
                    path.Combine(new NormalizedPath(angularJson["projects"][p]["root"].ToString())),
                    outputFolder.AppendPart(p)
                    )
                ).ToList();

            return(new AngularWorkspace(projects.Single(p => p.DirectoryPath == path), projects, outputFolder));
        }
        /// <summary>
        /// Create a <see cref="NPMProject"/> that can be a <see cref="NPMPublishedProject"/>.
        /// </summary>
        /// <param name="globalInfo">The global info of the CodeCakeBuilder.</param>
        /// <param name="dirPath">The directory path where is located the npm package.</param>
        /// <param name="outputPath">The directory path where the build output is. It can be the same than <paramref name="dirPath"/>.</param>
        /// <returns></returns>
        public static NPMProject Create(StandardGlobalInfo globalInfo, NPMSolution solution, NormalizedPath dirPath, NormalizedPath outputPath)
        {
            var        json = SimplePackageJsonFile.Create(globalInfo.Cake, dirPath);
            NPMProject output;

            if (json.IsPrivate)
            {
                output = CreateNPMProject(globalInfo, solution, json, outputPath);
            }
            else
            {
                output = new NPMPublishedProject(globalInfo, solution, json, outputPath);
            }
            return(output);
        }
Beispiel #5
0
        /// <summary>
        /// Reads the "CodeCakeBuilder/NPMSolution.xml" file that must exist.
        /// </summary>
        /// <param name="version">The version of all published packages.</param>
        /// <returns>The solution object.</returns>
        public static NPMSolution ReadFromNPMSolutionFile(StandardGlobalInfo globalInfo)
        {
            var document = XDocument.Load("CodeCakeBuilder/NPMSolution.xml").Root;
            var solution = new NPMSolution(globalInfo);

            foreach (var item in document.Elements("AngularWorkspace"))
            {
                solution.Add(AngularWorkspace.Create(globalInfo,
                                                     solution,
                                                     (string)item.Attribute("Path")));
            }
            foreach (var item in document.Elements("Project"))
            {
                solution.Add(NPMPublishedProject.Create(
                                 globalInfo,
                                 solution,
                                 (string)item.Attribute("Path"),
                                 (string)item.Attribute("OutputFolder")));
            }
            return(solution);
        }
Beispiel #6
0
 protected override IDisposable TokenInjector(NPMPublishedProject project)
 {
     return(project.TemporarySetPushTargetAndAzurePatLogin(FeedUri, ResolveAPIKey()));
 }
Beispiel #7
0
 protected override IDisposable TokenInjector(NPMPublishedProject project)
 {
     return(_usePassword
             ? project.TemporarySetPushTargetAndPasswordLogin(FeedUri, ResolveAPIKey())
             : project.TemporarySetPushTargetAndTokenLogin(FeedUri, ResolveAPIKey()));
 }
Beispiel #8
0
 protected abstract IDisposable TokenInjector(NPMPublishedProject project);