示例#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));
        }
示例#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));
        }
示例#4
0
 protected static NPMProject CreateNPMProject(
     StandardGlobalInfo globalInfo,
     NPMSolution npmSolution,
     SimplePackageJsonFile json,
     NormalizedPath outputPath)
 {
     return(new NPMProject(globalInfo, npmSolution, json, outputPath));
 }
示例#5
0
        NPMPublishedProject(StandardGlobalInfo globalInfo, NPMSolution npmSolution, SimplePackageJsonFile json, NormalizedPath outputPath)
            : base(globalInfo, npmSolution, json, outputPath)
        {
            ArtifactInstance = new ArtifactInstance(new Artifact("NPM", json.Name), globalInfo.Version);
            string tgz = json.Name.Replace("@", "").Replace('/', '-');

            TGZName = tgz + "-" + globalInfo.Version.ToString() + ".tgz";
        }
        NPMPublishedProject(StandardGlobalInfo globalInfo, NPMSolution npmSolution, SimplePackageJsonFile json, NormalizedPath outputPath)
            : base(globalInfo, npmSolution, json, outputPath)
        {
            _ckliLocalFeedMode = json.CKliLocalFeedMode;
            ArtifactInstance   = new ArtifactInstance(new Artifact("NPM", json.Name), globalInfo.BuildInfo.Version);
            string tgz = json.Name.Replace("@", "").Replace('/', '-');

            TGZName = tgz + "-" + globalInfo.BuildInfo.Version.WithBuildMetaData("").ToNormalizedString() + ".tgz";
        }
示例#7
0
        /// <summary>
        /// Adds the <see cref="NPMSolution"/> to the <paramref name="globalInfo"/>
        /// </summary>
        /// <param name="this">This global info.</param>
        /// <param name="solution">The NPM solution.</param>
        /// <returns>This info.</returns>
        public static StandardGlobalInfo AddNPM(this StandardGlobalInfo globalInfo, NPMSolution solution)
        {
            SVersion minmimalNpmVersionRequired = SVersion.Create(6, 7, 0);
            string   npmVersion = globalInfo.Cake.NpmGetNpmVersion();

            if (SVersion.Parse(npmVersion) < minmimalNpmVersionRequired)
            {
                globalInfo.Cake.TerminateWithError("Outdated npm. Version older than v6.7.0 are known to fail on publish.");
            }
            globalInfo.RegisterSolution(solution);
            return(globalInfo);
        }
示例#8
0
 protected NPMProject(
     StandardGlobalInfo globalInfo,
     NPMSolution npmSolution,
     SimplePackageJsonFile json,
     NormalizedPath outputPath)
 {
     DirectoryPath = json.JsonFilePath.RemoveLastPart();
     PackageJson   = json;
     OutputPath    = outputPath;
     NPMRCPath     = DirectoryPath.AppendPart(".npmrc");
     GlobalInfo    = globalInfo;
     NpmSolution   = npmSolution;
 }
        /// <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);
        }
示例#10
0
        public static IDisposable TemporaryReplaceDependenciesVersion(
            NPMSolution npmSolution,
            NormalizedPath jsonPath,
            bool ckliLocalFeedMode,
            SVersion version,
            Action <JObject> packageJsonPreProcessor
            )
        {
            (string content, TempFileTextModification temp) = CreateTempFileTextModification(jsonPath);
            JObject json = JObject.Parse(content);

            packageJsonPreProcessor?.Invoke(json);
            json.Remove("devDependencies");
            foreach (var dependencyPropName in new string[]
            {
                "dependencies",
                "peerDependencies",
                "bundledDependencies",
                "optionalDependencies",
            })
            {
                if (json.ContainsKey(dependencyPropName))
                {
                    JObject dependencies = (JObject)json[dependencyPropName];
                    foreach (KeyValuePair <string, JToken> keyValuePair in dependencies)
                    {
                        if (npmSolution.AllPublishedProjects.FirstOrDefault(x => x.PackageJson.Name == keyValuePair.Key)
                            is NPMPublishedProject localProject)
                        {
                            dependencies[keyValuePair.Key] = new JValue("^" + version);
                        }
                    }
                    if (ckliLocalFeedMode)
                    {
                        foreach (var dependency in ((IEnumerable <KeyValuePair <string, JToken> >)dependencies)
                                 .Select(s => new KeyValuePair <string, string>(s.Key, s.Value.ToString()))
                                 .Where(p => p.Value.StartsWith("file:"))
                                 .Select(s => new KeyValuePair <string, SVersion>(s.Key, ParseVersionFromPackagePath(s.Value))))
                        {
                            dependencies[dependency.Key] = dependency.Value.ToNormalizedString();
                        }
                    }
                }
            }
            File.WriteAllText(jsonPath, json.ToString());
            return(temp);
        }
示例#11
0
        /// <summary>
        /// Set the package version and change the project reference to package reference.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="version"></param>
        /// <param name="preparePack"></param>
        /// <param name="packageJsonPreProcessor"></param>
        /// <returns></returns>
        public static IDisposable TemporaryReplacePackageVersion(
            NPMSolution npmSolution,
            NormalizedPath jsonPath,
            SVersion version,
            bool preparePack,
            Action <JObject> packageJsonPreProcessor)
        {
            (string content, TempFileTextModification temp) = CreateTempFileTextModification(jsonPath);
            JObject json = JObject.Parse(content);

            json["version"] = version.ToNormalizedString();
            if (preparePack)
            {
                json.Remove("devDependencies");
                json.Remove("scripts");
                string[] _dependencyPropNames = new string[]
                {
                    "dependencies",
                    "peerDependencies",
                    "devDependencies",
                    "bundledDependencies",
                    "optionalDependencies",
                };
                foreach (var dependencyPropName in _dependencyPropNames)
                {
                    if (json.ContainsKey(dependencyPropName))
                    {
                        JObject dependencies = (JObject)json[dependencyPropName];
                        foreach (KeyValuePair <string, JToken> keyValuePair in dependencies)
                        {
                            if (npmSolution.AllPublishedProjects.FirstOrDefault(x => x.PackageJson.Name == keyValuePair.Key)
                                is NPMPublishedProject localProject)
                            {
                                dependencies[keyValuePair.Key] = new JValue("^" + version);
                            }
                        }
                    }
                }
            }
            packageJsonPreProcessor?.Invoke(json);
            File.WriteAllText(jsonPath, json.ToString());
            return(temp);
        }
示例#12
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);
        }
示例#13
0
 /// <summary>
 /// Adds the <see cref="Build.NPMArtifactType"/> for NPM based on <see cref="NPMSolution.ReadFromNPMSolutionFile"/>
 /// (projects are defined by "CodeCakeBuilder/NPMSolution.xml" file).
 /// </summary>
 /// <param name="this">This global info.</param>
 /// <returns>This info.</returns>
 public static StandardGlobalInfo AddNPM(this StandardGlobalInfo @this)
 {
     return(AddNPM(@this, NPMSolution.ReadFromNPMSolutionFile(@this)));
 }
示例#14
0
 public NPMArtifactType(StandardGlobalInfo globalInfo, NPMSolution solution)
     : base(globalInfo, "NPM")
 {
     Solution = solution;
 }