rbxts-transformer-commit-migrations 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/init.js +9 -8
- package/index.d.ts +3 -3
- package/out/index.js +15 -8
- package/package.json +1 -2
package/bin/init.js
CHANGED
|
@@ -11,19 +11,20 @@ const huskyDir = resolve(dir, ".husky");
|
|
|
11
11
|
const hookFile = resolve(huskyDir, "pre-commit");
|
|
12
12
|
|
|
13
13
|
if (!existsSync(huskyDir)) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
console.error("No .husky folder found. Run `npx husky init` first.");
|
|
15
|
+
process.exit(1);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const setupResolve = `npx resolve-commit-migrations\n`;
|
|
19
19
|
|
|
20
20
|
if (existsSync(hookFile)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const existing = readFileSync(hookFile, "utf-8");
|
|
22
|
+
|
|
23
|
+
if (!existing.includes(setupResolve)) {
|
|
24
|
+
writeFileSync(hookFile, existing + `\n${setupResolve}`);
|
|
25
|
+
}
|
|
25
26
|
} else {
|
|
26
|
-
|
|
27
|
+
writeFileSync(hookFile, setupResolve);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
console.log("Added
|
|
30
|
+
console.log("Added commit-migration macro stamp to .husky/pre-commit");
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function $migrate(order: number): never;
|
|
2
|
-
declare function $migrate(order: "__resolved"): number;
|
|
3
|
-
declare function $migrate(order: number | "__resolved"): number
|
|
1
|
+
export declare function $migrate(order: number): never;
|
|
2
|
+
export declare function $migrate(order: "__resolved"): number;
|
|
3
|
+
export declare function $migrate(order: number | "__resolved"): number | undefined;
|
package/out/index.js
CHANGED
|
@@ -2,19 +2,26 @@ import ts from "typescript";
|
|
|
2
2
|
import { findMacroCall, replaceMacroCall } from "./macro.js";
|
|
3
3
|
import loadMigrationEntries from "./util/loadMigrationEntries.js";
|
|
4
4
|
import { CONFIG } from "./config.js";
|
|
5
|
-
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
export default function (_, config) {
|
|
6
7
|
return (ctx) => {
|
|
8
|
+
const configPath = config?.configPath ?? CONFIG;
|
|
9
|
+
if (!existsSync(configPath)) {
|
|
10
|
+
console.error(`Invalid migration config path ${configPath}`);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
const [entryArr, entries] = loadMigrationEntries(configPath);
|
|
14
|
+
const orderedEntries = entryArr
|
|
15
|
+
.map((i) => ({ i, timestamp: entries[i].timestamp, order: entries[i].order }))
|
|
16
|
+
.toSorted((a, b) => a.timestamp - b.timestamp || a.order - b.order)
|
|
17
|
+
.map(({ i }) => i);
|
|
7
18
|
return (file) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.map((i) => ({ i, timestamp: entries[i].timestamp, order: entries[i].order }))
|
|
11
|
-
.toSorted((a, b) => a.timestamp - b.timestamp || a.order - b.order)
|
|
12
|
-
.map(({ i }) => i);
|
|
13
|
-
console.log(orderedEntries);
|
|
19
|
+
if (config?.files && !config.files.some((f) => file.fileName.includes(f)))
|
|
20
|
+
return file;
|
|
14
21
|
function visit(node) {
|
|
15
22
|
if (!ts.isPropertyAssignment(node) || !findMacroCall(node.initializer))
|
|
16
23
|
return ts.visitEachChild(node, visit, ctx);
|
|
17
|
-
const entry = node.name.getText(file);
|
|
24
|
+
const entry = ts.isIdentifier(node.name) ? node.name.text : node.name.getText(file);
|
|
18
25
|
const replacement = orderedEntries.indexOf(entry);
|
|
19
26
|
if (replacement !== -1) {
|
|
20
27
|
const newInit = replaceMacroCall(node.initializer, replacement);
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rbxts-transformer-commit-migrations",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "rbxts transformer used in user data migration builder chains",
|
|
5
5
|
"main": "out/index.js",
|
|
6
|
-
"typegis": "index.d.ts",
|
|
7
6
|
"type": "module",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"build": "tsc"
|