generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa2d60c
commit 2b6f104
Showing
11 changed files
with
76 additions
and
86 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,44 @@ | ||
import {readdir} from 'fs' | ||
import {Collection} from './models' | ||
import {readJSON, writeJSON} from './json-io' | ||
import { readJSON, writeJSON } from "./json-io"; | ||
import { readdir } from "fs/promises"; | ||
import { Collection } from "./models"; | ||
|
||
export async function processCollections( | ||
collections: Collection[] | ||
): Promise<void> { | ||
return new Promise(async (resolve, reject) => { | ||
const tasks = collections.map(processCollection) | ||
const results = await Promise.all(tasks) // Gather up the results. | ||
resolve() | ||
}) | ||
const tasks = collections.map(processCollection); | ||
try { | ||
await Promise.all(tasks); // Gather up the results. | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
|
||
async function processCollection(definition: Collection): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const records: {[id: string]: unknown} = {} | ||
const collection = {definition, records} | ||
processCollectionRecords(collection) | ||
.then(() => { | ||
resolve() | ||
}) | ||
.catch(reject) | ||
}) | ||
const records: { [id: string]: unknown } = {}; | ||
const collection = { definition, records }; | ||
return processCollectionRecords(collection); | ||
} | ||
|
||
interface ICollection { | ||
definition: Collection | ||
records: {[id: string]: unknown} | ||
definition: Collection; | ||
records: { [id: string]: unknown }; | ||
} | ||
|
||
async function processCollectionRecords( | ||
collection: ICollection | ||
): Promise<void> { | ||
return new Promise<void>((resolve, reject) => { | ||
readdir(collection.definition.dir, (err, files) => { | ||
if (err) { | ||
reject(err) | ||
return | ||
} | ||
const tasks = files.map(async file => processRecordDir(collection, file)) | ||
Promise.all(tasks) | ||
.then(() => resolve()) | ||
.catch(reject) | ||
}) | ||
}) | ||
async function processCollectionRecords(collection: ICollection): Promise<void> { | ||
const files = await readdir(collection.definition.dir); | ||
const tasks = files.map(async file => processRecordDir(collection, file)); | ||
await Promise.all(tasks); | ||
} | ||
|
||
async function processRecordDir( | ||
collection: ICollection, | ||
dirPath: string | ||
): Promise<unknown> { | ||
const jsonPath = `${dirPath}/record.json` | ||
const record = await readJSON(jsonPath) | ||
await writeJSON(record, jsonPath) | ||
return Promise.resolve(record) | ||
const jsonPath = `${dirPath}/record.json`; | ||
const record = await readJSON(jsonPath); | ||
await writeJSON(record, jsonPath); | ||
return Promise.resolve(record); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import * as core from '@actions/core' | ||
import {readJSONSync} from './json-io' | ||
import {wait} from './wait' | ||
import * as core from '@actions/core'; | ||
import { readJSONSync } from './json-io'; | ||
import { wait } from './wait'; | ||
|
||
async function run(): Promise<void> { | ||
try { | ||
const data = readJSONSync('.ingitdb/.ingitdb.json') | ||
const data = readJSONSync('.ingitdb/.ingitdb.json'); | ||
// eslint-disable-next-line no-console | ||
console.log('.ingitdb.json:', data) | ||
console.log('.ingitdb.json:', data); | ||
|
||
const ms: string = core.getInput('milliseconds') | ||
const ms: string = core.getInput('milliseconds'); | ||
// eslint-disable-next-line i18n-text/no-en | ||
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true | ||
core.debug(`Waiting ${ms} milliseconds ...`); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true | ||
|
||
core.debug(new Date().toTimeString()) | ||
await wait(parseInt(ms, 10)) | ||
core.debug(new Date().toTimeString()) | ||
core.debug(new Date().toTimeString()); | ||
await wait(parseInt(ms, 10)); | ||
core.debug(new Date().toTimeString()); | ||
|
||
core.setOutput('time', new Date().toTimeString()) | ||
core.setOutput('time', new Date().toTimeString()); | ||
} catch (error) { | ||
core.setFailed((error as Error).message) | ||
core.setFailed((error as Error).message); | ||
} | ||
} | ||
|
||
run() | ||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
export interface Collection { | ||
dir: string | ||
recordMode: 'directory' | 'json' | ||
primaryKey: string[] | ||
fields: Field[] | ||
title: TitleItem[] | ||
dir: string; | ||
recordMode: "directory" | "json"; | ||
primaryKey: string[]; | ||
fields: Field[]; | ||
title: TitleItem[]; | ||
} | ||
|
||
export interface TitleItem { | ||
field?: string | ||
str?: string | ||
func?: 'UPPERCASE' | ||
field?: string; | ||
str?: string; | ||
func?: "UPPERCASE"; | ||
} | ||
|
||
export interface Field { | ||
name: string | ||
type: 'string' | 'number' | 'url' | 'boolean' | ||
min?: number | ||
max?: number | ||
name: string; | ||
type: "string" | "number" | "url" | "boolean"; | ||
min?: number; | ||
max?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export async function wait(milliseconds: number): Promise<string> { | ||
return new Promise(resolve => { | ||
if (isNaN(milliseconds)) { | ||
throw new Error('milliseconds not a number') | ||
throw new Error('milliseconds not a number'); | ||
} | ||
|
||
setTimeout(() => resolve('done!'), milliseconds) | ||
}) | ||
setTimeout(() => resolve('done!'), milliseconds); | ||
}); | ||
} |