示例#1
0
// GoBranchOptionsPrompt will return a GoBranchOptions struct with a list of options on how to compile the individual Go branches
func GoBranchOptionsPrompt() (string, codeutilsShared.GoBranchOptions) {
	goBranchOptions := codeutilsShared.GoBranchOptions{}
	goBranchName := codeutilsShared.InputMessage("What is the name of your Go code's branch")
	goIsPackageString := codeutilsShared.InputMessage("Is this branch creating a binary or a Go package")

	if strings.Contains(goIsPackageString, "binary") { // If we are creating a binary
		goBranchOptions.BinaryName = codeutilsShared.InputMessage("Enter the name of this binary")
	} else { // If we are doing an install
		goBranchOptions.DoInstall = true
	}

	goSourcesString := codeutilsShared.InputMessage("Enter the sources you want to have compiled (separated by commas)")
	goBranchOptions.SourcesToInclude = strings.Split(goSourcesString, ",") // Separate the sources by ,

	return goBranchName, goBranchOptions
}
示例#2
0
// HTMLCompilerOptionsPrompt will return a HTMLCompilerOptions struct.
func HTMLCompilerOptionsPrompt() codeutilsShared.HTMLCompilerOptions {
	projectHTMLCompilerOptions := codeutilsShared.HTMLCompilerOptions{}
	enableFralaString := codeutilsShared.InputMessage("Are we enabling the Frala fragments and translations engine? (y/n)")

	projectHTMLCompilerOptions.EnableFrala = strings.Contains(enableFralaString, "y") // Set EnableFrala to bool of if enableFralaString contains y

	return projectHTMLCompilerOptions // Return the projectHTMLCompilerOptions
}
示例#3
0
// GoCompilerOptionsPrompt will return a GoCompilerOptions struct with a list of GoBranchOptions on how to compile our Go code
func GoCompilerOptionsPrompt() codeutilsShared.GoCompilerOptions {
	projectGoCompilerOptions := codeutilsShared.GoCompilerOptions{}
	projectGoCompilerOptions.Branches = make(map[string]codeutilsShared.GoBranchOptions)
	compileFromRootString := codeutilsShared.InputMessage("Are we going to be compiling from the root of the project directory (not src/go)")

	projectGoCompilerOptions.CompileFromRoot = strings.Contains(compileFromRootString, "y") // Set CompileFromRoot equal to if y is in compileFromRootString

	continueToAddBranches := true // Default continueToAddBranches as true, if false we exit the go branch creation loop

	for continueToAddBranches { // So long as continueToAddBranches is true
		branchName, branchOptions := GoBranchOptionsPrompt() // Prompt for branch info, return name and options
		projectGoCompilerOptions.Branches[branchName] = branchOptions

		createAnotherBranchString := codeutilsShared.InputMessage("Do you wish to create another branch (y/n)")
		continueToAddBranches = strings.Contains(createAnotherBranchString, "y") // Set continueToAddBranches to bool of whether createAnotherBranchString contains y
	}

	return projectGoCompilerOptions // Return the projectGoCompilerOptions
}
示例#4
0
// TypeScriptCompilerOptionsPrompt returns a TypeScriptCompilerOptions struct on how to compile our TypeScript code
func TypeScriptCompilerOptionsPrompt() codeutilsShared.TypeScriptCompilerOptions {
	typescriptCompilerOptions := codeutilsShared.TypeScriptCompilerOptions{} // Define typescriptCompilerOptions as a TypeScriptCompilerOptions struct

	// LibreJS
	useLibreJSHeader := codeutilsShared.InputMessage("Do you want to add a LibreJS header to the top of the compiled JS (y/n)")

	if strings.Contains(useLibreJSHeader, "y") { // If we should use a LibreJS Header
		typescriptCompilerOptions.UseLibreJSHeader = true // Set UseLibreJSHeader to true

		var validLibreJSHeader bool // Define validLibreJSHeader as false, continue to ask for a valid Spdx license until we get once

		for validLibreJSHeader == false {
			spdxLicense := codeutilsShared.InputMessage("Enter the LibreJS-valid license you want to use")
			spdxLicense = librejsgopher.ParseLicenseName(spdxLicense) // Return a parsed / cleaned string of the spdxLicense

			if librejsgopher.IsLicense(spdxLicense) { // If this is a valid Spdx license
				typescriptCompilerOptions.LibreJSLicense = spdxLicense // Set LibreJSLicense as spdxLicense
				validLibreJSHeader = true
			} else { // If this is not a valid Spdx license
				fmt.Println("LibreJS does not recognize this as a valid license to use. Please try again.")
			}
		}
	}

	// MinifyContent
	minifyJSContent := codeutilsShared.InputMessage("Do you want to automatically minify the JS (y/n)")
	typescriptCompilerOptions.MinifyContent = strings.Contains(minifyJSContent, "y") // Sets MinifyContent to true if minifyJSContent contains y

	// Target
	esTarget := codeutilsShared.InputMessage("What is the ECMAScript target you want to use (ES3, ES5, ES6)")

	if (esTarget == "ES3") || (esTarget == "ES5") || (esTarget == "ES6") { // If target is ES3, ES5, or ES6
		typescriptCompilerOptions.Target = esTarget // Set Target to esTarget
	} else { // If it is none of the above
		typescriptCompilerOptions.Target = "ES5" // Set target to ES5
	}

	// UniqueHash
	uniqueHash := codeutilsShared.InputMessage("Do you wish to add a unique hash ID to the end of the file during compile (y/n)")
	typescriptCompilerOptions.UniqueHash = strings.Contains(uniqueHash, "y") // Set UniqueHash to true if uniqueHash contains y

	return typescriptCompilerOptions
}
示例#5
0
// LESSCompilerOptionsPrompt will return a LESSCompilerOptions struct with a list of LESSBranchOptions on how to compile our LESS code
func LESSCompilerOptionsPrompt() codeutilsShared.LESSCompilerOptions {
	projectLESSCompilerOptions := codeutilsShared.LESSCompilerOptions{}
	projectLESSCompilerOptions.Branches = make(map[string]codeutilsShared.LESSBranchOptions)
	continueToAddBranches := true // Default continueToAddBranches as true, if false we exit the go branch creation loop

	for continueToAddBranches { // So long as continueToAddBranches is true
		branchName, branchOptions := LESSBranchOptionsPrompt() // Prompt for branch info, return name and options
		projectLESSCompilerOptions.Branches[branchName] = branchOptions

		createAnotherBranchString := codeutilsShared.InputMessage("Do you wish to create another branch (y/n)")
		continueToAddBranches = strings.Contains(createAnotherBranchString, "y") // Set continueToAddBranches based on whether createAnotherBranchString contains y
	}

	return projectLESSCompilerOptions // Return the projectLESSCompilerOptions
}
示例#6
0
// BootstrapProject assists in the bootstrap of a project.
func BootstrapProject(projectName string) {
	var projectConfig codeutilsShared.ProjectConfig // Define projectConfig as a ProjectConfig struct from codeutilsShared
	projectConfig.Name = projectName                // Set the Name to projectName

	contentTypesString := codeutilsShared.InputMessage("Please input the content types of this project, separated by commas")

	if contentTypesString != "" { // If the cocontentTypesStringntentTypes is not an empty string
		contentTypesString = strings.Replace(contentTypesString, " ", "", -1) // Remove any whitespace from contentTypesString
		contentTypesString = strings.ToLower(contentTypesString)              // Lowercase all content
		contentTypes := strings.Split(contentTypesString, ",")                // Split contentTypesString by , into contentTypes
		sort.Strings(contentTypes)                                            // Sort the contentTypes
		projectConfig.ContentTypes = contentTypes                             // Set ContentTypes to sorted contentTypes

		for _, contentType := range contentTypes { // For each contentType in contentTypes
			fmt.Println("----- Configuring " + contentType + " -----")

			switch contentType {
			case "go":
				projectConfig.Go = GoCompilerOptionsPrompt() // Define Go's GoCompilerOptions as the GoCompilerOptions provided by GoCompilerOptionsPrompt
			case "html": // If this is HTML contenttype
				projectConfig.HTML = HTMLCompilerOptionsPrompt() // Define HTML's HTMLCompilerOptions as the HTMLCompilerOptions provided by HTMLCompilerOptionsPrompt
				projectConfig.UsesTests = true
			case "less": // If this is LESS contenttype
				projectConfig.LESS = LESSCompilerOptionsPrompt() // Define LESS's LESSCompilerOptions as the LESSCompilerOptions
			case "typescript": // If this is TypeScript contenttype
				projectConfig.TypeScript = TypeScriptCompilerOptionsPrompt() // Define TypeScript's TypeScriptCompilerOptions as one provided by TypeScriptCompilerOptionsPrompt
			}

			codeutilsShared.OutputStatus(true, "Configured "+contentType+".")
			fmt.Println("") // Force new-line
		}

		CreateFolderStructure(projectConfig) // Create the folder structure if necessary
		codeutilsShared.OutputStatus(true, "Created folder structure for project.")

		// Save config
		projectConfigBytes, _ := json.MarshalIndent(projectConfig, "", "\t")                                          // Convert projectConfig to projectConfigBytes
		codeutilsShared.WriteOrUpdateFile("build/config.json", projectConfigBytes, codeutilsShared.UniversalFileMode) // Write the config to build/config
		codeutilsShared.OutputStatus(true, "Saved config.")
	} else { // If the contentTypes is an empty string
		fmt.Println("No content types provided for project creation.")
	}
}
示例#7
0
// LESSBranchOptionsPrompt will return a LESSBranchOptions struct with a list of options on how to compile the individual LESS branches
func LESSBranchOptionsPrompt() (string, codeutilsShared.LESSBranchOptions) {
	lessBranchOptions := codeutilsShared.LESSBranchOptions{} // Define lessBranchOptions as a LESSBranchOptions struct
	lessBranchName := codeutilsShared.InputMessage("What is the name of this LESS code branch")

	// FileName setting
	outputtedCSSFileName := codeutilsShared.InputMessage("What is the file name you want the outputted CSS to be")
	lessBranchOptions.FileName = strings.Replace(outputtedCSSFileName, ".css", "", -1) // Replace any .css reference

	// UniqueHash
	uniqueHashString := codeutilsShared.InputMessage("Do you wish to add a unique hash ID to the end of the file name during compile (y/n)")
	lessBranchOptions.UniqueHash = strings.Contains(uniqueHashString, "y") // Sets UniqueHash based on if uniqueHashString contains y

	// SourcesToInclude or UseGlob
	useGlobString := codeutilsShared.InputMessage("Will we be compiling all the LESS files in src/less (y/n)")
	lessBranchOptions.UseGlob = strings.Contains(useGlobString, "y") // If useGlobString contains y / yes, sets UseGlob to true

	if !lessBranchOptions.UseGlob { // If we will not be using all the LESS files in src/less
		sourcesToInclude := []string{} // Define sourcesToInclude as an empty string slice
		sourcesToIncludeString := codeutilsShared.InputMessage("What files will we be using to compile this branch (separate by comma)")

		for _, source := range strings.Split(sourcesToIncludeString, ",") {
			sourcesToInclude = append(sourcesToInclude, []string{strings.TrimSpace(source)}...) // Trim the space around source and append it to sourcesToInclude
		}

		lessBranchOptions.SourcesToInclude = sourcesToInclude // Set SourcesToInclude as sourcesToInclude []string{}
	}

	// Additional Compile Options
	doAdditionalCompileOptions := codeutilsShared.InputMessage("Do you wish to add additional compile options (y/n)")

	if strings.Contains(doAdditionalCompileOptions, "y") { // If we are going to be adding additional compile options
		additionalCompileOptions := []string{} // Set additionalCompileOptions to an empty string slice
		additionalCompileOptionsString := codeutilsShared.InputMessage("Enter the options, separated by semi-colon (;)")

		for _, compileOption := range strings.Split(additionalCompileOptionsString, ";") {
			additionalCompileOptions = append(additionalCompileOptions, []string{strings.TrimSpace(compileOption)}...) // Trim the space around compileOption and append it to additionalCompileOptions
		}

		lessBranchOptions.AdditionalCompileOptions = additionalCompileOptions // Assign AdditionalCompileOptions as additionalCompileOptions
	}

	return lessBranchName, lessBranchOptions
}