Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clean temp directory in local env #597

Merged
merged 4 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/faas-cli-plugin-dev-pack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export class DevPackPlugin extends BasePlugin {
}

async checkPort() {
if (
this.options.clean === 'false' ||
this.options.clean === false ||
this.options.clean === 'true' ||
this.options.clean === true
) {
process.env.MIDWAY_LOCAL_CLEAN = String(this.options.clean);
}
if (this.options.port) {
if (this.options.port === true) {
this.options.port = 3000;
Expand Down
17 changes: 14 additions & 3 deletions packages/faas-cli-plugin-invoke/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export * from './utils';

export class FaaSInvokePlugin extends BasePlugin {
baseDir: string;
buildDir: string;
buildDir: string = resolve(this.core.config.servicePath, '.faas_debug_tmp');
invokeFun: any;
codeAnalyzeResult: AnalyzeResult;
skipTsBuild: boolean;
Expand Down Expand Up @@ -123,16 +123,27 @@ export class FaaSInvokePlugin extends BasePlugin {
if (this.options.incremental) {
this.options.clean = false;
}
if (this.options.clean !== false) {
if (this.options.clean !== false && this.options.clean !== 'false') {
this.options.clean = true;
}

const envClean = process.env.MIDWAY_LOCAL_CLEAN;
if (envClean === 'true') {
this.options.clean = true;
this.options.incremental = false;
} else if (envClean === 'false') {
this.options.clean = false;
}

if (this.options.clean) {
cleanTarget(this.buildDir);
}

this.setStore('defaultTmpFaaSOut', this.defaultTmpFaaSOut);
}

async locator() {
this.baseDir = this.core.config.servicePath;
this.buildDir = resolve(this.baseDir, '.faas_debug_tmp');
const lockKey = `codeAnalyzeResult:${this.baseDir}`;
const { lockType, lockData } = getLock(lockKey);
let codeAnalyzeResult;
Expand Down
7 changes: 0 additions & 7 deletions packages/faas-cli/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
'use strict';
const { debugWrapper } = require('@midwayjs/debugger');
const { existsSync, remove } = require('fs-extra');
const { resolve } = require('path');
const cliFun = async argv => {
require('source-map-support/register');
const { CLI } = require('../dist');
const buildDirectionPath = resolve(process.cwd(), '.faas_debug_tmp');
if (existsSync(buildDirectionPath)) {
await remove(buildDirectionPath);
}

const cli = new CLI(argv);
cli
.start()
Expand Down
10 changes: 0 additions & 10 deletions packages/faas-dev-pack/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { invoke } from '@midwayjs/serverless-invoke';
import { resolve } from 'path';
import { existsSync, removeSync } from 'fs-extra';
export function resolveModule(gatewayName: string) {
const gatewayJSON = require('../gateway.json');
if (gatewayJSON[gatewayName]) {
Expand All @@ -11,14 +9,6 @@ export function resolveModule(gatewayName: string) {
}

export async function invokeFunction(options) {
if (!process.env.MIDWAY_DEV_PACK_RUNNING) {
const baseDir = options.functionDir || process.cwd();
const buildDir = resolve(baseDir, '.faas_debug_tmp');
if (existsSync(buildDir)) {
removeSync(buildDir);
}
process.env.MIDWAY_DEV_PACK_RUNNING = 'true';
}
options.incremental = options.incremental ?? true;
return invoke(options);
}