@slicemachine/init 2.8.2-dev-next-release.2 → 2.8.2-dev-next-release.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SliceMachineInitProcess.cjs +3 -3
- package/dist/SliceMachineInitProcess.cjs.map +1 -1
- package/dist/SliceMachineInitProcess.js +4 -4
- package/dist/SliceMachineInitProcess.js.map +1 -1
- package/dist/_node_modules/@babel/code-frame/lib/index.cjs +2 -2
- package/dist/_node_modules/@babel/code-frame/lib/index.js +2 -2
- package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.cjs +1 -1
- package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.js +1 -1
- package/dist/_node_modules/@babel/highlight/lib/index.cjs +3 -3
- package/dist/_node_modules/@babel/highlight/lib/index.js +3 -3
- package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.cjs +1 -1
- package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.js +1 -1
- package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.cjs +1 -1
- package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.js +1 -1
- package/dist/_node_modules/@nodelib/fs.scandir/out/settings.cjs +1 -1
- package/dist/_node_modules/@nodelib/fs.scandir/out/settings.js +1 -1
- package/dist/_node_modules/@nodelib/fs.stat/out/index.cjs +1 -1
- package/dist/_node_modules/@nodelib/fs.stat/out/index.js +1 -1
- package/dist/_node_modules/@nodelib/fs.walk/out/index.cjs +1 -1
- package/dist/_node_modules/@nodelib/fs.walk/out/index.js +1 -1
- package/dist/_node_modules/cross-spawn/index.cjs +1 -1
- package/dist/_node_modules/cross-spawn/index.js +1 -1
- package/dist/_node_modules/dir-glob/index.cjs +2 -2
- package/dist/_node_modules/dir-glob/index.js +2 -2
- package/dist/_node_modules/fast-glob/out/index.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/index.js +1 -1
- package/dist/_node_modules/fast-glob/out/managers/tasks.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/managers/tasks.js +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/deep.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/deep.js +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/entry.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/entry.js +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/error.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/providers/filters/error.js +1 -1
- package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.js +1 -1
- package/dist/_node_modules/fast-glob/out/providers/transformers/entry.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/providers/transformers/entry.js +1 -1
- package/dist/_node_modules/fast-glob/out/readers/async.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/readers/async.js +1 -1
- package/dist/_node_modules/fast-glob/out/readers/reader.cjs +2 -2
- package/dist/_node_modules/fast-glob/out/readers/reader.js +2 -2
- package/dist/_node_modules/fast-glob/out/readers/stream.cjs +2 -2
- package/dist/_node_modules/fast-glob/out/readers/stream.js +2 -2
- package/dist/_node_modules/fast-glob/out/readers/sync.cjs +2 -2
- package/dist/_node_modules/fast-glob/out/readers/sync.js +2 -2
- package/dist/_node_modules/fast-glob/out/utils/index.cjs +1 -1
- package/dist/_node_modules/fast-glob/out/utils/index.js +1 -1
- package/dist/_node_modules/get-stream/index.cjs +1 -1
- package/dist/_node_modules/get-stream/index.js +1 -1
- package/dist/_node_modules/js-tokens/index.cjs +1 -1
- package/dist/_node_modules/js-tokens/index.js +1 -1
- package/dist/_node_modules/lines-and-columns/build/index.cjs +1 -1
- package/dist/_node_modules/lines-and-columns/build/index.js +1 -1
- package/dist/_node_modules/map-obj/index.cjs +1 -1
- package/dist/_node_modules/map-obj/index.js +1 -1
- package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.cjs +1 -1
- package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.js +1 -1
- package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.cjs +1 -1
- package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.js +1 -1
- package/dist/_node_modules/parse-json/index.cjs +2 -2
- package/dist/_node_modules/parse-json/index.js +2 -2
- package/dist/_node_modules/path-key/index.cjs +1 -1
- package/dist/_node_modules/path-key/index.js +1 -1
- package/dist/_node_modules/path-type/index.cjs +1 -1
- package/dist/_node_modules/path-type/index.js +1 -1
- package/dist/_node_modules/signal-exit/index.cjs +1 -1
- package/dist/_node_modules/signal-exit/index.js +1 -1
- package/dist/_virtual/index10.cjs +2 -2
- package/dist/_virtual/index10.js +2 -2
- package/dist/_virtual/index11.cjs +2 -2
- package/dist/_virtual/index11.js +2 -2
- package/dist/_virtual/index12.cjs +2 -2
- package/dist/_virtual/index12.js +2 -2
- package/dist/_virtual/index13.cjs +2 -2
- package/dist/_virtual/index13.js +2 -2
- package/dist/_virtual/index15.cjs +2 -2
- package/dist/_virtual/index15.js +2 -2
- package/dist/_virtual/index16.cjs +2 -2
- package/dist/_virtual/index16.js +2 -2
- package/dist/_virtual/index17.cjs +2 -2
- package/dist/_virtual/index17.js +2 -2
- package/dist/_virtual/index18.cjs +2 -2
- package/dist/_virtual/index18.js +2 -2
- package/dist/_virtual/index19.cjs +2 -2
- package/dist/_virtual/index19.js +2 -2
- package/dist/_virtual/index3.cjs +2 -2
- package/dist/_virtual/index3.js +2 -2
- package/dist/_virtual/index4.cjs +2 -2
- package/dist/_virtual/index4.js +2 -2
- package/dist/_virtual/index5.cjs +2 -2
- package/dist/_virtual/index5.js +2 -2
- package/dist/_virtual/index6.cjs +2 -2
- package/dist/_virtual/index6.js +2 -2
- package/dist/_virtual/index7.cjs +2 -2
- package/dist/_virtual/index7.js +2 -2
- package/dist/_virtual/index8.cjs +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/_virtual/index9.cjs +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/lib/repositoryDomain.cjs +9 -8
- package/dist/lib/repositoryDomain.cjs.map +1 -1
- package/dist/lib/repositoryDomain.d.ts +2 -2
- package/dist/lib/repositoryDomain.js +9 -8
- package/dist/lib/repositoryDomain.js.map +1 -1
- package/dist/packages/init/package.json.cjs +4 -4
- package/dist/packages/init/package.json.js +4 -4
- package/package.json +4 -4
- package/src/SliceMachineInitProcess.ts +16 -7
- package/src/lib/repositoryDomain.ts +16 -8
package/dist/_virtual/index6.js
CHANGED
package/dist/_virtual/index7.cjs
CHANGED
package/dist/_virtual/index7.js
CHANGED
package/dist/_virtual/index8.cjs
CHANGED
package/dist/_virtual/index8.js
CHANGED
package/dist/_virtual/index9.cjs
CHANGED
package/dist/_virtual/index9.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const manager = require("@slicemachine/manager");
|
|
3
4
|
const abc123 = `abcdefghijklmnopqrstuvwxyz0123456789`;
|
|
4
5
|
const ADJECTIVES = [
|
|
5
6
|
"adorable",
|
|
@@ -67,8 +68,8 @@ const assertFormattedRepositoryDomain = (maybeFormattedRepositoryDomain, caller)
|
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
const ValidationErrors = {
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
LessThanMin: "LessThanMin",
|
|
72
|
+
MoreThanMax: "MoreThanMax",
|
|
72
73
|
AlreadyExists: "AlreadyExists"
|
|
73
74
|
};
|
|
74
75
|
const validateRepositoryDomain = (args) => {
|
|
@@ -79,8 +80,8 @@ const validateRepositoryDomain = (args) => {
|
|
|
79
80
|
*
|
|
80
81
|
* @see https://regex101.com/r/OBZ6UH/1
|
|
81
82
|
*/
|
|
82
|
-
[ValidationErrors.
|
|
83
|
-
[ValidationErrors.
|
|
83
|
+
[ValidationErrors.LessThanMin]: args.domain.length < manager.REPOSITORY_NAME_VALIDATION.Min,
|
|
84
|
+
[ValidationErrors.MoreThanMax]: args.domain.length > manager.REPOSITORY_NAME_VALIDATION.Max
|
|
84
85
|
};
|
|
85
86
|
return {
|
|
86
87
|
...errors,
|
|
@@ -105,11 +106,11 @@ const validateRepositoryDomainAndAvailability = async (args) => {
|
|
|
105
106
|
const getErrorMessageForRepositoryDomainValidation = (args) => {
|
|
106
107
|
if (args.validation.hasErrors) {
|
|
107
108
|
const formattedErrors = [];
|
|
108
|
-
if (args.validation.
|
|
109
|
-
formattedErrors.push(
|
|
109
|
+
if (args.validation.LessThanMin) {
|
|
110
|
+
formattedErrors.push(`must be ${manager.REPOSITORY_NAME_VALIDATION.Min} characters long or more`);
|
|
110
111
|
}
|
|
111
|
-
if (args.validation.
|
|
112
|
-
formattedErrors.push(
|
|
112
|
+
if (args.validation.MoreThanMax) {
|
|
113
|
+
formattedErrors.push(`must be ${manager.REPOSITORY_NAME_VALIDATION.Max} characters long or less`);
|
|
113
114
|
}
|
|
114
115
|
if (ValidationErrors.AlreadyExists in args.validation && args.validation.AlreadyExists) {
|
|
115
116
|
formattedErrors.push("is already taken");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryDomain.cjs","sources":["../../../src/lib/repositoryDomain.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"repositoryDomain.cjs","sources":["../../../src/lib/repositoryDomain.ts"],"sourcesContent":["import { REPOSITORY_NAME_VALIDATION } from \"@slicemachine/manager\";\n\nconst abc123 = `abcdefghijklmnopqrstuvwxyz0123456789`;\n\n// 11 characters long or less adjectives\nconst ADJECTIVES = [\n\t\"adorable\",\n\t\"beautiful\",\n\t\"charming\",\n\t\"cloudy\",\n\t\"delightful\",\n\t\"focused\",\n\t\"honest\",\n\t\"inspiring\",\n\t\"lovable\",\n\t\"melodious\",\n\t\"pleasant\",\n\t\"pretty\",\n\t\"shiny\",\n\t\"sugary\",\n\t\"tall\",\n\t\"valliant\",\n].filter((adjective) => adjective.length <= 11);\n\n// 11 characters long or less bakeries\nconst BAKERIES = [\n\t\"baguette\",\n\t\"briouat\",\n\t\"crepe\",\n\t\"croissant\",\n\t\"donut\",\n\t\"eclair\",\n\t\"flaons\",\n\t\"kolompeh\",\n\t\"macaron\",\n\t\"paste\",\n\t\"pretzel\",\n\t\"rustico\",\n\t\"semla\",\n\t\"strudel\",\n\t\"taiyaki\",\n\t\"toast\",\n].filter((bakery) => bakery.length <= 11);\n\nconst pickRandom = (arrOrString: string | string[]): string => {\n\treturn arrOrString[Math.floor(Math.random() * arrOrString.length)];\n};\n\nconst randomString = (length: number): string => {\n\tlet result = \"\";\n\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += pickRandom(abc123);\n\t}\n\n\treturn result;\n};\n\nexport const getRandomRepositoryDomain = (): string => {\n\treturn formatRepositoryDomain(\n\t\t`${pickRandom(ADJECTIVES)}-${pickRandom(BAKERIES)}-${randomString(6)}`,\n\t);\n};\n\nexport const formatRepositoryDomain = (rawDomain: string): string => {\n\t// Lowercase anything\n\tlet domain = rawDomain.toLowerCase();\n\n\t/**\n\t * Replace whitespaces and underscores with hyphens\n\t */\n\tdomain = domain.replace(/\\s/g, \"-\").replace(/_/g, \"-\");\n\n\t/**\n\t * Replace not allowed characters\n\t *\n\t * @see https://regex101.com/r/f2Hr0k/1\n\t */\n\tdomain = domain.replace(/[^a-z0-9-]/g, \"\");\n\n\t/**\n\t * Trim leading and trailing hyphens\n\t *\n\t * @see https://regex101.com/r/ivngfc/1\n\t */\n\tdomain = domain.replace(/(^-+)|(-+$)/g, \"\");\n\n\t/**\n\t * Replace multi hyphens\n\t *\n\t * @see https://regex101.com/r/t9qxh0/1\n\t */\n\tdomain = domain.replace(/-{2,}/g, \"-\");\n\n\treturn domain;\n};\n\nconst isFormattedRepositoryDomain = (\n\tmaybeFormattedRepositoryDomain: string,\n): boolean => {\n\treturn (\n\t\tmaybeFormattedRepositoryDomain ===\n\t\tformatRepositoryDomain(maybeFormattedRepositoryDomain)\n\t);\n};\n\nconst assertFormattedRepositoryDomain = (\n\tmaybeFormattedRepositoryDomain: string,\n\tcaller: string,\n): void => {\n\tif (!isFormattedRepositoryDomain(maybeFormattedRepositoryDomain)) {\n\t\tthrow new TypeError(\n\t\t\t`\\`${caller}()\\` can only validate formatted repository domains, use the \\`formatRepositoryDomain()\\` first.`,\n\t\t);\n\t}\n};\n\nexport const ValidationErrors = {\n\tLessThanMin: \"LessThanMin\",\n\tMoreThanMax: \"MoreThanMax\",\n\tAlreadyExists: \"AlreadyExists\",\n} as const;\ntype ValidationErrors =\n\t(typeof ValidationErrors)[keyof typeof ValidationErrors];\n\ntype ValidateRepositoryDomainArgs = { domain: string };\ntype ValidateRepositoryDomainReturnType = Record<\n\tExclude<ValidationErrors, \"AlreadyExists\"> | \"hasErrors\",\n\tboolean\n>;\nexport const validateRepositoryDomain = (\n\targs: ValidateRepositoryDomainArgs,\n): ValidateRepositoryDomainReturnType => {\n\tassertFormattedRepositoryDomain(args.domain, \"validateRepositoryDomain\");\n\n\tconst errors: Record<Exclude<ValidationErrors, \"AlreadyExists\">, boolean> = {\n\t\t/**\n\t\t * Checks non [a-z] first character\n\t\t *\n\t\t * @see https://regex101.com/r/OBZ6UH/1\n\t\t */\n\t\t[ValidationErrors.LessThanMin]:\n\t\t\targs.domain.length < REPOSITORY_NAME_VALIDATION.Min,\n\t\t[ValidationErrors.MoreThanMax]:\n\t\t\targs.domain.length > REPOSITORY_NAME_VALIDATION.Max,\n\t};\n\n\treturn {\n\t\t...errors,\n\t\thasErrors: Object.values(errors).some(Boolean),\n\t};\n};\n\ntype ValidateRepositoryDomainAndAvailabilityArgs = {\n\tdomain: string;\n\texistsFn: (domain: string) => boolean | Promise<boolean>;\n};\ntype ValidateRepositoryDomainAndAvailabilityReturnType = Record<\n\tValidationErrors | \"hasErrors\",\n\tboolean\n>;\nexport const validateRepositoryDomainAndAvailability = async (\n\targs: ValidateRepositoryDomainAndAvailabilityArgs,\n): Promise<ValidateRepositoryDomainAndAvailabilityReturnType> => {\n\tassertFormattedRepositoryDomain(\n\t\targs.domain,\n\t\t\"validateRepositoryDomainAndAvailability\",\n\t);\n\n\tconst errors = validateRepositoryDomain(args);\n\n\tif (!errors.hasErrors && (await args.existsFn(args.domain))) {\n\t\treturn {\n\t\t\t...errors,\n\t\t\t[ValidationErrors.AlreadyExists]: true,\n\t\t\thasErrors: true,\n\t\t};\n\t}\n\n\treturn {\n\t\t...errors,\n\t\t[ValidationErrors.AlreadyExists]: false,\n\t};\n};\n\ntype GetErrorMessageForRepositoryDomainValidationArgs = {\n\tvalidation:\n\t\t| ValidateRepositoryDomainReturnType\n\t\t| ValidateRepositoryDomainAndAvailabilityReturnType;\n\tdisplayDomain?: string;\n};\nexport const getErrorMessageForRepositoryDomainValidation = (\n\targs: GetErrorMessageForRepositoryDomainValidationArgs,\n): string | null => {\n\tif (args.validation.hasErrors) {\n\t\tconst formattedErrors: string[] = [];\n\n\t\tif (args.validation.LessThanMin) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`must be ${REPOSITORY_NAME_VALIDATION.Min} characters long or more`,\n\t\t\t);\n\t\t}\n\t\tif (args.validation.MoreThanMax) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`must be ${REPOSITORY_NAME_VALIDATION.Max} characters long or less`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tValidationErrors.AlreadyExists in args.validation &&\n\t\t\targs.validation.AlreadyExists\n\t\t) {\n\t\t\tformattedErrors.push(\"is already taken\");\n\t\t}\n\n\t\tif (!formattedErrors.length) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`has unhandled errors ${JSON.stringify(args.validation)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn `Repository name${\n\t\t\targs.displayDomain ? ` ${args.displayDomain}` : \"\"\n\t\t} ${formattedErrors.join(\" and \")}`;\n\t}\n\n\treturn null;\n};\n"],"names":["REPOSITORY_NAME_VALIDATION"],"mappings":";;;AAEA,MAAM,SAAS;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KAAK,kBAAkB;AAAA,IACvC;AAEG,QAAA,CAAC,gBAAgB,QAAQ;AAC5B,sBAAgB,KACf,wBAAwB,KAAK,UAAU,KAAK,UAAU,GAAG;AAAA,IAE1D;AAEM,WAAA,kBACN,KAAK,gBAAgB,IAAI,KAAK,kBAAkB,MAC7C,gBAAgB,KAAK,OAAO;AAAA,EAChC;AAEM,SAAA;AACR;;;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const getRandomRepositoryDomain: () => string;
|
|
2
2
|
export declare const formatRepositoryDomain: (rawDomain: string) => string;
|
|
3
3
|
export declare const ValidationErrors: {
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
4
|
+
readonly LessThanMin: "LessThanMin";
|
|
5
|
+
readonly MoreThanMax: "MoreThanMax";
|
|
6
6
|
readonly AlreadyExists: "AlreadyExists";
|
|
7
7
|
};
|
|
8
8
|
type ValidationErrors = (typeof ValidationErrors)[keyof typeof ValidationErrors];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { REPOSITORY_NAME_VALIDATION } from "@slicemachine/manager";
|
|
1
2
|
const abc123 = `abcdefghijklmnopqrstuvwxyz0123456789`;
|
|
2
3
|
const ADJECTIVES = [
|
|
3
4
|
"adorable",
|
|
@@ -65,8 +66,8 @@ const assertFormattedRepositoryDomain = (maybeFormattedRepositoryDomain, caller)
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
const ValidationErrors = {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
LessThanMin: "LessThanMin",
|
|
70
|
+
MoreThanMax: "MoreThanMax",
|
|
70
71
|
AlreadyExists: "AlreadyExists"
|
|
71
72
|
};
|
|
72
73
|
const validateRepositoryDomain = (args) => {
|
|
@@ -77,8 +78,8 @@ const validateRepositoryDomain = (args) => {
|
|
|
77
78
|
*
|
|
78
79
|
* @see https://regex101.com/r/OBZ6UH/1
|
|
79
80
|
*/
|
|
80
|
-
[ValidationErrors.
|
|
81
|
-
[ValidationErrors.
|
|
81
|
+
[ValidationErrors.LessThanMin]: args.domain.length < REPOSITORY_NAME_VALIDATION.Min,
|
|
82
|
+
[ValidationErrors.MoreThanMax]: args.domain.length > REPOSITORY_NAME_VALIDATION.Max
|
|
82
83
|
};
|
|
83
84
|
return {
|
|
84
85
|
...errors,
|
|
@@ -103,11 +104,11 @@ const validateRepositoryDomainAndAvailability = async (args) => {
|
|
|
103
104
|
const getErrorMessageForRepositoryDomainValidation = (args) => {
|
|
104
105
|
if (args.validation.hasErrors) {
|
|
105
106
|
const formattedErrors = [];
|
|
106
|
-
if (args.validation.
|
|
107
|
-
formattedErrors.push(
|
|
107
|
+
if (args.validation.LessThanMin) {
|
|
108
|
+
formattedErrors.push(`must be ${REPOSITORY_NAME_VALIDATION.Min} characters long or more`);
|
|
108
109
|
}
|
|
109
|
-
if (args.validation.
|
|
110
|
-
formattedErrors.push(
|
|
110
|
+
if (args.validation.MoreThanMax) {
|
|
111
|
+
formattedErrors.push(`must be ${REPOSITORY_NAME_VALIDATION.Max} characters long or less`);
|
|
111
112
|
}
|
|
112
113
|
if (ValidationErrors.AlreadyExists in args.validation && args.validation.AlreadyExists) {
|
|
113
114
|
formattedErrors.push("is already taken");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryDomain.js","sources":["../../../src/lib/repositoryDomain.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"repositoryDomain.js","sources":["../../../src/lib/repositoryDomain.ts"],"sourcesContent":["import { REPOSITORY_NAME_VALIDATION } from \"@slicemachine/manager\";\n\nconst abc123 = `abcdefghijklmnopqrstuvwxyz0123456789`;\n\n// 11 characters long or less adjectives\nconst ADJECTIVES = [\n\t\"adorable\",\n\t\"beautiful\",\n\t\"charming\",\n\t\"cloudy\",\n\t\"delightful\",\n\t\"focused\",\n\t\"honest\",\n\t\"inspiring\",\n\t\"lovable\",\n\t\"melodious\",\n\t\"pleasant\",\n\t\"pretty\",\n\t\"shiny\",\n\t\"sugary\",\n\t\"tall\",\n\t\"valliant\",\n].filter((adjective) => adjective.length <= 11);\n\n// 11 characters long or less bakeries\nconst BAKERIES = [\n\t\"baguette\",\n\t\"briouat\",\n\t\"crepe\",\n\t\"croissant\",\n\t\"donut\",\n\t\"eclair\",\n\t\"flaons\",\n\t\"kolompeh\",\n\t\"macaron\",\n\t\"paste\",\n\t\"pretzel\",\n\t\"rustico\",\n\t\"semla\",\n\t\"strudel\",\n\t\"taiyaki\",\n\t\"toast\",\n].filter((bakery) => bakery.length <= 11);\n\nconst pickRandom = (arrOrString: string | string[]): string => {\n\treturn arrOrString[Math.floor(Math.random() * arrOrString.length)];\n};\n\nconst randomString = (length: number): string => {\n\tlet result = \"\";\n\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += pickRandom(abc123);\n\t}\n\n\treturn result;\n};\n\nexport const getRandomRepositoryDomain = (): string => {\n\treturn formatRepositoryDomain(\n\t\t`${pickRandom(ADJECTIVES)}-${pickRandom(BAKERIES)}-${randomString(6)}`,\n\t);\n};\n\nexport const formatRepositoryDomain = (rawDomain: string): string => {\n\t// Lowercase anything\n\tlet domain = rawDomain.toLowerCase();\n\n\t/**\n\t * Replace whitespaces and underscores with hyphens\n\t */\n\tdomain = domain.replace(/\\s/g, \"-\").replace(/_/g, \"-\");\n\n\t/**\n\t * Replace not allowed characters\n\t *\n\t * @see https://regex101.com/r/f2Hr0k/1\n\t */\n\tdomain = domain.replace(/[^a-z0-9-]/g, \"\");\n\n\t/**\n\t * Trim leading and trailing hyphens\n\t *\n\t * @see https://regex101.com/r/ivngfc/1\n\t */\n\tdomain = domain.replace(/(^-+)|(-+$)/g, \"\");\n\n\t/**\n\t * Replace multi hyphens\n\t *\n\t * @see https://regex101.com/r/t9qxh0/1\n\t */\n\tdomain = domain.replace(/-{2,}/g, \"-\");\n\n\treturn domain;\n};\n\nconst isFormattedRepositoryDomain = (\n\tmaybeFormattedRepositoryDomain: string,\n): boolean => {\n\treturn (\n\t\tmaybeFormattedRepositoryDomain ===\n\t\tformatRepositoryDomain(maybeFormattedRepositoryDomain)\n\t);\n};\n\nconst assertFormattedRepositoryDomain = (\n\tmaybeFormattedRepositoryDomain: string,\n\tcaller: string,\n): void => {\n\tif (!isFormattedRepositoryDomain(maybeFormattedRepositoryDomain)) {\n\t\tthrow new TypeError(\n\t\t\t`\\`${caller}()\\` can only validate formatted repository domains, use the \\`formatRepositoryDomain()\\` first.`,\n\t\t);\n\t}\n};\n\nexport const ValidationErrors = {\n\tLessThanMin: \"LessThanMin\",\n\tMoreThanMax: \"MoreThanMax\",\n\tAlreadyExists: \"AlreadyExists\",\n} as const;\ntype ValidationErrors =\n\t(typeof ValidationErrors)[keyof typeof ValidationErrors];\n\ntype ValidateRepositoryDomainArgs = { domain: string };\ntype ValidateRepositoryDomainReturnType = Record<\n\tExclude<ValidationErrors, \"AlreadyExists\"> | \"hasErrors\",\n\tboolean\n>;\nexport const validateRepositoryDomain = (\n\targs: ValidateRepositoryDomainArgs,\n): ValidateRepositoryDomainReturnType => {\n\tassertFormattedRepositoryDomain(args.domain, \"validateRepositoryDomain\");\n\n\tconst errors: Record<Exclude<ValidationErrors, \"AlreadyExists\">, boolean> = {\n\t\t/**\n\t\t * Checks non [a-z] first character\n\t\t *\n\t\t * @see https://regex101.com/r/OBZ6UH/1\n\t\t */\n\t\t[ValidationErrors.LessThanMin]:\n\t\t\targs.domain.length < REPOSITORY_NAME_VALIDATION.Min,\n\t\t[ValidationErrors.MoreThanMax]:\n\t\t\targs.domain.length > REPOSITORY_NAME_VALIDATION.Max,\n\t};\n\n\treturn {\n\t\t...errors,\n\t\thasErrors: Object.values(errors).some(Boolean),\n\t};\n};\n\ntype ValidateRepositoryDomainAndAvailabilityArgs = {\n\tdomain: string;\n\texistsFn: (domain: string) => boolean | Promise<boolean>;\n};\ntype ValidateRepositoryDomainAndAvailabilityReturnType = Record<\n\tValidationErrors | \"hasErrors\",\n\tboolean\n>;\nexport const validateRepositoryDomainAndAvailability = async (\n\targs: ValidateRepositoryDomainAndAvailabilityArgs,\n): Promise<ValidateRepositoryDomainAndAvailabilityReturnType> => {\n\tassertFormattedRepositoryDomain(\n\t\targs.domain,\n\t\t\"validateRepositoryDomainAndAvailability\",\n\t);\n\n\tconst errors = validateRepositoryDomain(args);\n\n\tif (!errors.hasErrors && (await args.existsFn(args.domain))) {\n\t\treturn {\n\t\t\t...errors,\n\t\t\t[ValidationErrors.AlreadyExists]: true,\n\t\t\thasErrors: true,\n\t\t};\n\t}\n\n\treturn {\n\t\t...errors,\n\t\t[ValidationErrors.AlreadyExists]: false,\n\t};\n};\n\ntype GetErrorMessageForRepositoryDomainValidationArgs = {\n\tvalidation:\n\t\t| ValidateRepositoryDomainReturnType\n\t\t| ValidateRepositoryDomainAndAvailabilityReturnType;\n\tdisplayDomain?: string;\n};\nexport const getErrorMessageForRepositoryDomainValidation = (\n\targs: GetErrorMessageForRepositoryDomainValidationArgs,\n): string | null => {\n\tif (args.validation.hasErrors) {\n\t\tconst formattedErrors: string[] = [];\n\n\t\tif (args.validation.LessThanMin) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`must be ${REPOSITORY_NAME_VALIDATION.Min} characters long or more`,\n\t\t\t);\n\t\t}\n\t\tif (args.validation.MoreThanMax) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`must be ${REPOSITORY_NAME_VALIDATION.Max} characters long or less`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tValidationErrors.AlreadyExists in args.validation &&\n\t\t\targs.validation.AlreadyExists\n\t\t) {\n\t\t\tformattedErrors.push(\"is already taken\");\n\t\t}\n\n\t\tif (!formattedErrors.length) {\n\t\t\tformattedErrors.push(\n\t\t\t\t`has unhandled errors ${JSON.stringify(args.validation)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn `Repository name${\n\t\t\targs.displayDomain ? ` ${args.displayDomain}` : \"\"\n\t\t} ${formattedErrors.join(\" and \")}`;\n\t}\n\n\treturn null;\n};\n"],"names":[],"mappings":";AAEA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AAA,IACvC;AAEG,QAAA,CAAC,gBAAgB,QAAQ;AAC5B,sBAAgB,KACf,wBAAwB,KAAK,UAAU,KAAK,UAAU,GAAG;AAAA,IAE1D;AAEM,WAAA,kBACN,KAAK,gBAAgB,IAAI,KAAK,kBAAkB,MAC7C,gBAAgB,KAAK,OAAO;AAAA,EAChC;AAEM,SAAA;AACR;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const name = "@slicemachine/init";
|
|
4
|
-
const version = "2.8.2-dev-next-release.
|
|
4
|
+
const version = "2.8.2-dev-next-release.3";
|
|
5
5
|
const description = "Init Prismic Slice Machine in your project";
|
|
6
6
|
const keywords = [
|
|
7
7
|
"typescript",
|
|
@@ -55,7 +55,7 @@ const dependencies = {
|
|
|
55
55
|
"@antfu/ni": "^0.20.0",
|
|
56
56
|
"@lihbr/listr-update-renderer": "^0.5.3",
|
|
57
57
|
"@sentry/node": "^7.70.0",
|
|
58
|
-
"@slicemachine/manager": "^0.15.1-dev-next-release.
|
|
58
|
+
"@slicemachine/manager": "^0.15.1-dev-next-release.3",
|
|
59
59
|
chalk: "^4.1.2",
|
|
60
60
|
giget: "^1.1.2",
|
|
61
61
|
globby: "^13.1.3",
|
|
@@ -68,7 +68,7 @@ const dependencies = {
|
|
|
68
68
|
};
|
|
69
69
|
const devDependencies = {
|
|
70
70
|
"@size-limit/preset-small-lib": "8.2.4",
|
|
71
|
-
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.
|
|
71
|
+
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.3",
|
|
72
72
|
"@types/listr": "0.14.4",
|
|
73
73
|
"@types/prompts": "2.4.3",
|
|
74
74
|
"@types/semver": "7.3.13",
|
|
@@ -94,7 +94,7 @@ const devDependencies = {
|
|
|
94
94
|
"vite-plugin-sdk": "0.1.1",
|
|
95
95
|
vitest: "0.32.0"
|
|
96
96
|
};
|
|
97
|
-
const gitHead = "
|
|
97
|
+
const gitHead = "1899ff11683dd4fd8c9bd66f0a904177dc2fb72a";
|
|
98
98
|
const pkg = {
|
|
99
99
|
name,
|
|
100
100
|
version,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const name = "@slicemachine/init";
|
|
2
|
-
const version = "2.8.2-dev-next-release.
|
|
2
|
+
const version = "2.8.2-dev-next-release.3";
|
|
3
3
|
const description = "Init Prismic Slice Machine in your project";
|
|
4
4
|
const keywords = [
|
|
5
5
|
"typescript",
|
|
@@ -53,7 +53,7 @@ const dependencies = {
|
|
|
53
53
|
"@antfu/ni": "^0.20.0",
|
|
54
54
|
"@lihbr/listr-update-renderer": "^0.5.3",
|
|
55
55
|
"@sentry/node": "^7.70.0",
|
|
56
|
-
"@slicemachine/manager": "^0.15.1-dev-next-release.
|
|
56
|
+
"@slicemachine/manager": "^0.15.1-dev-next-release.3",
|
|
57
57
|
chalk: "^4.1.2",
|
|
58
58
|
giget: "^1.1.2",
|
|
59
59
|
globby: "^13.1.3",
|
|
@@ -66,7 +66,7 @@ const dependencies = {
|
|
|
66
66
|
};
|
|
67
67
|
const devDependencies = {
|
|
68
68
|
"@size-limit/preset-small-lib": "8.2.4",
|
|
69
|
-
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.
|
|
69
|
+
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.3",
|
|
70
70
|
"@types/listr": "0.14.4",
|
|
71
71
|
"@types/prompts": "2.4.3",
|
|
72
72
|
"@types/semver": "7.3.13",
|
|
@@ -92,7 +92,7 @@ const devDependencies = {
|
|
|
92
92
|
"vite-plugin-sdk": "0.1.1",
|
|
93
93
|
vitest: "0.32.0"
|
|
94
94
|
};
|
|
95
|
-
const gitHead = "
|
|
95
|
+
const gitHead = "1899ff11683dd4fd8c9bd66f0a904177dc2fb72a";
|
|
96
96
|
const pkg = {
|
|
97
97
|
name,
|
|
98
98
|
version,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/init",
|
|
3
|
-
"version": "2.8.2-dev-next-release.
|
|
3
|
+
"version": "2.8.2-dev-next-release.3",
|
|
4
4
|
"description": "Init Prismic Slice Machine in your project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@antfu/ni": "^0.20.0",
|
|
55
55
|
"@lihbr/listr-update-renderer": "^0.5.3",
|
|
56
56
|
"@sentry/node": "^7.70.0",
|
|
57
|
-
"@slicemachine/manager": "^0.15.1-dev-next-release.
|
|
57
|
+
"@slicemachine/manager": "^0.15.1-dev-next-release.3",
|
|
58
58
|
"chalk": "^4.1.2",
|
|
59
59
|
"giget": "^1.1.2",
|
|
60
60
|
"globby": "^13.1.3",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@size-limit/preset-small-lib": "8.2.4",
|
|
70
|
-
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.
|
|
70
|
+
"@slicemachine/plugin-kit": "0.4.22-dev-next-release.3",
|
|
71
71
|
"@types/listr": "0.14.4",
|
|
72
72
|
"@types/prompts": "2.4.3",
|
|
73
73
|
"@types/semver": "7.3.13",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"vite-plugin-sdk": "0.1.1",
|
|
94
94
|
"vitest": "0.32.0"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "1899ff11683dd4fd8c9bd66f0a904177dc2fb72a"
|
|
97
97
|
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
SliceMachineManager,
|
|
18
18
|
PackageManager,
|
|
19
19
|
StarterId,
|
|
20
|
+
REPOSITORY_NAME_VALIDATION,
|
|
20
21
|
} from "@slicemachine/manager";
|
|
21
22
|
|
|
22
23
|
import pkg from "../package.json";
|
|
@@ -683,7 +684,7 @@ export class SliceMachineInitProcess {
|
|
|
683
684
|
this.manager.prismicRepository.checkExists({ domain }),
|
|
684
685
|
});
|
|
685
686
|
|
|
686
|
-
if (validation.
|
|
687
|
+
if (validation.LessThanMin || validation.MoreThanMax) {
|
|
687
688
|
const errorMessage = getErrorMessageForRepositoryDomainValidation({
|
|
688
689
|
validation: {
|
|
689
690
|
...validation,
|
|
@@ -846,17 +847,25 @@ export class SliceMachineInitProcess {
|
|
|
846
847
|
const domain = formatRepositoryDomain(rawDomain);
|
|
847
848
|
const validation = validateRepositoryDomain({ domain });
|
|
848
849
|
|
|
849
|
-
const minRule = validation.
|
|
850
|
+
const minRule = validation.LessThanMin
|
|
850
851
|
? chalk.red(
|
|
851
|
-
`1. Name must be ${chalk.bold(
|
|
852
|
+
`1. Name must be ${chalk.bold(
|
|
853
|
+
REPOSITORY_NAME_VALIDATION.Min + " characters long or more",
|
|
854
|
+
)}`,
|
|
852
855
|
)
|
|
853
|
-
: `1. Name must be ${chalk.cyan(
|
|
856
|
+
: `1. Name must be ${chalk.cyan(
|
|
857
|
+
REPOSITORY_NAME_VALIDATION.Min + " characters long or more",
|
|
858
|
+
)}`;
|
|
854
859
|
|
|
855
|
-
const maxRule = validation.
|
|
860
|
+
const maxRule = validation.MoreThanMax
|
|
856
861
|
? chalk.red(
|
|
857
|
-
`1. Name must be ${chalk.bold(
|
|
862
|
+
`1. Name must be ${chalk.bold(
|
|
863
|
+
REPOSITORY_NAME_VALIDATION.Max + " characters long or less",
|
|
864
|
+
)}`,
|
|
858
865
|
)
|
|
859
|
-
: `1. Name must be ${chalk.cyan(
|
|
866
|
+
: `1. Name must be ${chalk.cyan(
|
|
867
|
+
REPOSITORY_NAME_VALIDATION.Max + " characters long or less",
|
|
868
|
+
)}`;
|
|
860
869
|
|
|
861
870
|
this.msg = chalk.reset(
|
|
862
871
|
`
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { REPOSITORY_NAME_VALIDATION } from "@slicemachine/manager";
|
|
2
|
+
|
|
1
3
|
const abc123 = `abcdefghijklmnopqrstuvwxyz0123456789`;
|
|
2
4
|
|
|
3
5
|
// 11 characters long or less adjectives
|
|
@@ -114,8 +116,8 @@ const assertFormattedRepositoryDomain = (
|
|
|
114
116
|
};
|
|
115
117
|
|
|
116
118
|
export const ValidationErrors = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
LessThanMin: "LessThanMin",
|
|
120
|
+
MoreThanMax: "MoreThanMax",
|
|
119
121
|
AlreadyExists: "AlreadyExists",
|
|
120
122
|
} as const;
|
|
121
123
|
type ValidationErrors =
|
|
@@ -137,8 +139,10 @@ export const validateRepositoryDomain = (
|
|
|
137
139
|
*
|
|
138
140
|
* @see https://regex101.com/r/OBZ6UH/1
|
|
139
141
|
*/
|
|
140
|
-
[ValidationErrors.
|
|
141
|
-
|
|
142
|
+
[ValidationErrors.LessThanMin]:
|
|
143
|
+
args.domain.length < REPOSITORY_NAME_VALIDATION.Min,
|
|
144
|
+
[ValidationErrors.MoreThanMax]:
|
|
145
|
+
args.domain.length > REPOSITORY_NAME_VALIDATION.Max,
|
|
142
146
|
};
|
|
143
147
|
|
|
144
148
|
return {
|
|
@@ -191,11 +195,15 @@ export const getErrorMessageForRepositoryDomainValidation = (
|
|
|
191
195
|
if (args.validation.hasErrors) {
|
|
192
196
|
const formattedErrors: string[] = [];
|
|
193
197
|
|
|
194
|
-
if (args.validation.
|
|
195
|
-
formattedErrors.push(
|
|
198
|
+
if (args.validation.LessThanMin) {
|
|
199
|
+
formattedErrors.push(
|
|
200
|
+
`must be ${REPOSITORY_NAME_VALIDATION.Min} characters long or more`,
|
|
201
|
+
);
|
|
196
202
|
}
|
|
197
|
-
if (args.validation.
|
|
198
|
-
formattedErrors.push(
|
|
203
|
+
if (args.validation.MoreThanMax) {
|
|
204
|
+
formattedErrors.push(
|
|
205
|
+
`must be ${REPOSITORY_NAME_VALIDATION.Max} characters long or less`,
|
|
206
|
+
);
|
|
199
207
|
}
|
|
200
208
|
if (
|
|
201
209
|
ValidationErrors.AlreadyExists in args.validation &&
|