|
|
|
@ -23,6 +23,7 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
{
|
|
|
|
|
public ILogger<NpmPackagesUpdater> Logger { get; set; }
|
|
|
|
|
protected ICancellationTokenProvider CancellationTokenProvider { get; }
|
|
|
|
|
public InstallLibsCommand InstallLibsCommand { get; }
|
|
|
|
|
public ICmdHelper CmdHelper { get; }
|
|
|
|
|
|
|
|
|
|
private readonly PackageJsonFileFinder _packageJsonFileFinder;
|
|
|
|
@ -35,17 +36,21 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
NpmGlobalPackagesChecker npmGlobalPackagesChecker,
|
|
|
|
|
ICancellationTokenProvider cancellationTokenProvider,
|
|
|
|
|
CliHttpClientFactory cliHttpClientFactory,
|
|
|
|
|
InstallLibsCommand ınstallLibsCommand,
|
|
|
|
|
ICmdHelper cmdHelper)
|
|
|
|
|
{
|
|
|
|
|
_packageJsonFileFinder = packageJsonFileFinder;
|
|
|
|
|
_npmGlobalPackagesChecker = npmGlobalPackagesChecker;
|
|
|
|
|
CancellationTokenProvider = cancellationTokenProvider;
|
|
|
|
|
InstallLibsCommand = ınstallLibsCommand;
|
|
|
|
|
CmdHelper = cmdHelper;
|
|
|
|
|
_cliHttpClientFactory = cliHttpClientFactory;
|
|
|
|
|
Logger = NullLogger<NpmPackagesUpdater>.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Update(string rootDirectory, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, string version = null)
|
|
|
|
|
public async Task Update(string rootDirectory, bool includePreviews = false,
|
|
|
|
|
bool includeReleaseCandidates = false,
|
|
|
|
|
bool switchToStable = false, string version = null)
|
|
|
|
|
{
|
|
|
|
|
var fileList = _packageJsonFileFinder.Find(rootDirectory);
|
|
|
|
|
|
|
|
|
@ -60,7 +65,9 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
|
|
|
|
|
async Task UpdateAsync(string file)
|
|
|
|
|
{
|
|
|
|
|
var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates, switchToStable, version);
|
|
|
|
|
var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates,
|
|
|
|
|
switchToStable,
|
|
|
|
|
version);
|
|
|
|
|
packagesUpdated.TryAdd(file, updated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -88,10 +95,10 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
RunYarn(fileDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsAngularProject(fileDirectory) && GulpFileExistAsync(fileDirectory))
|
|
|
|
|
if (!IsAngularProject(fileDirectory))
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
RunGulp(fileDirectory);
|
|
|
|
|
RunInstallLibsAsync(fileDirectory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -108,11 +115,6 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
return await Task.FromResult(File.Exists(Path.Combine(directoryName, ".npmrc")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool GulpFileExistAsync(string directoryName)
|
|
|
|
|
{
|
|
|
|
|
return File.Exists(Path.Combine(directoryName, "gulpfile.js"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CreateNpmrcFileAsync(string directoryName)
|
|
|
|
|
{
|
|
|
|
|
var fileName = Path.Combine(directoryName, ".npmrc");
|
|
|
|
@ -121,7 +123,6 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
|
|
|
|
|
if (await NpmrcFileExistAsync(directoryName))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(fileName);
|
|
|
|
|
|
|
|
|
|
if (!fileContent.Contains(abpRegistry))
|
|
|
|
@ -164,10 +165,10 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
{
|
|
|
|
|
var client = _cliHttpClientFactory.CreateClient();
|
|
|
|
|
using (var response = await client.GetHttpResponseMessageWithRetryAsync(
|
|
|
|
|
url: $"{CliUrls.WwwAbpIo}api/myget/apikey/",
|
|
|
|
|
cancellationToken: CancellationTokenProvider.Token,
|
|
|
|
|
logger: Logger
|
|
|
|
|
))
|
|
|
|
|
url: $"{CliUrls.WwwAbpIo}api/myget/apikey/",
|
|
|
|
|
cancellationToken: CancellationTokenProvider.Token,
|
|
|
|
|
logger: Logger
|
|
|
|
|
))
|
|
|
|
|
{
|
|
|
|
|
return Encoding.Default.GetString(await response.Content.ReadAsByteArrayAsync());
|
|
|
|
|
}
|
|
|
|
@ -202,7 +203,8 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
|
|
|
|
|
foreach (var abpPackage in abpPackages)
|
|
|
|
|
{
|
|
|
|
|
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates, switchToStable, specifiedVersion);
|
|
|
|
|
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates,
|
|
|
|
|
switchToStable, specifiedVersion);
|
|
|
|
|
|
|
|
|
|
if (updated)
|
|
|
|
|
{
|
|
|
|
@ -236,15 +238,19 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SemanticVersion.Parse(specifiedVersion) <= SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^")))
|
|
|
|
|
if (SemanticVersion.Parse(specifiedVersion) <=
|
|
|
|
|
SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^")))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
version = specifiedVersion.EnsureStartsWith('^');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((includePreviews || (!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) && !includeReleaseCandidates)
|
|
|
|
|
if ((includePreviews ||
|
|
|
|
|
(!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) &&
|
|
|
|
|
!includeReleaseCandidates)
|
|
|
|
|
{
|
|
|
|
|
version = "preview";
|
|
|
|
|
}
|
|
|
|
@ -328,16 +334,18 @@ namespace Volo.Abp.Cli.ProjectModification
|
|
|
|
|
|
|
|
|
|
abpPackages
|
|
|
|
|
.AddRange(properties.Where(p => p.Name.StartsWith("@abp/") || p.Name.StartsWith("@volo/"))
|
|
|
|
|
.ToList());
|
|
|
|
|
.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return abpPackages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void RunGulp(string fileDirectory)
|
|
|
|
|
protected virtual async Task RunInstallLibsAsync(string fileDirectory)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Running Gulp on {fileDirectory}");
|
|
|
|
|
CmdHelper.RunCmd($"cd {fileDirectory} && gulp");
|
|
|
|
|
var args = new CommandLineArgs("install-libs");
|
|
|
|
|
args.Options.Add(BundleCommand.Options.WorkingDirectory.Short, fileDirectory);
|
|
|
|
|
|
|
|
|
|
await InstallLibsCommand.ExecuteAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void RunYarn(string fileDirectory)
|
|
|
|
|