Skip to content

Commit

Permalink
Change output option to nullable
Browse files Browse the repository at this point in the history
* change output option to nullable: if set `undefined` on output option when fast-maker use handler option value
* refactoring IConfig instance name to config
* add task manager command
  * re-publish command on local registry
* version upgrade: 2.0.0-RC4 > 2.0.0
  • Loading branch information
imjuni committed Jan 15, 2023
1 parent 51e9f58 commit 162e7b6
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
17 changes: 17 additions & 0 deletions .configs/just.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import execa from 'execa';
import { series, task } from 'just-task';
import readPkg from 'read-pkg';
import * as uuid from 'uuid';

function splitArgs(args: string): string[] {
Expand Down Expand Up @@ -86,6 +87,21 @@ task('+pub:prod', async () => {
});
});

task('unpub', async () => {
const packageJson = readPkg.sync();
const cmd = 'npm';
const option = `unpublish ${packageJson.name}@${packageJson.version} --registry http://localhost:8901`;

await execa(cmd, splitArgs(option), {
env: {
NODE_ENV: 'production',
RELEASE_MODE: 'true',
},
stderr: process.stderr,
stdout: process.stdout,
});
});

task('+rollup:prod', async () => {
const cmd = 'rollup';
const option = '--config ./.configs/rollup.config.prod.ts --configPlugin ts';
Expand Down Expand Up @@ -122,6 +138,7 @@ task('+tsc', async () => {

task('build', series('clean', '+tsc'));
task('pub', series('clean', 'lint', 'ctix:single', '+rollup:prod', 'ctix:remove', '+pub'));
task('repub', series('unpub', 'pub'));
task('pub:prod', series('clean', 'lint', 'ctix:single', '+rollup:prod', 'ctix:remove', '+pub:prod'));
task('rollup:prod', series('clean', 'lint', 'ctix:single', '+rollup:prod', 'ctix:remove'));
task('rollup:dev', series('clean', 'lint', 'ctix:single', '+rollup:dev', 'ctix:remove'));
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-maker",
"version": "2.0.0-RC4",
"version": "2.0.0",
"description": "create route file on specific directory",
"scripts": {
"test": "jest --coverage",
Expand All @@ -9,6 +9,7 @@
"clean": "just --config ./.configs/just.config.ts clean",
"pub:prod": "just --config ./.configs/just.config.ts pub:prod",
"pub": "just --config ./.configs/just.config.ts pub",
"repub": "just --config ./.configs/just.config.ts repub",
"ctix:single": "just --config ./.configs/just.config.ts ctix:single",
"ctix:remove": "just --config ./.configs/just.config.ts ctix:remove",
"rollup:prod": "just --config ./.configs/just.config.ts rollup:prod",
Expand Down
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const routeCmd: CommandModule<IConfig, IConfig> = {
builder,
handler: async (args) => {
try {
const output = args.output ?? args.handler;

if (process.env.SYNC_MODE === 'true') {
await routeCommandSyncHandler(args);
await routeCommandSyncHandler({ ...args, output });
} else {
await routeCommandClusterHandler(args);
await routeCommandClusterHandler({ ...args, output });
}
} catch (catched) {
const err = isError(catched) ?? new Error('unknown error raised');
Expand Down
2 changes: 1 addition & 1 deletion src/cli/command/routeCommandClusterHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default async function routeCommandClusterHandler(config: IConfig) {
throw prettfiedEither.fail;
}

await fs.promises.writeFile(path.join(config.output ?? config.handler, 'route.ts'), prettfiedEither.pass);
await fs.promises.writeFile(path.join(config.output, 'route.ts'), prettfiedEither.pass);

console.log(getReasonMessages(logbox.reasons));

Expand Down
2 changes: 1 addition & 1 deletion src/cli/command/routeCommandSyncHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function routeCommandSyncHandler(config: IConfig) {
throw prettfiedEither.fail;
}

await fs.promises.writeFile(path.join(config.output ?? config.handler, 'route.ts'), prettfiedEither.pass);
await fs.promises.writeFile(path.join(config.output, 'route.ts'), prettfiedEither.pass);

console.log(getReasonMessages(routing.pass.log.reasons));

Expand Down
6 changes: 3 additions & 3 deletions src/module/proceedStage02.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'path';
import { type Project } from 'ts-morph';
import { interpret } from 'xstate';

export default async function proceedStage02(project: Project, option: IConfig, handlers: IRouteHandler[]) {
export default async function proceedStage02(project: Project, config: IConfig, handlers: IRouteHandler[]) {
const reasons: IReason[] = [];
const logObject: Partial<IStage02Log> = {};

Expand Down Expand Up @@ -148,7 +148,7 @@ export default async function proceedStage02(project: Project, option: IConfig,
throw new Error(`Source-code is empty: ${handlerNode.filename}`);
}

const relativePath = path.relative(option.output, source.getFilePath().toString());
const relativePath = path.relative(config.output, source.getFilePath().toString());
const hash = getHash(relativePath);
const routeHandler = handlerNode.nodes.find((node): node is IHandlerStatement => node.kind === 'handler');
const routeOption = handlerNode.nodes.find((node): node is IOptionStatement => node.kind === 'option');
Expand All @@ -166,7 +166,7 @@ export default async function proceedStage02(project: Project, option: IConfig,
routeHandler: routeFile,
handler: routeHandler,
routeOption,
option,
config,
});

const service = interpret(machine);
Expand Down
2 changes: 1 addition & 1 deletion src/route/watchRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function watchRouting(config: IConfig & IWatchConfig) {
const prettfiedEither = await prettierProcessing({ code });

if (prettfiedEither.type === 'pass') {
await fs.promises.writeFile(path.join(config.output ?? config.handler, 'route.ts'), prettfiedEither.pass);
await fs.promises.writeFile(path.join(config.output, 'route.ts'), prettfiedEither.pass);
console.log(getReasonMessages(routing.pass.log.reasons));
}

Expand Down
6 changes: 3 additions & 3 deletions src/xstate/RequestHandlerAnalysisMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IAnalysisMachineContext {
routeHandler: IRouteHandler;
handler: IHandlerStatement;
currentNode: number;
option: IConfig;
config: IConfig;
routeOption?: IOptionStatement;
hash: string;

Expand Down Expand Up @@ -546,13 +546,13 @@ const requestHandlerAnalysisMachine = (
const everyTypeReferenceNodes = getTypeReferences(parameter, false);
const resolutions = getResolvedModuleInImports({
source: context.source,
option: context.option,
option: context.config,
typeReferenceNodes,
});

const localResolutions = getLocalModuleInImports({
source: context.source,
option: context.option,
option: context.config,
typeReferenceNodes,
});

Expand Down
4 changes: 2 additions & 2 deletions src/xstate/__test__/xstate.tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test('t001-FSM-TypeLiteral', async () => {
routeHandler: testRouteHandlerFile,
handler: routeHandler,
routeOption,
option: share.option,
config: share.option,
});

const service = interpret(machine);
Expand Down Expand Up @@ -151,7 +151,7 @@ test('t002-FSM-FastifyRequest', async () => {
routeHandler: testRouteHandlerFile,
handler: routeHandler,
routeOption,
option: share.option,
config: share.option,
});

const service = interpret(machine);
Expand Down

0 comments on commit 162e7b6

Please sign in to comment.