Skip to content

Commit

Permalink
add nodejs-src action
Browse files Browse the repository at this point in the history
add openapi stub action
  • Loading branch information
TimurRin committed Sep 4, 2024
1 parent 9f9d441 commit df9736b
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 4 deletions.
4 changes: 2 additions & 2 deletions anca.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dataVersion": 0,
"version": {
"latest": "0.1.0-dev.2",
"latestNext": "0.1.0-dev.2+next.20240904_084209",
"timestamp": 1725439329
"latestNext": "0.1.0-dev.2+next.20240904_133911",
"timestamp": 1725457151
},
"files": [
{
Expand Down
93 changes: 93 additions & 0 deletions src/actions/nodejs-src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import fs from "fs";
import path from "path";

import { AncaDevelopment } from "../schema.js";
import { writeFolderFile } from "../utils.js";

const SRC_FILE_PATH = "./src/index.ts";
const TEST_FILE_PATH = "./test/index.test.ts";

/**
*
* @param development
*/
function getSrcContents(development: AncaDevelopment) {
return `console.log("Hello, Anca!"); // ${development.fullPath}\n`;
}

/**
*
* @param development
*/
function getTestContents(development: AncaDevelopment) {
return `console.log("Hello, Test Anca!"); // ${development.fullPath}\n`;
}

/**
*
* @param development
*/
export async function checkNodejsSrc(development: AncaDevelopment) {
if (development.state == null) {
return;
}
const contents = development.state.files[SRC_FILE_PATH];
if (contents == null) {
return false;
}

return contents === getSrcContents(development);
}

/**
*
* @param development
*/
export async function checkNodejsTest(development: AncaDevelopment) {
if (development.state == null) {
return;
}
const contents = development.state.files[TEST_FILE_PATH];
console.log(contents);
if (contents == null) {
return false;
}

return contents === getTestContents(development);
}

/**
*
* @param development
*/
export async function fixNodejsSrc(development: AncaDevelopment) {
if (development.state == null) {
return;
}
await fs.promises.mkdir(path.join(development.fullPath, "src"), {
recursive: true,
});
await writeFolderFile(
development.fullPath,
SRC_FILE_PATH,
getSrcContents(development),
);
}

/**
*
* @param development
*/
export async function fixNodejsTest(development: AncaDevelopment) {
if (development.state == null) {
return;
}
await fs.promises.mkdir(path.join(development.fullPath, "test"), {
recursive: true,
});
await writeFolderFile(
development.fullPath,
TEST_FILE_PATH,
getTestContents(development),
);
}
43 changes: 43 additions & 0 deletions src/actions/openapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { AncaDevelopment } from "../schema.js";
import { writeFolderFile } from "../utils.js";

const FILE_PATH = "openapi.json";

/**
*
* @param development
*/
function getContents(development: AncaDevelopment) {
return "json content of openapi " + development.fullPath;
}

/**
*
* @param development
*/
export async function checkOpenapiJson(development: AncaDevelopment) {
if (development.state == null) {
return;
}
const contents = development.state.files[FILE_PATH];
if (contents == null) {
return false;
}

return contents === getContents(development);
}

/**
*
* @param development
*/
export async function fixOpenapiJson(development: AncaDevelopment) {
if (development.state == null) {
return;
}
await writeFolderFile(
development.fullPath,
FILE_PATH,
getContents(development),
);
}
4 changes: 2 additions & 2 deletions src/cinnabar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by Cinnabar Meta. Do not edit.

export const CINNABAR_PROJECT_TIMESTAMP = 1725439329;
export const CINNABAR_PROJECT_VERSION = "0.1.0-dev.2+next.20240904_084209";
export const CINNABAR_PROJECT_TIMESTAMP = 1725457151;
export const CINNABAR_PROJECT_VERSION = "0.1.0-dev.2+next.20240904_133911";
53 changes: 53 additions & 0 deletions src/developments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import {
checkNodejsSeaBuildJs,
checkNodejsSeaConfigJson,
} from "./actions/nodejs-sea.js";
import { checkNodejsSrc, checkNodejsTest } from "./actions/nodejs-src.js";
import { checkNodejsTsconfigJson } from "./actions/nodejs-tsconfig.js";
import { checkNodejsTsupConfigJs } from "./actions/nodejs-tsup.js";
import { checkOpenapiJson } from "./actions/openapi.js";
import { checkReadmeMd } from "./actions/readme.js";
import { checkForGit, getGit } from "./git.js";
import { getDevelopmentMeta } from "./meta.js";
Expand Down Expand Up @@ -204,13 +206,15 @@ export async function refreshDevelopmentState(
await addCommonToDevelopmentPack(development);
await addDevcontainersToDevelopmentPack(development);
await addGithubActionsToDevelopmentPack(development);
await addOpenapiJsonToDevelopmentPack(development);
await addNodeJsToDevelopmentPack(development);

state.meta = getDevelopmentMeta(development);

await checkCommonToDevelopmentPack(development);
await checkDevcontainersToDevelopmentPack(development);
await checkGithubActionsToDevelopmentPack(development);
await checkOpenapiJsonDevelopmentPack(development);
await checkNodeJsToDevelopmentPack(development);
}

Expand Down Expand Up @@ -393,6 +397,44 @@ async function checkGithubActionsToDevelopmentPack(
}
}

/**
*
* @param development
*/
async function addOpenapiJsonToDevelopmentPack(development: AncaDevelopment) {
if (development.state == null) {
return;
}
if (development.state.config.monorepo != null) {
return;
}
if (development.state.config.stack !== "nodejs") {
return;
}

await addJsonFileToPack(development, "openapi.json");
}

/**
*
* @param development
*/
async function checkOpenapiJsonDevelopmentPack(development: AncaDevelopment) {
if (development.state == null) {
return;
}
if (development.state.config.monorepo != null) {
return;
}
if (development.state.config.stack !== "nodejs") {
return;
}

if (!(await checkOpenapiJson(development))) {
development.state.issues.push("openapiJsonSetToDefault");
}
}

/**
*
* @param development
Expand All @@ -408,6 +450,9 @@ async function addNodeJsToDevelopmentPack(development: AncaDevelopment) {
return;
}

await addFileToPack(development, "./src/index.ts");
await addFileToPack(development, "./test/index.test.ts");

await addFileToPack(development, ".prettierignore");
await addFileToPack(development, ".prettierrc");

Expand Down Expand Up @@ -444,6 +489,14 @@ async function checkNodeJsToDevelopmentPack(development: AncaDevelopment) {
return;
}

if (!(await checkNodejsSrc(development))) {
development.state.issues.push("nodejsSrcSetToDefault");
}

if (!(await checkNodejsTest(development))) {
development.state.issues.push("nodejsTestSetToDefault");
}

if (!(await checkNodejsPrettierIgnore(development))) {
development.state.issues.push("nodejsPrettierIgnoreSetToDefault");
}
Expand Down
3 changes: 3 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export type AncaAction =
| "nodejsPrettierRcSetToDefault"
| "nodejsSeaBuildJsSetToDefault"
| "nodejsSeaConfigJsonSetToDefault"
| "nodejsSrcSetToDefault"
| "nodejsTestSetToDefault"
| "nodejsTsconfigSetToDefault"
| "nodejsTsupConfigJsSetToDefault"
| "openapiJsonSetToDefault"
| "readmeSetToDefault";

export interface AncaMeta {
Expand Down
23 changes: 23 additions & 0 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import {
fixNodejsSeaBuildJs,
fixNodejsSeaConfigJson,
} from "./actions/nodejs-sea.js";
import { fixNodejsSrc, fixNodejsTest } from "./actions/nodejs-src.js";
import { fixNodejsTsconfigJson } from "./actions/nodejs-tsconfig.js";
import { fixNodejsTsupConfigJs } from "./actions/nodejs-tsup.js";
import { fixOpenapiJson } from "./actions/openapi.js";
import { fixReadmeMd } from "./actions/readme.js";
import { CINNABAR_PROJECT_VERSION } from "./cinnabar.js";
import { getInstance } from "./config.js";
Expand Down Expand Up @@ -235,6 +237,20 @@ async function showDevelopmentActions(
},
label: "[sea.config.json] Set to default",
},
nodejsSrcSetToDefault: {
action: async () => {
await fixNodejsSrc(development);
await backHere();
},
label: "[src/index.ts] Set to default",
},
nodejsTestSetToDefault: {
action: async () => {
await fixNodejsTest(development);
await backHere();
},
label: "[test/index.test.ts] Set to default",
},
nodejsTsconfigSetToDefault: {
action: async () => {
await fixNodejsTsconfigJson(development);
Expand All @@ -249,6 +265,13 @@ async function showDevelopmentActions(
},
label: "[tsup.config.js] Set to default",
},
openapiJsonSetToDefault: {
action: async () => {
await fixOpenapiJson(development);
await backHere();
},
label: "[openapi.json] Set to default",
},
readmeSetToDefault: {
action: async () => {
await fixReadmeMd(development);
Expand Down

0 comments on commit df9736b

Please sign in to comment.