UNPKG

@gobstones/gobstones-scripts

Version:

Scripts to abstract away build configuration of Gobstones Project's libraries and modules.

415 lines 17 kB
/** * Models the possible values of operating systems. */ export type OSType = 'macos' | 'posix' | 'windows'; /** * Models the different type of executable scripts. */ export type ScriptType = 'node' | 'sh' | 'pwsh' | 'cmd'; /** * Models the possible values of package managers. */ export type PackageManager = keyof ConfigPackageManagers; /** * Models the possible values of project types. */ export type ProjectType = keyof ConfigProjectTypes; /** * Models the possible values of project type's file. */ export type FileName = keyof ProjectTypeDefinition; /** * Models a package manager definition and basic commands and folder it has. */ export interface PackageManagerDefinition { /** The name of this package manager */ name: string; /** The regular command name. */ cmd: string; /** The command used to install dependencies. */ install: string; /** The command used to execute a binary related to the package manager. */ run: string; /** A set of module folders that the package manager uses. */ modulesFolders: string[]; /** A set of binary folders that the package manager uses. */ binFolders: string[]; } /** * Models a project type's file definition and the expected behavior of * the file. */ export interface FileDefinition { /** * The internal name for this file descriptor. Will automatically * be set to the key name when creating the list of files. */ name: FileName; /** The location of one or more files in the gobstones-script's path. */ gobstonesScriptsLocation: string[]; /** The location that the files should have in the local project's folder. */ projectLocation: string[]; /** Whether this file should be copied on project initialization. */ copyOnInit: boolean; /** Whether this file should be copied on project update. */ copyOnUpdate: boolean; /** Whether this file should be copied on project ejection. */ copyOnEject: boolean; /** * Whether this file represents tooling configuration files * that can be overwritten with local configurations. */ isOverridable: boolean; /** * Whether this file contains reference to the generic project * name that should be updates. */ requiresReferenceUpdate: boolean; /** * Whether this file requires the data for testing (verdaccio server * data) to be inserted to it. */ requiresTestDataInjection: boolean; } /** * Models a project type's file definition that has tooling content */ export interface FileDefinitionWithTooling extends FileDefinition { /** * The detected tooling file to use. Only present if * the file is overridable. The full path of the file is saved. * It's automatically calculated. */ toolingFile: string; } /** * Models a project type's file definitions. */ export interface ProjectTypeDefinition { /** The package.json file of the project type. */ packageJson: FileDefinition; /** The LICENSE file of the project type. */ license: FileDefinition; /** The README.md file of the project type. */ readme: FileDefinition; /** The CHANGELOG.md file of the project type. */ changelog: FileDefinition; /** The CONTRIBUTING.md file of the project type. */ contributing: FileDefinition; /** The .gitignore folder of the project type. */ git: FileDefinition; /** The .npmignore and .npmrc files of the project type. */ npm: FileDefinition; /** The src folder of the project type. */ src: FileDefinition; /** The test folder of the project type. */ test: FileDefinition; /** The .husky folder of the project type. */ husky: FileDefinition; /** The .vscode folder of the project type. */ vscode: FileDefinition; /** The .github folder of the project type. */ github: FileDefinition; /** The .editorconfig file of the project type. */ editorconfig: FileDefinition; /** The .prettierrc and .prettierignore files of the project type. */ prettier: FileDefinition; /** The .commitlint and .czrc files of the project type. */ commitlint: FileDefinition; /** The .eslint file of the project type. */ eslint: FileDefinition; /** The package-scripts.js file of the project type. */ nps: FileDefinitionWithTooling; /** The .tsconfig.js file of the project type. */ typescript: FileDefinitionWithTooling; /** The .rollup.config.js file of the project type. */ rollup: FileDefinitionWithTooling; /** The .typedoc.config.js file of the project type. */ typedoc: FileDefinitionWithTooling; /** The .jest.config.js file of the project type. */ jest: FileDefinitionWithTooling; /** The .jestproxies folder of the project type. */ jestproxies?: FileDefinition; /** The demos folder of the project type. */ demos?: FileDefinition; /** The .vite.config.js file of the project type. */ vite?: FileDefinition; /** The stories folder of the project type. */ stories?: FileDefinition; /** The .storybook folder of the project type. */ storybook?: FileDefinition; /** The .tconfig.json file of the project type. */ tsConfigJSON: FileDefinitionWithTooling; /** The LICENSE_HEADER file of the project type. */ licenseHeader: FileDefinitionWithTooling; /** The license.config.js file of the project type. */ licenseHeaderConfig: FileDefinitionWithTooling; } /** * Models a project type's file definition names, after * being filtered by category. */ export interface FilteredFilesDefinition { /** The list of file names to be copied on init. */ copiedOnInit: FileName[]; /** The list of file names to be copied on update. */ copiedOnUpdate: FileName[]; /** The list of file names to be copied on eject. */ copiedOnEject: FileName[]; /** The list of file names that are part of the tooling * and require to identify the configuration file location. */ toolingFiles: FileName[]; } /** * Models the configuration for all the available * package managers. It's one of the main {@link Config} * sections. */ export interface ConfigPackageManagers { /** The configuration for **npm**. */ npm: PackageManagerDefinition; /** The configuration for **yarn**. */ yarn: PackageManagerDefinition; /** The configuration for **pnpm**. */ pnpm: PackageManagerDefinition; } /** * Models the configuration for the system's * environment, as detected by node. Is one of the * main {@link Config} sections. */ export interface ConfigEnvironment { /** The running tool version. */ toolVersion: string; /** The running tool test server. */ toolTestServer: string; /** The current working directory, as detected through environment. */ workingDirectory: string; /** The current operating system, as detected through environment. */ operatingSystem: OSType; /** The current package manager, as detected through environment. */ detectedPackageManager: PackageManager; } /** * Models the configuration for all the different * locations this tool manages. It's one of the main * {@link Config} sections. */ export interface ConfigLocations { /** The root of the currently running project. */ projectRoot: string; /** The root of the gobstones-scripts Library. */ gobstonesScriptsRoot: string; /** The root of the gobstones-scripts Library project files. */ gobstonesScriptsProjectsRoot: string; } /** * Models the configuration for the current execution * environment. That is, the loaded state of execution * for this particular run. Is one of the main * {@link Config} sections. */ export interface ConfigExecutionEnvironment { /** The currently in use project type. */ projectType: ProjectType; /** The currently in use package manager. */ packageManager: keyof ConfigPackageManagers; /** Whether the tool should use full paths when displaying any. */ useFullPaths: boolean; /** Whether the tool is running in debug mode. */ debug: boolean; /** Whether the tool is running in test mode. */ test: boolean; /** Whether the tool should expect a local tsconfig.json file instead of building from a .js one. */ useLocalTsconfigJson: boolean; } /** * Models the configuration for the different types * of project templates that exist. It's one of the main * {@link Config} sections. */ export interface ConfigProjectTypes { /** The **Library** project type. */ Library: ProjectTypeDefinition; /** The **CLILibrary** project type. */ CLILibrary: ProjectTypeDefinition; /** The **ReactLibrary** project type. */ ReactLibrary: ProjectTypeDefinition; /** The **NonCode** project type. */ NonCode: ProjectTypeDefinition; } /** * Models the configuration of filtered file definitions * for the different types of project templates that exist. * It's one of the main {@link Config} sections. */ export interface ConfigFilteredProjectTypes { /** The **Library** filtered project type files. */ Library: FilteredFilesDefinition; /** The **cli-Library** filtered project type files. */ CLILibrary: FilteredFilesDefinition; /** The **react-Library** filtered project type files. */ ReactLibrary: FilteredFilesDefinition; /** The **NonCode** project type. */ NonCode: FilteredFilesDefinition; } /** * Models an executable file path and characteristics. */ export interface ExecutableScriptDefinition { /** The node package name this executable belongs to. */ packageName: string; /** The binary name of this executable. */ binName: string; /** The script file that should be executed. */ scriptFile: string; /** The command to execute in the terminal */ command: string; /** * The mode on which such binary file should run. * It may be a full JS file to be executed by node, * a Shell script supported by any POSIX file, * of a Windows "PowerShell" script or "cmd" script. */ mode: ScriptType; } /** * This class represents the main configuration object generated by the application. * The configuration is automatically loaded once the {@link init} method is called. * This object is also the main entry point to obtain configuration options of the tool * as to obtain the located directories, tooling files and obtain location for the * executable scripts for different tools. */ export declare class Config { /** Whether the configuration has been initialized. */ private _lastInitializationValues?; /** The subpart of the configuration corresponding to package managers. */ private _packageManagers; /** The subpart of the configuration corresponding to the environment. */ private _environment; /** The subpart of the configuration corresponding to the different path locations. */ private _locations; /** The subpart of the configuration corresponding to the current execution environment. */ private _executionEnvironment; /** The subpart of the configuration corresponding to the different project types. */ private _projectTypes; /** The subpart of the configuration corresponding to the different project type filtered files. */ private _filteredProjectTypes; /** A cache for the executable scripts already detected. */ private _binaryFilesCache; /** * Create a new instance of the configuration. */ constructor(); /** Returns the subpart of the configuration corresponding to package managers. */ get packageManagers(): ConfigPackageManagers; /** Returns subpart of the configuration corresponding to the environment. */ get environment(): ConfigEnvironment; /** Returns the subpart of the configuration corresponding to the different path locations. */ get locations(): ConfigLocations; /** Returns the subpart of the configuration corresponding to the current execution environment. */ get executionEnvironment(): ConfigExecutionEnvironment; /** Returns the subpart of the configuration corresponding to the different project types. */ get projectTypes(): ConfigProjectTypes; /** The subpart of the configuration corresponding to the different project type filtered files. */ get filteredProjectTypes(): ConfigFilteredProjectTypes; get packageManager(): PackageManagerDefinition; get projectType(): ProjectTypeDefinition; get projectTypeFilteredFiles(): FilteredFilesDefinition; /** * Orchestrate the initialization of the Config object. * This initialization is needed in order to access any of the * sub-configuration sections, except for retrieving * executable scripts. */ init(apiGivenProjectType?: string, apiGivenPackageManager?: string, debug?: boolean, test?: boolean, useLocalTsconfigJson?: boolean): this; /** * Change the current directory of the process to another one. * Additionally, update the global configuration to match. * * @param dir - The directory to change to */ changeDir(dir: string): string; /** * Return the information for executing a binary file, if it can be found * by the configuration system. Additionally, and differently from the * simple {@link getBin} helper, this method provides caching, as to not * attempt to find the element twice. * * @param packageName - The package name that contains the binary file. * @param binName - The binary file to execute. * * @returns The executable to run, or undefined if not found. */ getBinary(packageName: string, binName: string): ExecutableScriptDefinition | undefined; /** Initialize the different available package managers. */ private _initAvailablePackageManagers; /** Initialize the current environment from detected information. */ private _detectEnvironment; /** * Initialize the different locations by attempting to detect the current * folder containing a project and the folder containing the gobstones-scripts Library. */ private _initializeLocations; /** * Initialize the current execution environment. This is obtained by a * mix between possible CLI/API given parameters (such as using -t or -m), * given as input, and the information read in the current's project package.json, * as well as defaults in case no configuration is provided. * * Priority is given to CLI/API given, then the package.json configuration * and lastly defaults. * * @param apiGivenProjectType - The CLI/API given value for project type to use, if any. * @param apiGivenPackageManager - The CLI/API given value for package manager to use, if any. * @param debug - The CLI/API given value to know if we are running in debug mode. * @param test - The CLI/API given value to know if we are running in test mode. * @param useLocalTsconfigJson - The CLI/API given value to know if we should use the default tsconfig.json file. */ private _initializeExecutionEnvironment; /** * Initialize the different project type definitions with all their * file information. */ private _loadProjectTypeDefinitions; /** * Returns the file information for all files that are common to any * project. Expects the route of the project's subfolder. * * @param projectTypePath - The route of the project's subfolder (e.g. 'CLILibrary' or 'NonCode') * @param noCommonFiles - The filenames to search in the project specific folder, instead of the common. * @param excludedFiles - Files from the common folder to exclude from this project definition. * * @returns A partial ProjectTypeDefinition. */ private _getCommonProjectTypeDefinition; /** * Initialize the different project type definitions with all their * file information filtered accordingly to their type. */ private _loadProcessedProjectTypeDefinitions; /** * Joins multiple partial project type definitions into a single cohesive one. * Does not verify that the result contains all keys. */ private _joinProjectTypeDefinitions; /** * Return a file definition with defaults, that will be overwritten by the * partial file definition given. * * @param name - The name of the file definition. * @param partialFileInfo - The partial information for this file definition. * @returns A full file definition. */ private _fileDefinition; /** * Return a file definition with defaults, that will be overwritten by the * partial file definition given. * * @param name - The name of the file definition. * @param partialFileInfo - The partial information for this file definition. * @returns A full file definition. */ private _fileDefinitionWithTooling; } //# sourceMappingURL=config.d.ts.map