public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_account)) { _account = ReadUtils.GetString("Username:"******"Password:"******"you have successful logged in"); } else { await WriteUtils.PrintErrorAsync(failureMessage); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (!await _configRepository.IsNeedInstallAsync()) { await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {_settingsManager.ContentRootPath}"); return; } var userName = string.IsNullOrEmpty(_userName) ? ReadUtils.GetString("Super administrator username:"******"Super administrator password:"******"index.html"), Constants.Html5Empty); await WriteUtils.PrintSuccessAsync("Congratulations, SS CMS was installed successfully!"); }
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 static async Task <(bool Success, string name, string filePath)> PackageAsync(IPathManager pathManager, ICacheManager cacheManager, IDatabaseManager databaseManager, string directory, bool isOverride) { var site = await databaseManager.SiteRepository.GetSiteByDirectoryAsync(directory); var sitePath = await pathManager.GetSitePathAsync(site); if (site == null || !DirectoryUtils.IsDirectoryExists(sitePath)) { await WriteUtils.PrintErrorAsync($@"Invalid site directory path: ""{directory}"""); return(false, null, null); } var readme = string.Empty; Theme theme = null; var readmePath = PathUtils.Combine(sitePath, "README.md"); if (FileUtils.IsFileExists(readmePath)) { readme = FileUtils.ReadText(readmePath); var yaml = MarkdownUtils.GetYamlFrontMatter(readme); if (!string.IsNullOrEmpty(yaml)) { readme = MarkdownUtils.RemoveYamlFrontMatter(readme); theme = YamlUtils.Deserialize <Theme>(yaml); } } var writeReadme = false; if (theme == null || string.IsNullOrEmpty(theme.Name) || string.IsNullOrEmpty(theme.CoverUrl)) { writeReadme = true; theme = new Theme { Name = ReadUtils.GetString("name:"), CoverUrl = ReadUtils.GetString("cover image url:"), Summary = ReadUtils.GetString("repository url:"), Tags = ReadUtils.GetStringList("tags:"), ThumbUrls = ReadUtils.GetStringList("thumb image urls:"), Compatibilities = ReadUtils.GetStringList("compatibilities:"), Price = ReadUtils.GetYesNo("is free?") ? 0 : ReadUtils.GetDecimal("price:"), }; } if (writeReadme) { readme = @$ "--- {YamlUtils.Serialize(theme)} --- " + readme; FileUtils.WriteText(readmePath, readme); } var packageName = "T_" + theme.Name.Replace(" ", "_"); var packagePath = pathManager.GetSiteTemplatesPath(packageName); var fileName = packageName + ".zip"; var filePath = pathManager.GetSiteTemplatesPath(fileName); if (!isOverride && FileUtils.IsFileExists(filePath)) { return(true, theme.Name, filePath); } FileUtils.DeleteFileIfExists(filePath); DirectoryUtils.DeleteDirectoryIfExists(packagePath); await Console.Out.WriteLineAsync($"Theme name: {theme.Name}"); await Console.Out.WriteLineAsync($"Theme folder: {packagePath}"); await Console.Out.WriteLineAsync("Theme packaging..."); var caching = new CacheUtils(cacheManager); var manager = new SiteTemplateManager(pathManager, databaseManager, caching); if (manager.IsSiteTemplateDirectoryExists(packageName)) { manager.DeleteSiteTemplate(packageName); } var directoryNames = DirectoryUtils.GetDirectoryNames(sitePath); var directories = new List <string>(); var siteDirList = await databaseManager.SiteRepository.GetSiteDirsAsync(0); foreach (var directoryName in directoryNames) { var isSiteDirectory = false; if (site.Root) { foreach (var siteDir in siteDirList) { if (StringUtils.EqualsIgnoreCase(siteDir, directoryName)) { isSiteDirectory = true; } } } if (!isSiteDirectory && !pathManager.IsSystemDirectory(directoryName)) { directories.Add(directoryName); } } var files = DirectoryUtils.GetFileNames(sitePath); var exportObject = new ExportObject(pathManager, databaseManager, caching, site); await exportObject.ExportFilesToSiteAsync(packagePath, true, directories, files, true); var siteContentDirectoryPath = pathManager.GetSiteTemplateMetadataPath(packagePath, DirectoryUtils.SiteFiles.SiteTemplates.SiteContent); await exportObject.ExportSiteContentAsync(siteContentDirectoryPath, true, true, new List <int>()); await SiteTemplateManager.ExportSiteToSiteTemplateAsync(pathManager, databaseManager, caching, site, packageName); var siteTemplateInfo = new SiteTemplateInfo { SiteTemplateName = theme.Name, PicFileName = string.Empty, WebSiteUrl = string.Empty, Description = string.Empty }; var xmlPath = pathManager.GetSiteTemplateMetadataPath(packagePath, DirectoryUtils.SiteFiles.SiteTemplates.FileMetadata); XmlUtils.SaveAsXml(siteTemplateInfo, xmlPath); pathManager.CreateZip(filePath, packagePath); return(true, theme.Name, filePath); }