Skip to content

Commit d1de99c

Browse files
committed
Refactored to use modules
1 parent 1c2273f commit d1de99c

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

dist/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21222,6 +21222,14 @@ const getSchemaEntries = (schema) => {
2122221222
return [category_schema_entry, color_schema_entry];
2122321223
};
2122421224

21225+
;// CONCATENATED MODULE: ./src/utils/modifyRows.ts
21226+
const modifyRows = (recordMap, databaseId) => {
21227+
return Object.values(recordMap.block)
21228+
.filter((block) => block.value.id !== databaseId)
21229+
.map((block) => block.value)
21230+
.sort((rowA, rowB) => rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1);
21231+
};
21232+
2122521233
;// CONCATENATED MODULE: ./src/index.ts
2122621234
var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2122721235
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -21240,6 +21248,7 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu
2124021248

2124121249

2124221250

21251+
2124321252
function main() {
2124421253
return src_awaiter(this, void 0, void 0, function* () {
2124521254
try {
@@ -21296,10 +21305,7 @@ function main() {
2129621305
.value;
2129721306
const { schema } = collection;
2129821307
const [category_schema_entry, color_schema_entry] = getSchemaEntries(schema);
21299-
const rows = Object.values(recordMap.block)
21300-
.filter((block) => block.value.id !== databaseId)
21301-
.map((block) => block.value)
21302-
.sort((rowA, rowB) => rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1);
21308+
const rows = modifyRows(recordMap, databaseId);
2130321309
if (rows.length === 0)
2130421310
return core.error('No database rows detected');
2130521311
else {
@@ -21322,6 +21328,7 @@ function main() {
2132221328
...readmeLines.slice(endIdx)
2132321329
];
2132421330
core.info(`Writing to ${README_PATH}`);
21331+
console.log(finalLines);
2132521332
external_fs_default().writeFileSync(README_PATH, finalLines.join('\n'));
2132621333
try {
2132721334
yield commitFile();

src/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as core from '@actions/core';
22
import { NotionEndpoints } from '@nishans/endpoints';
3-
import { ICollection, ICollectionBlock, IPage } from '@nishans/types';
3+
import { ICollection, ICollectionBlock } from '@nishans/types';
44
import fs from 'fs';
55
import { checkForSections } from './utils/checkForSections';
66
import { commitFile } from './utils/commitFile';
77
import { constructCategoriesMap } from './utils/constructCategoriesMap';
88
import { constructNewContents } from './utils/constructNewContents';
99
import { getSchemaEntries } from './utils/getSchemaEntries';
10+
import { modifyRows } from './utils/modifyRows';
1011

1112
async function main() {
1213
try {
@@ -87,12 +88,7 @@ async function main() {
8788
schema
8889
);
8990

90-
const rows = Object.values(recordMap.block)
91-
.filter((block) => block.value.id !== databaseId)
92-
.map((block) => block.value as IPage)
93-
.sort((rowA, rowB) =>
94-
rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1
95-
);
91+
const rows = modifyRows(recordMap, databaseId);
9692

9793
if (rows.length === 0) return core.error('No database rows detected');
9894
else {
@@ -123,6 +119,8 @@ async function main() {
123119

124120
core.info(`Writing to ${README_PATH}`);
125121

122+
console.log(finalLines);
123+
126124
fs.writeFileSync(README_PATH, finalLines.join('\n'));
127125

128126
try {

src/utils/modifyRows.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { IPage, RecordMap } from '@nishans/types';
2+
3+
export const modifyRows = (
4+
recordMap: Pick<RecordMap, 'block'>,
5+
databaseId: string
6+
) => {
7+
return Object.values(recordMap.block)
8+
.filter((block) => block.value.id !== databaseId)
9+
.map((block) => block.value as IPage)
10+
.sort((rowA, rowB) =>
11+
rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1
12+
);
13+
};

0 commit comments

Comments
 (0)