packages/schema-diff/docs/classes/Directory.html
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>@java-patterns/schema-diff documentation</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../styles/style.css">
<link rel="stylesheet" href="../styles/dark.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top visible-xs">
<a href="../" class="navbar-brand">@java-patterns/schema-diff documentation</a>
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
</div>
<div class="xs-menu menu" id="mobile-menu">
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
</div>
<div class="container-fluid main">
<div class="row main">
<div class="hidden-xs menu">
<compodoc-menu mode="normal"></compodoc-menu>
</div>
<!-- START CONTENT -->
<div class="content class">
<div class="content-data">
<ol class="breadcrumb">
<li>Classes</li>
<li >Directory</li>
</ol>
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#info" role="tab" id="info-tab" data-toggle="tab" data-link="info">Info</a>
</li>
<li >
<a href="#source" role="tab" id="source-tab" data-toggle="tab" data-link="source">Source</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="c-info">
<p class="comment">
<h3>File</h3>
</p>
<p class="comment">
<code>src/index.ts</code>
</p>
<section>
<h3 id="index">Index</h3>
<table class="table table-sm table-bordered index-table">
<tbody>
<tr>
<td class="col-md-4">
<h6><b>Properties</b></h6>
</td>
</tr>
<tr>
<td class="col-md-4">
<ul class="index-list">
<li>
<a href="#fileMap" >fileMap</a>
</li>
<li>
<a href="#fullPath" >fullPath</a>
</li>
<li>
<a href="#name" >name</a>
</li>
<li>
<a href="#nodes" >nodes</a>
</li>
<li>
<a href="#path" >path</a>
</li>
</ul>
</td>
</tr>
<tr>
<td class="col-md-4">
<h6><b>Methods</b></h6>
</td>
</tr>
<tr>
<td class="col-md-4">
<ul class="index-list">
<li>
<span class="modifier">Static</span>
<span class="modifier">Async</span>
<a href="#create" >create</a>
</li>
<li>
<span class="modifier">Private</span>
<span class="modifier">Static</span>
<span class="modifier">Async</span>
<a href="#getChildren" >getChildren</a>
</li>
<li>
<span class="modifier">Public</span>
<a href="#getFile" >getFile</a>
</li>
<li>
<span class="modifier">Public</span>
<a href="#hasFile" >hasFile</a>
</li>
<li>
<span class="modifier">Public</span>
<a href="#listFiles" >listFiles</a>
</li>
<li>
<span class="modifier">Public</span>
<a href="#walk" >walk</a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 id="constructor">Constructor</h3>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<span class="modifier">Private</span>
<code>constructor(fullPath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, nodes: <a href="../undefineds/FSNode.html" target="_self">FSNode[]</a>, fileMap: <a href="../classes/File.html" target="_self">FileMap</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="171" class="link-to-prism">src/index.ts:171</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div>
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>fullPath</td>
<td>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
<td>
No
</td>
</tr>
<tr>
<td>nodes</td>
<td>
<code><a href="../miscellaneous/typealiases.html#FSNode" target="_self" >FSNode[]</a></code>
</td>
<td>
No
</td>
</tr>
<tr>
<td>fileMap</td>
<td>
<code><a href="../classes/File.html" target="_self" >FileMap</a></code>
</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 id="inputs">
Properties
</h3>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="fileMap"></a>
<span class="name">
<span ><b>fileMap</b></span>
<a href="#fileMap"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<i>Type : </i> <code>literal type</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="171" class="link-to-prism">src/index.ts:171</a></div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="fullPath"></a>
<span class="name">
<span ><b>fullPath</b></span>
<a href="#fullPath"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="169" class="link-to-prism">src/index.ts:169</a></div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="name"></a>
<span class="name">
<span ><b>name</b></span>
<a href="#name"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="167" class="link-to-prism">src/index.ts:167</a></div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="nodes"></a>
<span class="name">
<span ><b>nodes</b></span>
<a href="#nodes"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<i>Type : </i> <code>Array<File | Directory></code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="170" class="link-to-prism">src/index.ts:170</a></div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="path"></a>
<span class="name">
<span ><b>path</b></span>
<a href="#path"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="168" class="link-to-prism">src/index.ts:168</a></div>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 id="methods">
Methods
</h3>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="create"></a>
<span class="name">
<span class="modifier">Static</span>
<span class="modifier">Async</span>
<span ><b>create</b></span>
<a href="#create"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>create(fullPath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, _deltaFileMap: <a href="../classes/File.html" target="_self">DeltaFileMap</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="181"
class="link-to-prism">src/index.ts:181</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Default value</td>
</tr>
</thead>
<tbody>
<tr>
<td>fullPath</td>
<td>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
<td>
No
</td>
<td>
</td>
</tr>
<tr>
<td>_deltaFileMap</td>
<td>
<code><a href="../classes/File.html" target="_self" >DeltaFileMap</a></code>
</td>
<td>
No
</td>
<td>
<code>{}</code>
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code>unknown</code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="getChildren"></a>
<span class="name">
<span class="modifier">Private</span>
<span class="modifier">Static</span>
<span class="modifier">Async</span>
<span ><b>getChildren</b></span>
<a href="#getChildren"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>getChildren(fullPath)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="186"
class="link-to-prism">src/index.ts:186</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>fullPath</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code>Promise<></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="getFile"></a>
<span class="name">
<span class="modifier">Public</span>
<span ><b>getFile</b></span>
<a href="#getFile"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>getFile(fullPath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="223"
class="link-to-prism">src/index.ts:223</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>fullPath</td>
<td>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="../classes/File.html" target="_self" >File</a></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="hasFile"></a>
<span class="name">
<span class="modifier">Public</span>
<span ><b>hasFile</b></span>
<a href="#hasFile"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>hasFile(fullPath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="219"
class="link-to-prism">src/index.ts:219</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>fullPath</td>
<td>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="listFiles"></a>
<span class="name">
<span class="modifier">Public</span>
<span ><b>listFiles</b></span>
<a href="#listFiles"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>listFiles()</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="227"
class="link-to-prism">src/index.ts:227</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Returns : </b> <code>string[]</code>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="walk"></a>
<span class="name">
<span class="modifier">Public</span>
<span ><b>walk</b></span>
<a href="#walk"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<span class="modifier-icon icon ion-ios-reset"></span>
<code>walk(callback: (undefined) => void)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="209"
class="link-to-prism">src/index.ts:209</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Calls a callback for every file of this directory and its sub directories</p>
</div>
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td>
<td>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
</section>
</div>
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {createReadStream, promises as fs} from "fs";
import path from "path";
import {createHash} from "crypto";
import {spawn} from "child_process";
const schemaV1Path = path.join(process.cwd(), `${process.env.SOURCE_DIR1}`).normalize()
const schemaV2Path = path.join(process.cwd(), `${process.env.SOURCE_DIR2}`).normalize()
const baseV1Name = path.basename(schemaV1Path)
const baseV2Name = path.basename(schemaV2Path)
/** Represents the git status of a file */
enum FileStatus {
Deleted = "deleted",
Modified = "modified",
Added = "added",
Renamed = "renamed",
Unknown = "unknown",
}
type DeltaFileMap = { [filePath: string]: FileStatus }
/**
* Converts git status short codes to their `FileStatus` equivalent.
* @param change Single character shorthand git file state
*/
const GitChangeToFileStatus = (change: string) => {
switch (change) {
case "M":
return FileStatus.Modified
case "A":
return FileStatus.Added
case "D":
return FileStatus.Deleted
case "R":
return FileStatus.Renamed
default:
return FileStatus.Unknown
}
}
interface BranchState {
commitsAhead: number
commitsBehind: number
}
/**
* Gives status information on the current branch as compared to origin/main
*/
const getBranchDrift = (): Promise<BranchState> =>
new Promise((resolve, reject) => {
let output = ""
const delta = spawn("git", [
"rev-list",
"--left-right",
"--count",
"origin/main...HEAD",
])
delta.stdout.on("data", (data) => {
output += data
})
delta.on("close", (code) => {
if (code !== 0) {
reject("Failed to get branch drift")
} else {
const commitChanges = output.match(/(\d+)\s+(\d+)/)
if (!commitChanges) {
reject("Something was wrong with the branch drift output")
}
let [, commitsBehind, commitsAhead] = Array.from(
commitChanges!
).map((x) => Number(x))
resolve({
commitsAhead,
commitsBehind,
})
}
})
})
/**
* Uses git to generate a delta map of files that have changed since main
*/
const getChangedFiles = (): Promise<DeltaFileMap> =>
new Promise((resolve, reject) => {
let changedBlob = ""
const changed = spawn("git", ["diff", "--name-status", "origin/main"])
changed.stdout.on("data", (data) => {
changedBlob += data
})
changed.on("close", (code) => {
if (code !== 0) {
reject("Failed to find changed files via git")
} else {
resolve(
changedBlob
.split("\n")
.map((status) => {
const match = status.match(/([A-Z])\s+(.+)/)
if (match) {
const [, status, filePath] = match
return {
[path.resolve(filePath)]: GitChangeToFileStatus(status),
}
}
return {} as any
})
.reduce((a, b) => ({...a, ...b}), {})
)
}
})
})
/**
* Determines if a given path is a directory
* @param filepath
*/
const isDirectory = async (filepath: string): Promise<boolean> =>
(await fs.lstat(filepath)).isDirectory()
/**
* Asynchronously generates an md5 of a file
* @param filePath The full path to a file (include its name)
*/
const hashFile = (filePath: string): Promise<string> =>
new Promise((resolve, reject) => {
const stream = createReadStream(filePath)
const hash = createHash("md5")
stream.on("data", (data: string) => hash.update(data, "utf8"))
stream.on("end", () => {
resolve(hash.digest("hex"))
})
stream.on("error", (error) => {
reject(error)
})
})
type FSNode = File | Directory
type FileMap = { [path: string]: File }
class File {
name: string
path: string
fullPath: string
relativePath: string
hash: string
private constructor(fullPath: string, hash: string) {
this.name = path.basename(fullPath)
this.path = path.dirname(fullPath)
this.fullPath = fullPath
this.relativePath = path.relative(process.cwd(), fullPath)
this.hash = hash
}
static async create(fullPath: string) {
return new File(fullPath, await hashFile(fullPath))
}
}
class Directory {
name: string
path: string
fullPath: string
nodes: Array<File | Directory>
fileMap: { [path: string]: File }
private constructor(fullPath: string, nodes: FSNode[], fileMap: FileMap) {
this.name = path.basename(fullPath)
this.path = path.dirname(fullPath)
this.fullPath = fullPath
this.nodes = nodes
this.fileMap = fileMap
}
static async create(fullPath: string, _deltaFileMap: DeltaFileMap = {}) {
const [children, childMap] = await this.getChildren(fullPath)
return new Directory(fullPath, children, childMap)
}
private static async getChildren(fullPath): Promise<[FSNode[], FileMap]> {
const nodes: FSNode[] = []
const fileNames = await fs.readdir(fullPath)
let fileMap: FileMap = {}
for (let fileName of fileNames) {
const currentPath = path.join(fullPath, fileName)
if (await isDirectory(currentPath)) {
let dir = await Directory.create(currentPath)
nodes.push(dir)
fileMap = {...fileMap, ...dir.fileMap}
} else {
let file = await File.create(currentPath)
nodes.push(file)
fileMap[file.fullPath] = file
}
}
return [nodes, fileMap]
}
/**
* Calls a callback for every file of this directory and its sub directories
*/
public walk(callback: (File) => void) {
for (let child of this.nodes) {
if (child instanceof Directory) {
child.walk(callback)
} else {
callback(child)
}
}
}
public hasFile(fullPath: string) {
!!this.fileMap[fullPath]
}
public getFile(fullPath: string): File {
return this.fileMap[fullPath]
}
public listFiles(): string[] {
return Object.keys(this.fileMap)
}
}
const isFromSchemaV1 = (filePath: string) => filePath.includes(baseV1Name)
/** Convert an absolute file path to a partial path that starts after `/v1/` or `/v2/` */
const fromSchemaRoot = (filePath: string) =>
isFromSchemaV1(filePath)
? filePath.split(baseV1Name)[1]
: filePath.split(baseV2Name)[1]
/** Updates a path from `/v1/` to `/v2/` or vice versa */
const switchSchemaPath = (filePath: string) =>
isFromSchemaV1(filePath)
? filePath.replace(baseV1Name, baseV2Name)
: filePath.replace(baseV2Name, baseV1Name)
/**
* @param directory1
* @param directory2
* @param directoryMapper Used to establish a common path between files of the two directories
*/
const diffDirectories = (
directory1: Directory,
directory2: Directory,
directoryMapper = (p) => p
): [string[], string[], string[]] => {
const fileList1 = directory1.listFiles().map(directoryMapper)
const fileList2 = directory2.listFiles().map(directoryMapper)
const sharedFiles = fileList1.filter((x) => fileList2.includes(x))
const filesUniqueTo1 = fileList1.filter((x) => !sharedFiles.includes(x))
const filesUniqueTo2 = fileList2.filter((x) => !sharedFiles.includes(x))
return [filesUniqueTo1, sharedFiles, filesUniqueTo2]
}
// Main work
;(async () => {
const branchState = await getBranchDrift()
// Is there a better way to handle this?
if (branchState.commitsBehind > 0) {
console.warn("Branch is currently behind main, might not reflect accurate state\n")
}
const fileChanges = Object.entries(await getChangedFiles()).filter(
([file]) => file.includes(baseV1Name) || file.includes(baseV2Name)
)
// If no file updates, skip
if (fileChanges.length === 0) {
console.log(`No updates detected in ${baseV1Name} or ${baseV2Name}, skipping...\n`)
return
}
// Read files from the FS
const schemaV1 = await Directory.create(schemaV1Path)
const schemaV2 = await Directory.create(schemaV2Path)
// Sort out which files are shared by v1 and v2
const [
filesUniqueToSchemaV1,
filesInBothSchemas,
// filesUniqueToSchemaV2,
] = diffDirectories(schemaV1, schemaV2, fromSchemaRoot)
const unknownChanges = fileChanges
.filter(([, status]) => status === FileStatus.Unknown)
.map(([file]) => file)
const modifiedFiles = fileChanges
.filter(([, status]) => status === FileStatus.Modified)
.map(([file]) => file)
const addedFiles = fileChanges
.filter(([, status]) => status === FileStatus.Added)
.map(([file]) => file)
// const deletedFiles = fileChanges
// .filter(([, status]) => status === FileStatus.Deleted)
// .map(([file]) => file)
// const renamedFiles = fileChanges
// .filter(([, status]) => status === FileStatus.Renamed)
// .map(([file]) => file)
if (unknownChanges.length > 0) {
console.warn(
"File changes detect with unknown git status, please verify the following and update the schema drift script\n" +
unknownChanges.map((file) => `- ${file}\n`)
)
}
// Scenarios
//
// For files that exist in both places
// File A was modified in (v1|v2), should it also be modified in (v2|v1)?
modifiedFiles
.map((filePath) => [fromSchemaRoot(filePath), filePath])
.filter(([file]) => filesInBothSchemas.includes(file))
.forEach(([, filePath]) => {
if (isFromSchemaV1(filePath)) {
const schemaV1File = schemaV1.getFile(filePath)
const schemaV2File = schemaV2.getFile(switchSchemaPath(filePath))
// Both files are the same now, nothing to do here
if (schemaV1File.hash === schemaV2File.hash) return
console.warn(
`${schemaV1File.relativePath} has been modified, should this update also happen in ${schemaV2File.relativePath}?`
)
} else {
const schemaV2File = schemaV2.getFile(filePath)
const schemaV1File = schemaV1.getFile(switchSchemaPath(filePath))
// The files are the same, skip
if (schemaV2File.hash === schemaV1File.hash) return
console.warn(
`${schemaV2File.relativePath} has been modified, should this update also happen in ${schemaV1File.relativePath}?`
)
}
})
// For files added during transition
// File was added to v1, should it also exist in v2?
addedFiles
.map((filePath) => [fromSchemaRoot(filePath), filePath])
.filter(([file]) => filesUniqueToSchemaV1.includes(file))
.forEach(([, filePath]) => {
const file = schemaV1.getFile(filePath)
console.warn(
`${file.relativePath} was added to v1, should it also be added to v2?`
)
})
// For updates in v1 that don't match to V2
// An update was made to a file in v1, but it doesn't exist in V2. Double
// check that there aren't updates required.
modifiedFiles
.map((filePath) => [fromSchemaRoot(filePath), filePath])
.filter(([file]) => filesUniqueToSchemaV1.includes(file))
.forEach(([, filePath]) => {
const file = schemaV1.getFile(filePath)
console.warn(
`${file.relativePath} was modified in v1, but doesn't exist in v2. Ensure no v2 changes are required.`
)
})
})()
</code></pre>
</div>
</div>
</div><div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
</div>
<label class="dark-mode-switch">
<input type="checkbox">
<span class="slider">
<svg class="slider-icon" viewBox="0 0 24 24" fill="none" height="20" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" width="20" xmlns="http://www.w3.org/2000/svg">
<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"></path>
</svg>
</span>
</label>
<script>
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
var COMPODOC_CURRENT_PAGE_CONTEXT = 'class';
var COMPODOC_CURRENT_PAGE_URL = 'Directory.html';
var MAX_SEARCH_RESULTS = 15;
</script>
<script src="../js/libs/custom-elements.min.js"></script>
<script src="../js/libs/lit-html.js"></script>
<script src="../js/menu-wc.js" defer></script>
<script nomodule src="../js/menu-wc_es5.js" defer></script>
<script src="../js/libs/bootstrap-native.js"></script>
<script src="../js/libs/es6-shim.min.js"></script>
<script src="../js/libs/EventDispatcher.js"></script>
<script src="../js/libs/promise.min.js"></script>
<script src="../js/libs/zepto.min.js"></script>
<script src="../js/compodoc.js"></script>
<script src="../js/tabs.js"></script>
<script src="../js/menu.js"></script>
<script src="../js/libs/clipboard.min.js"></script>
<script src="../js/libs/prism.js"></script>
<script src="../js/sourceCode.js"></script>
<script src="../js/search/search.js"></script>
<script src="../js/search/lunr.min.js"></script>
<script src="../js/search/search-lunr.js"></script>
<script src="../js/search/search_index.js"></script>
<script src="../js/lazy-load-graphs.js"></script>
</body>
</html>