public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var pluginsPath = CliUtils.IsSsCmsExists(_settingsManager.ContentRootPath) ? _pathManager.PluginsPath : _settingsManager.ContentRootPath; var(status, _) = await _apiService.GetStatusAsync(); var publisher = status == null ? ReadUtils.GetString("What's the publisher of your plugin?") : status.UserName; if (status == null && !StringUtils.IsStrictName(publisher)) { await WriteUtils.PrintErrorAsync( $@"Invalid plugin publisher: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}"""); return; } var name = ReadUtils.GetString("What's the name of your plugin?"); if (!StringUtils.IsStrictName(name)) { await WriteUtils.PrintErrorAsync( $@"Invalid plugin name: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}"""); return; } var pluginId = PluginUtils.GetPluginId(publisher, name); var pluginPath = PathUtils.Combine(pluginsPath, pluginId); var dict = new Dictionary <string, object> { ["name"] = name, ["publisher"] = publisher }; var json = TranslateUtils.JsonSerialize(dict); await FileUtils.WriteTextAsync(PathUtils.Combine(pluginPath, Constants.PackageFileName), json); await WriteUtils.PrintSuccessAsync($@"The plugin ""{pluginId}"" was created successfully."); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var contentRootPath = _settingsManager.ContentRootPath; if (!CliUtils.IsSsCmsExists(contentRootPath)) { var(success, result, failureMessage) = await _apiService.GetReleasesAsync(_settingsManager.Version, null); if (!success) { await WriteUtils.PrintErrorAsync(failureMessage); return; } var proceed = ReadUtils.GetYesNo($"Do you want to install SS CMS in {contentRootPath}?"); if (!proceed) { return; } Console.WriteLine($"Downloading SS CMS {result.Cms.Version}..."); var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version); await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!"); DirectoryUtils.Copy(directoryPath, contentRootPath, true); } InstallUtils.Init(contentRootPath); if (!await _configRepository.IsNeedInstallAsync()) { await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {contentRootPath}"); return; } var databaseTypeInput = ReadUtils.GetSelect("Database type", new List <string> { DatabaseType.MySql.GetValue().ToLower(), DatabaseType.SqlServer.GetValue().ToLower(), DatabaseType.PostgreSql.GetValue().ToLower(), DatabaseType.SQLite.GetValue().ToLower() }); var databaseType = TranslateUtils.ToEnum(databaseTypeInput, DatabaseType.MySql); var databaseName = string.Empty; var databaseHost = string.Empty; var isDatabaseDefaultPort = true; var databasePort = 0; var databaseUserName = string.Empty; var databasePassword = string.Empty; if (databaseType != DatabaseType.SQLite) { databaseHost = ReadUtils.GetString("Database hostname / IP:"); isDatabaseDefaultPort = ReadUtils.GetYesNo("Use default port?"); if (!isDatabaseDefaultPort) { databasePort = ReadUtils.GetInt("Database port:"); } databaseUserName = ReadUtils.GetString("Database userName:"******"Database password:"******"Database name", databaseNames); } var databaseConnectionString = InstallUtils.GetDatabaseConnectionString(databaseType, databaseHost, isDatabaseDefaultPort, databasePort, databaseUserName, databasePassword, databaseName); var isProtectData = ReadUtils.GetYesNo("Protect settings in sscms.json?"); _settingsManager.SaveSettings(isProtectData, false, false, databaseType, databaseConnectionString, string.Empty, string.Empty, null, null); await WriteUtils.PrintSuccessAsync("SS CMS was download and ready for install, please run: sscms install database"); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var contentRootPath = _settingsManager.ContentRootPath; if (!CliUtils.IsSsCmsExists(contentRootPath) || await _configRepository.IsNeedInstallAsync()) { await WriteUtils.PrintErrorAsync($"SS CMS has not been installed in {contentRootPath}"); return; } var(success, result, failureMessage) = _apiService.GetReleases(_settingsManager.Version, null); if (!success) { await WriteUtils.PrintErrorAsync(failureMessage); return; } if (!SemVersion.TryParse(result.Cms.Version, out var version) || version <= _settingsManager.Version) { Console.WriteLine($"SS CMS {result.Cms.Version} is the latest version and no update is required"); var proceed = ReadUtils.GetYesNo("do you still want to update?"); if (!proceed) { return; } } else { var proceed = ReadUtils.GetYesNo($"New version {result.Cms.Version} found, do you want to update?"); if (!proceed) { return; } } Console.WriteLine($"Downloading SS CMS {result.Cms.Version}..."); var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version); FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, Constants.ConfigFileName)); FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/404.html")); FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/favicon.ico")); FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/index.html")); await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please stop website and override files and directories "); Console.WriteLine($" {directoryPath}"); Console.WriteLine("to"); Console.WriteLine($" {contentRootPath}"); var offlinePath = _pathManager.GetPackagesPath("app_offline.htm"); FileUtils.WriteText(offlinePath, "down for maintenance"); //var unOverrides = new List<string>(); //foreach (var fileName in DirectoryUtils.GetFileNames(directoryPath)) //{ // if (!FileUtils.CopyFile(PathUtils.Combine(directoryPath, fileName), // PathUtils.Combine(contentRootPath, fileName), true)) // { // unOverrides.Add(fileName); // } //} //foreach (var directoryName in DirectoryUtils.GetDirectoryNames(directoryPath)) //{ // DirectoryUtils.Copy(PathUtils.Combine(directoryPath, directoryName), PathUtils.Combine(contentRootPath, directoryName), true); //} //if (unOverrides.Count > 0) //{ // Replacing(contentRootPath, directoryPath, unOverrides); //} //FileUtils.DeleteFileIfExists(offlinePath); //await WriteUtils.PrintSuccessAsync($"Congratulations, SS CMS was updated to {result.Cms.Version} successfully!"); }