예제 #1
0
    public void Check()
    {
        var installedNpmPackages = NpmHelper.GetInstalledNpmPackages();

        if (!installedNpmPackages.Contains(" yarn@"))
        {
            NpmHelper.InstallYarn();
        }
    }
예제 #2
0
    public async Task UpsertPackageAsync(ILocalPackage package)
    {
        Console.WriteLine("Upserting package " + package.PublishName + " version " + package.Version + " to remote package repository.");

        await NpmHelper.PublishAsync(
            package.FolderPath,
            _npmSettings.AuthToken);

        package.PublishUrl = $"https://www.npmjs.com/package/{package.PublishName}/v/{package.Version}";
    }
예제 #3
0
        public static string GetAutoRestPath(bool withoutPath = false)
        {
            if (Environment.OSVersion.Platform == PlatformID.MacOSX ||
                Environment.OSVersion.Platform == PlatformID.Unix ||
                withoutPath)
            {
                return("autorest");
            }

            return(Path.Combine(
                       NpmHelper.GetPrefixPath(),
                       "autorest.cmd"));
        }
예제 #4
0
 public void TryGetNpmPrefixPathFromNpmConfig_Returns_Null_Upon_Exception(IProcessLauncher process)
 {
     Mock.Get(process)
     .Setup(
         c => c.Start(
             It.IsAny <string>(),
             It.IsAny <string>(),
             It.IsAny <Action <string> >(),
             It.IsAny <Action <string> >(),
             It.IsAny <string>()))
     .Throws <Exception>();
     NpmHelper.TryGetNpmPrefixPathFromNpmConfig(process)
     .Should()
     .BeNull();
 }
        public void TryGetNpmPrefixPathFromNpmConfig()
        {
            var mock = new Mock <IProcessLauncher>();

            mock.Setup(
                c => c.Start(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <Action <string> >(),
                    It.IsAny <Action <string> >(),
                    It.IsAny <string>()))
            .Throws(new Exception());
            NpmHelper.TryGetNpmPrefixPathFromNpmConfig(mock.Object)
            .Should()
            .BeNullOrEmpty();
        }
예제 #6
0
    private void AddPackage(List <string> packageJsonFilePaths, string package, string version)
    {
        if (!packageJsonFilePaths.Any() || string.IsNullOrWhiteSpace(package))
        {
            return;
        }

        var yarnAvailable = NpmHelper.IsYarnAvailable();

        foreach (var packageJsonFilePath in packageJsonFilePaths)
        {
            var directory = Path.GetDirectoryName(packageJsonFilePath).EnsureEndsWith(Path.DirectorySeparatorChar);
            if (yarnAvailable)
            {
                NpmHelper.YarnAddPackage(package, version, directory);
            }
            else
            {
                NpmHelper.NpmInstallPackage(package, version, directory);
            }
        }
    }
예제 #7
0
 public void TryGetNpmPrefixPathFromNpmConfig_Returns_NotNull()
 {
     NpmHelper.TryGetNpmPrefixPathFromNpmConfig()
     .Should()
     .NotBeNull();
 }
예제 #8
0
 public ThemePackageAdder(NpmHelper npmHelper, PackageJsonFileFinder packageJsonFileFinder)
 {
     NpmHelper             = npmHelper;
     PackageJsonFileFinder = packageJsonFileFinder;
 }
예제 #9
0
 public NpmGlobalPackagesChecker(NpmHelper npmHelper)
 {
     NpmHelper = npmHelper;
     Logger    = NullLogger <NpmGlobalPackagesChecker> .Instance;
 }
예제 #10
0
 public void DirectoryExists_GetNpmPrefixPath()
 => Directory.Exists(NpmHelper.GetPrefixPath())
 .Should()
 .BeTrue();
예제 #11
0
 public void Can_GetNpmPrefixPath()
 => NpmHelper.GetPrefixPath()
 .Should()
 .NotBeNullOrWhiteSpace();
예제 #12
0
 public void FileExists_GetNpmPath()
 => File.Exists(NpmHelper.GetNpmPath())
 .Should()
 .BeTrue();
예제 #13
0
 public void GetNpmPath_IgnorePath_Returns_Npm()
 => NpmHelper.GetNpmPath(true)
 .Should()
 .Be("npm");
예제 #14
0
    public async Task InstallLibsAsync(string directory)
    {
        var projectPaths = FindAllProjects(directory);

        if (!projectPaths.Any())
        {
            Logger.LogError("No project found in the directory.");
            return;
        }

        if (!NpmHelper.IsNpmInstalled())
        {
            Logger.LogWarning("NPM is not installed, visit https://nodejs.org/en/download/ and install NPM");
            return;
        }

        if (!NpmHelper.IsYarnAvailable())
        {
            Logger.LogWarning("YARN is not installed, which may cause package inconsistency, please use YARN instead of NPM. visit https://classic.yarnpkg.com/lang/en/docs/install/ and install YARN");
        }

        Logger.LogInformation($"Found {projectPaths.Count} projects.");
        foreach (var projectPath in projectPaths)
        {
            Logger.LogInformation($"{Path.GetDirectoryName(projectPath)}");
        }

        foreach (var projectPath in projectPaths)
        {
            var projectDirectory = Path.GetDirectoryName(projectPath);

            // angular
            if (projectPath.EndsWith("angular.json"))
            {
                if (NpmHelper.IsYarnAvailable())
                {
                    NpmHelper.RunYarn(projectDirectory);
                }
                else
                {
                    NpmHelper.RunNpmInstall(projectDirectory);
                }
            }

            // MVC or BLAZOR SERVER
            if (projectPath.EndsWith(".csproj"))
            {
                var packageJsonFilePath = Path.Combine(Path.GetDirectoryName(projectPath), "package.json");

                if (!File.Exists(packageJsonFilePath))
                {
                    continue;
                }

                if (NpmHelper.IsYarnAvailable())
                {
                    NpmHelper.RunYarn(projectDirectory);
                }
                else
                {
                    NpmHelper.RunNpmInstall(projectDirectory);
                }

                await CleanAndCopyResources(projectDirectory);
            }
        }
    }
예제 #15
0
 public InstallLibsService(IJsonSerializer jsonSerializer, NpmHelper npmHelper)
 {
     NpmHelper       = npmHelper;
     _jsonSerializer = jsonSerializer;
 }