├── .gitignore ├── .npmignore ├── rollup.config.js ├── editorconfig ├── readme.md ├── .vscode └── tasks.json ├── tsconfig.json ├── src ├── core.ts ├── unique-id.ts ├── messaging.ts ├── model-transform.ts ├── code-writer-utility.ts ├── logger.ts ├── string-utility.ts ├── text-writer.ts ├── name-utility.ts └── code-writer.ts ├── package.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | #Npm modules 2 | node_modules/ 3 | npm-debug.log.* 4 | 5 | #Custom generated output 6 | dist/ 7 | *.tgz -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode/* 2 | src 3 | !dist/*/src 4 | tsconfig.json 5 | *.npmignore 6 | *.ts 7 | !*.d.ts 8 | rollup.config.js -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | input: 'dist/es6/core.js', // rollup requires ES input 3 | output: { 4 | format: 'umd', 5 | name: '@yellicode/core', 6 | file: 'dist/bundles/core.umd.js' 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = tab 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [package.json] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Yellicode Core 2 | 3 | ### Core package for Yellicode 4 | 5 | Yellicode lets you build your own code generation templates with TypeScript. It consists of a Node.js CLI and extensible APIs, making it easy for developers to create, share and re-use code generators for their favorite programming languages and frameworks. 6 | 7 | Check out [our website](https://www.yellicode.com) for more. 8 | 9 | License: MPL-2.0 -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "build", 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | }, 13 | "problemMatcher": [] 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "es2015", 5 | "outDir": "dist/es5", 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "inlineSourceMap": false, 9 | "lib": [ 10 | "es2015", 11 | "dom" 12 | ] 13 | }, 14 | "exclude": [ 15 | "dist/types", // avoid error TS5055: Cannot write file 'myfile.d.ts' https://github.com/Microsoft/TypeScript/issues/6046 16 | "node_modules" 17 | ] 18 | } -------------------------------------------------------------------------------- /src/core.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | export * from './string-utility' 9 | export * from './name-utility'; 10 | export * from './code-writer-utility'; 11 | export * from './messaging'; 12 | export * from './logger'; 13 | export * from './unique-id' 14 | export * from './model-transform'; 15 | export * from "./code-writer"; 16 | export * from "./text-writer"; -------------------------------------------------------------------------------- /src/unique-id.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | import { nanoid } from 'nanoid' 10 | 11 | export class UniqueId { 12 | /** 13 | * Creates a unique ID using te 'nanoid' package. 14 | * @param size The size of the ID (defaulted to 21 by nanoid) 15 | */ 16 | public static create(size?: number): string { 17 | return nanoid(size); 18 | } 19 | } -------------------------------------------------------------------------------- /src/messaging.ts: -------------------------------------------------------------------------------- 1 | import { LogLevel } from './logger'; 2 | 3 | /* 4 | * Copyright (c) 2019 Yellicode 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | /** 12 | * Defines the structure of messages that are sent between the client template process and the main process. 13 | */ 14 | export interface IProcessMessage { 15 | cmd?: 'processStarted' | 'generateStarted' | 'generateFinished' | 'getModel' | 'setModel'; 16 | log?: { level: LogLevel, message: string }; 17 | } 18 | 19 | export interface ISetModelMessage extends IProcessMessage { 20 | modelData?: any; 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yellicode/core", 3 | "version": "1.5.0", 4 | "description": "Core package for Yellicode - an extensible code generator.", 5 | "license": "MPL-2.0", 6 | "main": "dist/bundles/core.umd.js", 7 | "module": "dist/es5/core.js", 8 | "es2015": "dist/es6/core.js", 9 | "types": "dist/types/core.d.ts", 10 | "sideEffects": false, 11 | "repository": { 12 | "type": "git", 13 | "url": "github:yellicode/core.git" 14 | }, 15 | "dependencies": { 16 | "nanoid": "^3.1.12" 17 | }, 18 | "devDependencies": { 19 | "@types/node": "^14.14.22", 20 | "rollup": "^3.29.5" 21 | }, 22 | "scripts": { 23 | "build:es5": "tsc", 24 | "build:es6": "tsc -m es6 -t es6 --outDir dist/es6 --declaration --declarationDir dist/types", 25 | "build:umd": "rollup --config rollup.config.js", 26 | "build:dist": "npm run build:es5 & npm run build:es6 & npm run build:umd", 27 | "build": "npm run build:dist", 28 | "prepare": "npm run build:dist" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/model-transform.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | /** 10 | * The base interface for all model transformations. 11 | */ 12 | export interface ModelTransform { 13 | /** 14 | * Transforms the source model into the target model. 15 | */ 16 | transform(source: TSource): TTarget; 17 | } 18 | 19 | /** 20 | * Performs a sequence of model transforms, where the output of each transform is 21 | * the input of the next transform. 22 | */ 23 | export class ModelTransformPipeline implements ModelTransform { 24 | private transforms: ModelTransform[]; 25 | 26 | /** 27 | * Creates a new ModelTransformPipeline, optionally initialized with a collection of transforms. 28 | * @param transform sAny transforms to initialize the pipeline with. 29 | */ 30 | constructor(...transforms: ModelTransform[]) { 31 | this.transforms = transforms || []; 32 | } 33 | 34 | /** 35 | * Adds a new collection of transforms to the pipeline. 36 | * @param transforms The transforms to be added. 37 | */ 38 | public addRange(...transforms: ModelTransform[]): void { 39 | transforms.forEach(t => { 40 | this.transforms.push(t); 41 | }); 42 | } 43 | 44 | /** 45 | * Adds a new transform to the pipeline. 46 | * @param transform The transform to be added. 47 | */ 48 | public add(transform: ModelTransform): void { 49 | if (!transform) return; 50 | 51 | this.transforms.push(transform); 52 | } 53 | 54 | /** 55 | * Transforms the source model by applying the specified transforms in sequence. 56 | * @returns The output of the last transform that was applied. 57 | */ 58 | public transform(model: TModel): TModel { 59 | if (this.transforms == null) 60 | return model; 61 | 62 | let transformedModel = model; 63 | this.transforms.forEach(t => { 64 | transformedModel = t.transform(transformedModel); 65 | }); 66 | return transformedModel; 67 | } 68 | } -------------------------------------------------------------------------------- /src/code-writer-utility.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | /** 10 | * Contains helper methods that can be used by custom code writers and templates. 11 | */ 12 | export class CodeWriterUtility { 13 | /** 14 | * Wraps the provided string input to a specified maximum width. 15 | * @argument str The string to be wrapped. 16 | * @argument width The maximum width of the wrapped text in characters. 17 | * @returns A string array containing all lines. 18 | */ 19 | public static wordWrap(str: string, width: number): string[] { 20 | const result: string[] = []; 21 | 22 | if (width < 1 || str == null || str.length <= width) 23 | return result; 24 | 25 | const len = str.length; 26 | let rangeMax = len - width; // we don't need to split after this position 27 | let rangeStart = 0; 28 | let subString: string; 29 | while (rangeStart < rangeMax) { 30 | let subLength: number; 31 | let rangeEnd = rangeStart + width; 32 | // First test for newlines in this range. If so, don't split on word break but on the newline. 33 | var ixNewLine = str.indexOf("\n", rangeStart); 34 | if (ixNewLine > -1 && ixNewLine > rangeStart && ixNewLine < rangeEnd) { 35 | subLength = ixNewLine - rangeStart; 36 | subString = str.substr(rangeStart, subLength); 37 | rangeStart = rangeStart + subLength + 1; 38 | result.push(subString); 39 | continue; 40 | } 41 | // No newlines. Find the last wordbreak in the range. 42 | let ix = str.lastIndexOf(" ", rangeEnd); // find the last word break 43 | let rangeStartNext: number = 0; 44 | if (ix > -1 && ix != rangeStart - 1) { 45 | subLength = ix - rangeStart; 46 | if (subLength > 0) { 47 | rangeStartNext = rangeStart + subLength + 1; // +1 to skip the whitespace 48 | } 49 | //else { // not needed anymore because of the maxPos check 50 | // sub = str.substr(pos); 51 | // newPos = len + 1; 52 | //} 53 | } else { 54 | // The range has no whitespace. 55 | subLength = width; 56 | rangeStartNext = rangeStart + width; 57 | } 58 | subString = str.substr(rangeStart, subLength); 59 | rangeStart = rangeStartNext; 60 | result.push(subString.trim()); 61 | } 62 | // Add the remainder 63 | if (rangeStart < len) { 64 | subString = str.substr(rangeStart); 65 | result.push(subString); 66 | } 67 | // console.debug(result); 68 | return result; 69 | } 70 | } -------------------------------------------------------------------------------- /src/logger.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | /** 10 | * Defines the interface for types that implement logging. 11 | */ 12 | export interface Logger { 13 | verbose(message: string): void; 14 | info(message: string): void; 15 | warn(message: string): void; 16 | error(message: string): void; 17 | log(message: string, level: LogLevel): void; 18 | } 19 | 20 | 21 | /** 22 | * Enumerates the possible Yellicode logging levels. 23 | */ 24 | export enum LogLevel { 25 | None = 0, 26 | Error = 1, 27 | Warning = 2, 28 | Info = 3, 29 | Verbose = 4 30 | } 31 | 32 | export namespace LogLevel { 33 | export function parse(str: string): LogLevel | null { 34 | if (!str) return null; 35 | switch (str.toLowerCase()) { 36 | case 'none': return LogLevel.None; 37 | case 'error': return LogLevel.Error; 38 | case 'warning': return LogLevel.Warning; 39 | case 'info': return LogLevel.Info; 40 | case 'verbose': return LogLevel.Verbose; 41 | default: return null; 42 | } 43 | } 44 | } 45 | 46 | /** 47 | * A Logger implementation that logs to the default Console. 48 | */ 49 | export class ConsoleLogger implements Logger { 50 | constructor(private console: Console, private level: LogLevel = LogLevel.Info, private includeTimestamp = false) { 51 | 52 | } 53 | 54 | public verbose(message: string): void { 55 | if (this.level < LogLevel.Verbose) return; 56 | this.write("Verbose", message); 57 | }; 58 | 59 | public info(message: string): void { 60 | if (this.level < LogLevel.Info) return; 61 | this.write("Info", message); 62 | }; 63 | 64 | public warn(message: string): void { 65 | if (this.level < LogLevel.Warning) return; 66 | this.write("Warning", message); 67 | }; 68 | 69 | public error(message: string): void { 70 | if (this.level < LogLevel.Error) return; 71 | this.write("Error", message); 72 | }; 73 | 74 | public log(message: string, level: LogLevel): void { 75 | switch (level) { 76 | case LogLevel.Verbose: 77 | this.verbose(message); 78 | break; 79 | case LogLevel.Info: 80 | this.info(message); 81 | break; 82 | case LogLevel.Warning: 83 | this.warn(message); 84 | break; 85 | case LogLevel.Error: 86 | this.error(message); 87 | break; 88 | } 89 | } 90 | 91 | private write(level: string, message: string): void { 92 | if (!this.includeTimestamp) { 93 | this.console.log(`${level}: ${message}`); 94 | return; 95 | } 96 | var d = new Date(); 97 | var time = d.toLocaleTimeString(); 98 | var ms = ConsoleLogger.padMilliseconds(d.getMilliseconds()); 99 | this.console.log(`${time}:${ms} - ${level}: ${message}`); 100 | } 101 | 102 | private static padMilliseconds(num: number, length = 3) { 103 | if ((''+num).length >= length) return num; 104 | var lead = '0' + new Array(length).join('0') 105 | return (lead + num).slice(-length); 106 | } 107 | } -------------------------------------------------------------------------------- /src/string-utility.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | /** 10 | * Contains simple utility methods that deal with strings. 11 | */ 12 | export class StringUtility { 13 | public static wordWrap(str: string, width: number): string[] { 14 | const result: string[] = []; 15 | 16 | if (width < 1 || str == null || str.length <= width) 17 | return result; 18 | 19 | const len = str.length; 20 | let rangeMax = len - width; // we don't need to split after this position 21 | let rangeStart = 0; 22 | let subString: string; 23 | while (rangeStart < rangeMax) { 24 | let subLength: number; 25 | let rangeEnd = rangeStart + width; 26 | // First test for newlines in this range. If so, don't split on word break but on the newline. 27 | var ixNewLine = str.indexOf("\n", rangeStart); 28 | if (ixNewLine > -1 && ixNewLine > rangeStart && ixNewLine < rangeEnd) { 29 | subLength = ixNewLine - rangeStart; 30 | subString = str.substr(rangeStart, subLength); 31 | rangeStart = rangeStart + subLength + 1; 32 | result.push(subString); 33 | continue; 34 | } 35 | // No newlines. Find the last wordbreak in the range. 36 | let ix = str.lastIndexOf(" ", rangeEnd); // find the last word break 37 | let rangeStartNext: number = 0; 38 | if (ix > -1 && ix != rangeStart - 1) { 39 | subLength = ix - rangeStart; 40 | if (subLength > 0) { 41 | rangeStartNext = rangeStart + subLength + 1; // +1 to skip the whitespace 42 | } 43 | //else { // not needed anymore because of the maxPos check 44 | // sub = str.substr(pos); 45 | // newPos = len + 1; 46 | //} 47 | } else { 48 | // The range has no whitespace. 49 | subLength = width; 50 | rangeStartNext = rangeStart + width; 51 | } 52 | subString = str.substr(rangeStart, subLength); 53 | rangeStart = rangeStartNext; 54 | result.push(subString.trim()); 55 | } 56 | // Add the remainder 57 | if (rangeStart < len) { 58 | subString = str.substr(rangeStart); 59 | result.push(subString); 60 | } 61 | // console.debug(result); 62 | return result; 63 | } 64 | 65 | /** 66 | * Makes the first character of the string uppercase. 67 | */ 68 | public static capitalize(str: string): string { 69 | if (str == null || str.length === 0) 70 | return str; 71 | 72 | return str.charAt(0).toUpperCase() + str.slice(1); 73 | } 74 | 75 | /** 76 | * Makes the first character of the string lowercase. 77 | */ 78 | public static unCapitalize(str: string): string { 79 | if (str == null || str.length === 0) 80 | return str; 81 | 82 | return str.charAt(0).toLowerCase() + str.slice(1); 83 | } 84 | 85 | /** 86 | * Returns a boolean value indicating if the string is upperCase. 87 | */ 88 | public static isUpperCase(str: string): boolean { 89 | if (!str) return false; 90 | return (str === str.toUpperCase() && str !== str.toLowerCase()); 91 | } 92 | 93 | /** 94 | * Returns a boolean value indicating if the string is lowerCase. 95 | */ 96 | public static isLowerCase(str: string): boolean { 97 | if (!str) return false; 98 | return (str === str.toLowerCase() && str !== str.toUpperCase()) 99 | } 100 | } -------------------------------------------------------------------------------- /src/text-writer.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | /** 10 | * Represents a writer that can write a sequential series of characters. 11 | */ 12 | export interface TextWriter { 13 | /** 14 | * Gets or sets the end of line string. The default value is platform dependent. 15 | */ 16 | endOfLineString: string; 17 | 18 | /** 19 | * Gets or sets the indent string. The default value is a '\t' (tab character). 20 | */ 21 | indentString: string; 22 | 23 | /** 24 | * Writes a string value to the output. 25 | * @param value The string value to be written. 26 | */ 27 | write(value: string): this; 28 | 29 | /** 30 | * Writes a single whitespace character to the output. 31 | */ 32 | writeWhiteSpace(): this; 33 | 34 | /** 35 | * Writes a new line to the output. The line is indented automatically. The line is ended with the endOfLineString. 36 | * @param value The line to write. When omitted, only the endOfLineString is written. 37 | */ 38 | writeLine(value?: string): this; 39 | 40 | /** 41 | * Writes a collection of lines to the output. Each line is indented automatically and ended with the endOfLineString. 42 | * @param values The lines to write. 43 | * @param delimiter An optional delimiter to be written at the end of each line, except for the last one. 44 | */ 45 | writeLines(values: string[], delimiter?: string): this; 46 | 47 | /** 48 | * Writes a new line to the output while temporarily increasing the indent. The line is ended with the endOfLineString. 49 | * @param value The line to write. 50 | */ 51 | writeLineIndented(value: string): this; 52 | 53 | /** 54 | * Writes the endOfLineString to the output. 55 | * @param value Any value to write before the endOfLineString string is written. 56 | */ 57 | writeEndOfLine(value?: string): this; 58 | 59 | /** 60 | * Writes the contents of the specified file to the output. 61 | * @param fileName The path of the file, relative to the template. 62 | * @param encoding Optional: the encoding that is used for the file. The default is 'utf-8'. 63 | */ 64 | writeFile(path: string, encoding?: string): this; 65 | 66 | /** 67 | * Writes the contents of the specified file region to the output. 68 | * @param regionName The name of the region to write. The current FileRegionMapper will be used to determine the format of the 69 | * region marker (by default: "/// code goes here..."). 70 | * @param fileName The path of the file, relative to the template. 71 | * @param encoding The encoding that is used for the file. The default is 'utf-8'. 72 | * @returns True if the region was found in the specified file and was written successfully. 73 | */ 74 | writeFileRegion(regionName: string, path: string, encoding?: string): boolean; 75 | 76 | /** 77 | * Writes the current indentString to the output. 78 | */ 79 | writeIndent(): this; 80 | 81 | /** 82 | * Increases the current indent, which is prefixed to each line of the output. 83 | */ 84 | increaseIndent(): this; 85 | 86 | /** 87 | * Decreases the current indent, which is prefixed to each line of the output. 88 | */ 89 | decreaseIndent(): this; 90 | 91 | /** 92 | * Resets any indentation, causing new line writes to start at the first character position. 93 | */ 94 | clearIndent(): this; 95 | 96 | /** 97 | * Disables writing any indentation for following writeIndent() and writeLine() calls, until 98 | * resumeIndent() is called. 99 | */ 100 | suppressIndent(): this; 101 | 102 | /** 103 | * Resumes writing indentation after a call to suppressIndent(). 104 | */ 105 | resumeIndent(): this; 106 | 107 | /** 108 | * Disables writing any end of line character for following and writeLine() calls, until 109 | * resumeEndOfLine() is called. 110 | */ 111 | suppressEndOfLine(): this; 112 | 113 | /** 114 | * Resumes writing end of line characters after a call to suppressEndOfLine(). 115 | */ 116 | resumeEndOfLine(): this; 117 | 118 | /** 119 | * Prevents the SLOC (source lines of code) counter from being incremented. 120 | */ 121 | freezeSloc(): this; 122 | 123 | /** 124 | * Stops preventing the SLOC (source lines of code) counter from being incremented. 125 | */ 126 | unfreezeSloc(): this; 127 | 128 | /** 129 | * Writes the contained contents without counting the lines as SLOC (source lines of code). 130 | * This is similar to calling freezeSloc() -> contents -> unfreezeSloc(). 131 | * @param contents The code to write without increasing SLOC. 132 | */ 133 | withFrozenSloc(contents: (writer: this) => void): this; 134 | 135 | /** 136 | * The total number of lines currently written. 137 | */ 138 | loc: number; 139 | 140 | /** 141 | * The total number of lines currently written, excluding comments and vertical space 142 | * (SLOC = source lines of code). 143 | */ 144 | sloc: number; 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/name-utility.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | import { StringUtility } from './string-utility'; 9 | 10 | /** 11 | * Provides helper functions for converting the casing of names. 12 | */ 13 | export class NameUtility { 14 | /** 15 | * Makes the first character of the string uppercase. 16 | */ 17 | public static capitalize(input: string): string { 18 | if (!input) return input; 19 | return StringUtility.capitalize(input); 20 | } 21 | 22 | /** 23 | * Makes the first character of the string lowercase. 24 | */ 25 | public static unCapitalize(input: string): string { 26 | if (!input) return input; 27 | return StringUtility.unCapitalize(input); 28 | } 29 | 30 | /** 31 | * Converts a UpperCamelCase or lowerCamelCase string to a kebab-case (aka dash-case) string. 32 | * @param input A camelCase or UpperCamelCase string. 33 | * @returns a kebab-case (aka dash-case) string, meaning all lowercase with a dash separating words. 34 | */ 35 | public static camelToKebabCase(input: string): string { 36 | if (!input) return input; 37 | 38 | const result: string[] = []; 39 | 40 | for (var i = 0, len = input.length; i < len; i++) { 41 | var c = input.charAt(i); 42 | const upperCase = c.toUpperCase(); 43 | const lowerCase = c.toLowerCase(); 44 | const isUpperCase = (c === upperCase && c !== lowerCase); 45 | if (isUpperCase && i > 0 && i < len - 1) { 46 | let insertHyphen = true; 47 | if (i < len - 1 && StringUtility.isUpperCase(input.charAt(i + 1))) { 48 | // The next character is also uppercase 49 | insertHyphen = false; 50 | } 51 | if (insertHyphen) { 52 | result.push('-'); 53 | } 54 | } 55 | result.push(lowerCase); 56 | } 57 | return result.join(''); 58 | } 59 | 60 | 61 | /** 62 | * Converts a UpperCamelCase string to a lowerCamelCase string. 63 | * @param input A UpperCamelCase string. 64 | * @returns a lowerCamelCase string. 65 | */ 66 | public static upperToLowerCamelCase(input: string): string { 67 | if (!input) return input; 68 | 69 | let done = false; 70 | let isPreviousMatch = false; 71 | 72 | const result: string[] = new Array(input.length); 73 | for (var i = 0, len = input.length; i < len; i++) { 74 | var c = input.charAt(i); 75 | if (!done) { 76 | const upperCase = c.toUpperCase(); 77 | const lowerCase = c.toLowerCase(); 78 | const isMatch = (c === upperCase && c !== lowerCase); 79 | if (isMatch) { 80 | // The character is upperCase, make it lowerCase 81 | c = lowerCase; 82 | } 83 | else { 84 | // The character is lowerCase. We are done, but.. 85 | if (isPreviousMatch && i > 1) { 86 | // ... if we converted the previous char to lowercase, make it uppercase again. 87 | // For example: ISBNNumber would become isbnNumber instead of isbnnumber 88 | result[i - 1] = result[i - 1].toUpperCase(); 89 | } 90 | done = true; 91 | } 92 | isPreviousMatch = isMatch; 93 | } 94 | result[i] = c; 95 | } 96 | return result.join(''); 97 | } 98 | 99 | /** 100 | * Converts a lowerCamelCase string to a UpperCamelCase string. 101 | * @param input A lowerCamelCase string. 102 | * @returns a UpperCamelCase string. 103 | */ 104 | public static lowerToUpperCamelCase(input: string): string { 105 | return StringUtility.capitalize(input); 106 | } 107 | 108 | /** 109 | * Converts a kebab-case, lowerCamelCase or UpperCamelCase string to an ALL_UPPER_CASE string. 110 | * @param input A kebab-case (aka dash-case), lowerCamelCase or UpperCamelCase string. 111 | * @returns an ALL_UPPER_CASE string. 112 | */ 113 | public static toAllUpperCase(input: string): string { 114 | if (!input) return input; 115 | 116 | const result: string[] = []; 117 | 118 | for (var i = 0, len = input.length; i < len; i++) { 119 | var c = input.charAt(i); 120 | const upperCase = c.toUpperCase(); 121 | const lowerCase = c.toLowerCase(); 122 | const isUpperCase = (c === upperCase && c !== lowerCase); 123 | const isDash = c === '-'; 124 | if ((isDash || isUpperCase) && i > 0 && i < len - 1) { 125 | let insertHyphen = true; 126 | if (i < len - 1 && StringUtility.isUpperCase(input.charAt(i + 1))) { 127 | // The next character is also uppercase 128 | insertHyphen = false; 129 | } 130 | if (insertHyphen) { 131 | result.push('_'); 132 | } 133 | } 134 | if (!isDash) 135 | result.push(upperCase); 136 | } 137 | return result.join(''); 138 | } 139 | } -------------------------------------------------------------------------------- /src/code-writer.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Yellicode 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | import { TextWriter } from "./text-writer"; 9 | 10 | /** 11 | * The abstract base class for all code writers. This writer implements the TextWriter interface by decorating 12 | * the TextWriter provided in the constructor. 13 | */ 14 | export abstract class CodeWriter implements TextWriter { 15 | private writer: TextWriter; 16 | 17 | // NOTE: only documenting the get accessors because the TS compiler we use for doc generation concats the doc 18 | // comments for the getter and setter. 19 | 20 | /** 21 | * Gets or sets the end of line string. The default value is platform dependent. 22 | */ 23 | public get endOfLineString(): string { 24 | return this.writer.endOfLineString; 25 | } 26 | 27 | public set endOfLineString(value: string) { 28 | this.writer.endOfLineString = value; 29 | } 30 | 31 | /** 32 | * Gets or sets the indent string. The default value is a '\t' (tab character). 33 | */ 34 | public get indentString(): string { 35 | return this.writer.indentString; 36 | } 37 | 38 | public set indentString(value: string) { 39 | this.writer.indentString = value; 40 | } 41 | 42 | /** 43 | * Constructor. Creates a new CodeWriter that uses the provided TextWriter internally. 44 | * @param writer A TextWriter object. In a code generation template, a TextWriter instance can be obtained by calling any of the generate...() 45 | * functions on the current CodeGenerator. 46 | */ 47 | constructor(writer: TextWriter) { 48 | this.writer = writer; 49 | } 50 | 51 | /****************************************************************************** 52 | * TextWriter delegation 53 | ******************************************************************************/ 54 | /** 55 | * Writes a string value to the output. 56 | * @param value The string value to be written. 57 | */ 58 | public write(value: string): this { 59 | this.writer.write(value); 60 | return this; 61 | }; 62 | 63 | /** 64 | * Writes a single whitespace character to the output. 65 | */ 66 | public writeWhiteSpace(): this { 67 | this.writer.writeWhiteSpace(); 68 | return this; 69 | } 70 | 71 | /** 72 | * Writes a new line to the output. The line is indented automatically. The line is ended with the endOfLineString. 73 | * @param value The line to write. When omitted, only the endOfLineString is written. 74 | */ 75 | public writeLine(value?: string): this { 76 | this.writer.writeLine(value); 77 | return this; 78 | }; 79 | 80 | /** 81 | * Writes a collection of lines to the output. Each line is indented automatically and ended with the endOfLineString. 82 | * @param values The lines to write. 83 | * @param delimiter An optional delimiter to be written at the end of each line, except for the last one. 84 | */ 85 | public writeLines(values: string[], delimiter?: string): this { 86 | this.writer.writeLines(values, delimiter); 87 | return this; 88 | } 89 | 90 | /** 91 | * Writes a new line to the output while temporarily increasing the indent. The line is ended with the endOfLineString. 92 | * @param value The line to write. 93 | */ 94 | public writeLineIndented(value: string): this { 95 | this.writer.writeLineIndented(value); 96 | return this; 97 | } 98 | 99 | /** 100 | * Writes the endOfLineString to the output. 101 | * @param value Any value to write before the endOfLineString string is written. 102 | */ 103 | public writeEndOfLine(value?: string): this { 104 | this.writer.writeEndOfLine(value); 105 | return this; 106 | }; 107 | 108 | /** 109 | * Writes the contents of the specified file to the output. 110 | * @param fileName The path of the file, relative to the template. 111 | * @param encoding Optional: the encoding that is used for the file. The default is 'utf-8'. 112 | */ 113 | public writeFile(path: string, encoding?: string): this { 114 | this.writer.writeFile(path, encoding); 115 | return this; 116 | } 117 | 118 | /** 119 | * Writes the contents of the specified file region to the output. 120 | * @param regionName The name of the region to write. The region should be marked using "/// code goes here...". 121 | * @param fileName The path of the file, relative to the template. 122 | * @param encoding The encoding that is used for the file. The default is 'utf-8'. 123 | */ 124 | public writeFileRegion(regionName: string, path: string, encoding?: string): boolean { 125 | return this.writer.writeFileRegion(regionName, path, encoding); 126 | } 127 | 128 | /** 129 | * Writes the current indentString to the output. 130 | */ 131 | public writeIndent(): this { 132 | this.writer.writeIndent(); 133 | return this; 134 | }; 135 | 136 | /** 137 | * Increases the current indent, which is prefixed to each line of the output. 138 | */ 139 | public increaseIndent(): this { 140 | this.writer.increaseIndent(); 141 | return this; 142 | } 143 | 144 | /** 145 | * Decreases the current indent, which is prefixed to each line of the output. 146 | */ 147 | public decreaseIndent(): this { 148 | this.writer.decreaseIndent(); 149 | return this; 150 | } 151 | 152 | /** 153 | * Resets any indentation, causing new line writes to start at the first character position. 154 | */ 155 | public clearIndent(): this { 156 | this.writer.clearIndent(); 157 | return this; 158 | } 159 | 160 | /** 161 | * Disables writing any indentation for following writeIndent() and writeLine() calls, until 162 | * resumeIndent() is called. 163 | */ 164 | public suppressIndent(): this { 165 | this.writer.suppressIndent(); 166 | return this; 167 | } 168 | 169 | /** 170 | * Resumes writing indentation after a call to suppressIndent(). 171 | */ 172 | public resumeIndent(): this { 173 | this.writer.resumeIndent(); 174 | return this; 175 | } 176 | 177 | /** 178 | * Disables writing any end of line character for following and writeLine() calls, until 179 | * resumeEndOfLine() is called. 180 | */ 181 | public suppressEndOfLine(): this { 182 | this.writer.suppressEndOfLine(); 183 | return this; 184 | } 185 | 186 | /** 187 | * Resumes writing end of line characters after a call to suppressEndOfLine(). 188 | */ 189 | public resumeEndOfLine(): this { 190 | this.writer.resumeEndOfLine(); 191 | return this; 192 | } 193 | 194 | /** 195 | * The total number of lines currently written. 196 | */ 197 | public get loc(): number { 198 | return this.writer.loc; 199 | } 200 | 201 | /** 202 | * The total number of lines currently written, excluding comments and vertical space. 203 | */ 204 | public get sloc(): number { 205 | return this.writer.sloc; 206 | } 207 | 208 | /** 209 | * Prevents the SLOC (source lines of code) counter from being incremented. 210 | */ 211 | public freezeSloc(): this { 212 | this.writer.freezeSloc(); 213 | return this; 214 | } 215 | 216 | /** 217 | * Stops preventing the SLOC (source lines of code) counter from being incremented. 218 | */ 219 | public unfreezeSloc(): this { 220 | this.writer.unfreezeSloc(); 221 | return this; 222 | } 223 | 224 | /** 225 | * Writes the contained contents without counting the lines as SLOC (source lines of code). 226 | * This is similar to calling freezeSloc() -> contents -> unfreezeSloc(). 227 | * @param contents The code to write without increasing SLOC. 228 | */ 229 | public withFrozenSloc(contents: (writer: this) => void): this { 230 | this.writer.withFrozenSloc(() => { 231 | contents(this); 232 | }); 233 | return this; 234 | } 235 | 236 | /****************************************************************************** 237 | * End of TextWriter delegation 238 | ******************************************************************************/ 239 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. --------------------------------------------------------------------------------