diff --git a/cmd/authelia-gen/cmd_commit_msg.go b/cmd/authelia-gen/cmd_commit_msg.go index cadf70d68..5565fed40 100644 --- a/cmd/authelia-gen/cmd_commit_msg.go +++ b/cmd/authelia-gen/cmd_commit_msg.go @@ -110,7 +110,7 @@ func commitLintRunE(cmd *cobra.Command, args []string) (err error) { return err } - if pathCommitLintConfig, err = cmd.Flags().GetString(cmdFlagFileConfigCommitLint); err != nil { + if pathCommitLintConfig, err = getPFlagPath(cmd.Flags(), cmdFlagRoot, cmdFlagWeb, cmdFlagFileConfigCommitLint); err != nil { return err } diff --git a/cmd/authelia-gen/cmd_docs_data.go b/cmd/authelia-gen/cmd_docs_data.go index 2ece27952..5218002a8 100644 --- a/cmd/authelia-gen/cmd_docs_data.go +++ b/cmd/authelia-gen/cmd_docs_data.go @@ -51,6 +51,26 @@ func docsDataMiscRunE(cmd *cobra.Command, args []string) (err error) { data.CSP.TemplateDefault = strings.ReplaceAll(data.CSP.TemplateDefault, "%s", codeCSPNonce) data.CSP.TemplateDevelopment = strings.ReplaceAll(data.CSP.TemplateDevelopment, "%s", codeCSPNonce) + var ( + pathPackageJSON string + dataPackageJSON []byte + packageJSON PackageJSON + ) + + if pathPackageJSON, err = getPFlagPath(cmd.Flags(), cmdFlagRoot, cmdFlagWeb, cmdFlagFileWebPackage); err != nil { + return err + } + + if dataPackageJSON, err = os.ReadFile(pathPackageJSON); err != nil { + return err + } + + if err = json.Unmarshal(dataPackageJSON, &packageJSON); err != nil { + return fmt.Errorf("failed to unmarshall package.json: %w", err) + } + + data.Latest = packageJSON.Version + var ( outputPath string dataJSON []byte diff --git a/cmd/authelia-gen/cmd_locales.go b/cmd/authelia-gen/cmd_locales.go index 0fcc390c3..b0a028371 100644 --- a/cmd/authelia-gen/cmd_locales.go +++ b/cmd/authelia-gen/cmd_locales.go @@ -42,7 +42,7 @@ func localesRunE(cmd *cobra.Command, args []string) (err error) { return err } - if pathWebI18NIndex, err = cmd.Flags().GetString(cmdFlagFileWebI18N); err != nil { + if pathWebI18NIndex, err = getPFlagPath(cmd.Flags(), cmdFlagRoot, cmdFlagWeb, cmdFlagFileWebI18N); err != nil { return err } diff --git a/cmd/authelia-gen/cmd_root.go b/cmd/authelia-gen/cmd_root.go index d0809957c..6fccc6068 100644 --- a/cmd/authelia-gen/cmd_root.go +++ b/cmd/authelia-gen/cmd_root.go @@ -26,12 +26,14 @@ func newRootCmd() *cobra.Command { cmd.PersistentFlags().StringP(cmdFlagCwd, "C", "", "Sets the CWD for git commands") cmd.PersistentFlags().StringP(cmdFlagRoot, "d", dirCurrent, "The repository root") + cmd.PersistentFlags().String(cmdFlagWeb, dirWeb, "The repository web directory in relation to the root directory") cmd.PersistentFlags().StringSliceP(cmdFlagExclude, "X", nil, "Sets the names of excluded generators") cmd.PersistentFlags().String(cmdFlagFeatureRequest, fileGitHubIssueTemplateFR, "Sets the path of the feature request issue template file") cmd.PersistentFlags().String(cmdFlagBugReport, fileGitHubIssueTemplateBR, "Sets the path of the bug report issue template file") cmd.PersistentFlags().Int(cmdFlagVersions, 5, "the maximum number of minor versions to list in output templates") cmd.PersistentFlags().String(cmdFlagDirLocales, dirLocales, "The locales directory in relation to the root") - cmd.PersistentFlags().String(cmdFlagFileWebI18N, fileWebI18NIndex, "The i18n typescript configuration file in relation to the root") + cmd.PersistentFlags().String(cmdFlagFileWebI18N, fileWebI18NIndex, "The i18n typescript configuration file in relation to the web directory") + cmd.PersistentFlags().String(cmdFlagFileWebPackage, fileWebPackage, "The node package configuration file in relation to the web directory") cmd.PersistentFlags().String(cmdFlagDocsDataLanguages, fileDocsDataLanguages, "The languages docs data file in relation to the docs data folder") cmd.PersistentFlags().String(cmdFlagDocsDataMisc, fileDocsDataMisc, "The misc docs data file in relation to the docs data folder") cmd.PersistentFlags().String(cmdFlagDocsCLIReference, dirDocsCLIReference, "The directory to store the markdown in") diff --git a/cmd/authelia-gen/const.go b/cmd/authelia-gen/const.go index f68364e9e..811390896 100644 --- a/cmd/authelia-gen/const.go +++ b/cmd/authelia-gen/const.go @@ -3,12 +3,14 @@ package main const ( dirCurrent = "./" dirLocales = "internal/server/locales" + dirWeb = "web" subPathCmd = "cmd" subPathInternal = "internal" - fileCICommitLintConfig = "web/.commitlintrc.js" - fileWebI18NIndex = "web/src/i18n/index.ts" + fileCICommitLintConfig = ".commitlintrc.js" + fileWebI18NIndex = "src/i18n/index.ts" + fileWebPackage = "package.json" fileDocsCommitMessageGuidelines = "docs/content/en/contributing/guidelines/commit-message.md" @@ -68,27 +70,30 @@ const ( const ( cmdFlagRoot = "dir.root" - cmdFlagExclude = "exclude" - cmdFlagVersions = "versions" + cmdFlagWeb = "dir.web" + cmdFlagFileWebI18N = "file.web.i18n" + cmdFlagFileWebPackage = "file.web.package" + cmdFlagDocs = "dir.docs" cmdFlagDirLocales = "dir.locales" cmdFlagDocsCLIReference = "dir.docs.cli-reference" cmdFlagDocsContent = "dir.docs.content" cmdFlagDocsData = "dir.docs.data" - cmdFlagDocs = "dir.docs" - cmdFlagDocsDataLanguages = "file.docs.data.languages" cmdFlagDocsDataMisc = "file.docs.data.misc" cmdFlagDocsDataKeys = "file.docs.data.keys" - cmdFlagCwd = "cwd" + cmdFlagDocsDataLanguages = "file.docs.data.languages" cmdFlagFileConfigKeys = "file.configuration-keys" cmdFlagFileScriptsGen = "file.scripts.gen" cmdFlagFileServerGenerated = "file.server.generated" cmdFlagFileConfigCommitLint = "file.commit-lint-config" cmdFlagFileDocsCommitMsgGuidelines = "file.docs-commit-msg-guidelines" - cmdFlagFileWebI18N = "file.web-i18n" cmdFlagFeatureRequest = "file.feature-request" cmdFlagBugReport = "file.bug-report" - cmdFlagPackageConfigKeys = "package.configuration.keys" - cmdFlagPackageScriptsGen = "package.scripts.gen" + + cmdFlagExclude = "exclude" + cmdFlagVersions = "versions" + cmdFlagCwd = "cwd" + cmdFlagPackageConfigKeys = "package.configuration.keys" + cmdFlagPackageScriptsGen = "package.scripts.gen" ) const ( diff --git a/cmd/authelia-gen/types.go b/cmd/authelia-gen/types.go index 479f0410d..7f3183a4c 100644 --- a/cmd/authelia-gen/types.go +++ b/cmd/authelia-gen/types.go @@ -32,7 +32,8 @@ type GitHubTagsJSON struct { // DocsDataMisc represents the docs misc data schema. type DocsDataMisc struct { - CSP TemplateCSP `json:"csp"` + CSP TemplateCSP `json:"csp"` + Latest string `json:"latest"` } // TemplateCSP represents the CSP template vars. @@ -139,7 +140,13 @@ func (t labelType) String() string { return fmt.Sprintf("%s/%s", labelAreaPrefixType, labelTypeDescriptions[t]) } +// CSPValue represents individual CSP values. type CSPValue struct { Name string Value string } + +// PackageJSON represents a NPM package.json file. +type PackageJSON struct { + Version string `json:"version"` +} diff --git a/docs/data/misc.json b/docs/data/misc.json index f20002991..304b2d8bd 100644 --- a/docs/data/misc.json +++ b/docs/data/misc.json @@ -1 +1 @@ -{"csp":{"default":"default-src 'self'; frame-src 'none'; object-src 'none'; style-src 'self' 'nonce-${NONCE}'; frame-ancestors 'none'; base-uri 'self'","development":"default-src 'self' 'unsafe-eval'; frame-src 'none'; object-src 'none'; style-src 'self' 'nonce-${NONCE}'; frame-ancestors 'none'; base-uri 'self'","nonce":"${NONCE}"}} \ No newline at end of file +{"csp":{"default":"default-src 'self'; frame-src 'none'; object-src 'none'; style-src 'self' 'nonce-${NONCE}'; frame-ancestors 'none'; base-uri 'self'","development":"default-src 'self' 'unsafe-eval'; frame-src 'none'; object-src 'none'; style-src 'self' 'nonce-${NONCE}'; frame-ancestors 'none'; base-uri 'self'","nonce":"${NONCE}"},"latest":"4.37.5"} \ No newline at end of file diff --git a/docs/layouts/index.html b/docs/layouts/index.html index ae4c6247d..ceb7dd3c9 100644 --- a/docs/layouts/index.html +++ b/docs/layouts/index.html @@ -7,7 +7,7 @@

{{ .Params.lead | safeHTML }}

Get Started -

Open-source Apache 2.0 Licensed. GitHub v{{ $data := getJSON "https://raw.githubusercontent.com/authelia/authelia/master/web/package.json" }}{{ $data.version }}

+

Open-source Apache 2.0 Licensed. GitHub v{{ $.Site.Data.misc.latest }}