Skip to content

Commit

Permalink
Merge pull request #564 from devsapp/shl/update_core
Browse files Browse the repository at this point in the history
Shl/update core
  • Loading branch information
heimanba authored Jan 4, 2022
2 parents 59ab98c + 3231996 commit 7f660a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"dependencies": {
"@alicloud/fc2": "^2.3.0",
"@serverless-devs/core": "latest",
"@serverless-devs/fc-core": "latest",
"i18n": "^0.13.2",
"inquirer": "^8.1.1",
"js-yaml": "^4.0.0",
"lodash": "^4.17.21",
"rimraf": "^3.0.2",
"tty-table": "^4.1.3"
},
"autoInstall": false,
Expand All @@ -29,6 +29,7 @@
"husky": "^7.0.2",
"jest": "^26.4.0",
"promise-retry": "^2.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.2.0",
"ts-loader": "^8.0.14",
"ts-node": "^9.1.1",
Expand Down
2 changes: 1 addition & 1 deletion publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Component
Name: fc
Provider:
- 阿里云
Version: 0.1.35
Version: dev
Description: 阿里云函数计算基础组件
HomePage: https://github.com/devsapp/fc
Tags:
Expand Down
31 changes: 0 additions & 31 deletions src/common/logger.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
import { Logger } from '@serverless-devs/core';
import os from 'os';
import path from 'path';
import rimraf from 'rimraf';
import { spawnSync } from 'child_process';

export const CONTEXT = 'FC';

const logger = new Logger(CONTEXT);

function getCommand() {
try {
const serverless_devs_temp_argv = JSON.parse(process.env['serverless_devs_temp_argv']);
const command = serverless_devs_temp_argv.slice(2);
return command ? `s ${command.join(' ')}` : undefined;
} catch (error) {}
}

if (typeof logger.task !== 'function') {
const cachePath = path.join(os.homedir(), '.s', 'cache');
rimraf.sync(path.join(cachePath));
try {
spawnSync('npm install @serverless-devs/s -g', { shell: true });
} catch (error) {
try {
spawnSync('yarn global add @serverless-devs/s', { shell: true });
} catch (error) {
logger.warn(
"It is detected that your version is an old version, you can run 'npm install @serverless-devs/s -g' to update",
);
}
}
const msg = getCommand() ? `Please retry again with '${getCommand()}'.` : 'Please retry again.';
logger.log(`\nWARNING\n======================\n* Oops! some problem happen, ${msg}`, 'yellow');
process.exit(1);
}

export default logger;
24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import FcRemoteDebug from './lib/component/fc-remote-debug';
import FcEval from './lib/component/fc-eval';
import { EvalOption } from './lib/interface/component/fc-eval';
import { FcInvokeProps } from './lib/interface/component/fc-remote-invoke';
import path from 'path';
import os from 'os';
import fs from 'fs';

const SUPPORTED_LOCAL_METHOD: string[] = ['invoke', 'start'];
const DEPLOY_SUPPORT_CONFIG_ARGS = ['code', 'config'];
Expand Down Expand Up @@ -926,9 +929,30 @@ https://gitee.com/devsapp/fc/blob/main/docs/zh/command/nas.md#nas-upload-命令\
await this.report(componentName, methodName, inputs?.credentials?.AccountID);
componentInputs.props = props;
componentInputs.args = args;
await this.updateCore();
// const componentIns: any = await core.load(`devsapp/${componentName}`);
const componentIns: any = await core.load(`${componentName}`);
this.logger.debug(`Inputs of component: ${componentName} is: ${JSON.stringify(componentInputs, null, ' ')}`);
return await componentIns[methodName](componentInputs);
}

private async updateCore() {
if(!_.isFunction(core.tableLayout)){
try {
const homePath = _.isFunction(core.getRootHome) ? core.getRootHome() : os.homedir();
const corePath = path.join(homePath, 'cache', 'core');
const lockPath = path.resolve(corePath, '.s.lock');
const result = await core.request('https://registry.devsapp.cn/simple/devsapp/core/releases/latest');
const version = result.tag_name;
const url = `https://registry.devsapp.cn/simple/devsapp/core/zipball/${version}`;
const filename = `core@${version}.zip`;
await core.downloadRequest(url, corePath, { filename, extract: true, strip: 1 });
fs.writeFileSync(lockPath, JSON.stringify({ version }, null, 2));
} catch (error) {
this.logger.log(`\nWARNING\n======================\n* Exception happened! Please execute 's clean --cache' and try again`, 'yellow');
process.exit(1)
}
}
}

}
6 changes: 2 additions & 4 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as core from '@serverless-devs/core';
import _ from 'lodash';

import * as fcCore from '@serverless-devs/fc-core';

export default class Client {
static fcClient: any;

static async setFcClient(region: string, credentials, access: string) {
const fcCommon = await core.loadComponent('devsapp/fc-common');
const fcClient = await fcCommon.makeFcClient({
const fcClient = await fcCore.makeFcClient({
project: { access },
credentials,
props: {
Expand Down

0 comments on commit 7f660a8

Please sign in to comment.