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: fix windows word when output #591

Merged
merged 8 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/faas-cli-command-core/src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function installNpm(options: INpmInstallOptions) {
slience,
registerPath,
} = options;
const cmd = `${baseDir ? `cd ${baseDir};` : ''}${register} i ${npmName}${
const cmd = `${baseDir ? `cd ${baseDir} && ` : ''}${register} i ${npmName}${
mode ? ` --${mode}` : ' --no-save'
}${registerPath ? ` --registry=${registerPath}` : ''}`;

Expand Down
25 changes: 15 additions & 10 deletions packages/faas-cli-plugin-package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ export class PackagePlugin extends BasePlugin {
this.core.cli.log(` - BaseDir: ${this.servicePath}`);
this.core.cli.log(' - AnalyzeResult');
this.core.cli.log(
` ProjectType: ${this.codeAnalyzeResult.projectType}`
` - ProjectType: ${this.codeAnalyzeResult.projectType}`
);
if (this.codeAnalyzeResult.midwayRoot) {
// 输出 midway-* 项目根路径
this.core.cli.log(
` MidwayRoot: ${
` - MidwayRoot: ${
this.servicePath === this.codeAnalyzeResult.midwayRoot
? '.'
: relative(this.servicePath, this.codeAnalyzeResult.midwayRoot)
}`
);
// 输出 ts 代码根路径
this.core.cli.log(
` TSCodeRoot: ${relative(
` - TSCodeRoot: ${relative(
this.servicePath,
this.codeAnalyzeResult.tsCodeRoot
)}`
Expand All @@ -175,15 +175,15 @@ export class PackagePlugin extends BasePlugin {
);
if (this.codeAnalyzeResult.integrationProject) {
this.core.cli.log(
` TSBuildTemporaryRoot: ${this.integrationDistTempDirectory}`
` - TSBuildTemporaryRoot: ${this.integrationDistTempDirectory}`
);
await remove(join(this.servicePath, this.integrationDistTempDirectory));
} else {
this.core.cli.log(' TSBuildTemporaryRoot: dist');
this.core.cli.log(' - TSBuildTemporaryRoot: dist');
}
// 输出构建产物根路径
this.core.cli.log(
` PackageRoot: ${relative(this.servicePath, this.midwayBuildPath)}`
` - PackageRoot: ${relative(this.servicePath, this.midwayBuildPath)}`
);
}
await remove(this.midwayBuildPath);
Expand Down Expand Up @@ -215,7 +215,7 @@ export class PackagePlugin extends BasePlugin {
),
exclude: packageObj.exclude,
log: path => {
this.core.cli.log(` Copy ${path}`);
this.core.cli.log(` - Copy ${path}`);
},
});
if (this.codeAnalyzeResult.integrationProject) {
Expand Down Expand Up @@ -361,14 +361,14 @@ export class PackagePlugin extends BasePlugin {

async emit() {
const isTsDir = existsSync(join(this.servicePath, 'tsconfig.json'));
this.core.cli.log('Building Midway FaaS directory files...');
this.core.cli.log('Building project directory files...');
if (!isTsDir) {
this.core.cli.log(' - Not found tsconfig.json and skip build');
return;
}
this.core.cli.log(' - Using tradition build mode');
this.program.emit();
this.core.cli.log(' - Build Midway FaaS complete');
this.core.cli.log(' - Build project complete');
}

// 生成默认入口
Expand Down Expand Up @@ -648,8 +648,10 @@ export class PackagePlugin extends BasePlugin {
defaultBeforeGenerateSpec() {
const service: any = this.core.service;
if (service?.deployType) {
this.core.cli.log(` - found deployType: ${service?.deployType}`);
// add default function
if (!service.functions) {
if (!service.functions || Object.keys(service.functions).length === 0) {
this.core.cli.log(` - create default functions`);
service.functions = {
app_index: {
handler: 'index.handler',
Expand All @@ -663,16 +665,19 @@ export class PackagePlugin extends BasePlugin {
}

if (service?.deployType === 'egg') {
this.core.cli.log(` - create default layer: egg`);
service.layers['eggLayer'] = { path: 'npm:@midwayjs/egg-layer' };
}

if (service?.deployType === 'express') {
this.core.cli.log(` - create default layer: express`);
service.layers['expressLayer'] = {
path: 'npm:@midwayjs/express-layer',
};
}

if (service?.deployType === 'koa') {
this.core.cli.log(` - create default layer: koa`);
service.layers['koaLayer'] = { path: 'npm:@midwayjs/koa-layer' };
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/faas-cli-plugin-package/test/package-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { resolve, join } from 'path';
import { existsSync, remove, readFileSync } from 'fs-extra';
import * as assert from 'assert';

describe('/test/package-a[[.test.ts', () => {
import { AliyunFCPlugin } from '../../faas-cli-plugin-fc';

describe.only('/test/package-a[[.test.ts', () => {
describe('package application layer project', () => {
const baseDir = resolve(__dirname, './fixtures/app-layer');

Expand All @@ -25,12 +27,14 @@ describe('/test/package-a[[.test.ts', () => {
log: console,
});
core.addPlugin(PackagePlugin);
core.addPlugin(AliyunFCPlugin);
await core.ready();
await core.invoke(['package']);
const buildPath = join(baseDir, '.serverless');
assert(existsSync(join(buildPath, 'f.yml')));
assert(existsSync(join(buildPath, 'app')));
assert(existsSync(join(buildPath, 'config')));
assert(existsSync(join(buildPath, 'index.js')));
assert(
/npm:@midwayjs\/egg-layer/.test(
readFileSync(join(buildPath, 'f.yml')).toString('utf8')
Expand Down
3 changes: 3 additions & 0 deletions packages/serverless-spec-builder/src/fc/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ function convertMethods(methods: string | string[]): HTTPEventType[] {
}

methods = [methods];
} else if (methods?.length) {
// has value
} else {
// empty
return ['GET', 'PUT', 'POST', 'DELETE', 'HEAD'];
}

Expand Down
17 changes: 17 additions & 0 deletions packages/serverless-spec-builder/test/fc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe('/test/fc.test.ts', () => {
Type: 'HTTP',
},
});

// third function
const funResult3 = result['Resources']['serverless-hello-world']['index3'];
assert(funResult3['Type'] === 'Aliyun::Serverless::Function');
assert(funResult3['Properties']['Initializer'] === 'index.initializer');
assert(funResult3['Properties']['Handler'] === 'index.handler');
assert(funResult3['Properties']['Runtime'] === 'nodejs10');

assert.deepStrictEqual(funResult3['Events'], {
'http-index3': {
Properties: {
AuthType: 'ANONYMOUS',
Methods: ['GET', 'POST'],
},
Type: 'HTTP',
},
});
});

it('test http events no method', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ functions:
role: 'acs:ram::1234567890:role/fc-invoke-test'
version: LATEST

index3:
handler: index.handler
events:
- http:
method:
- get
- post
path: /

package:
artifact: code.zip
124 changes: 0 additions & 124 deletions packages/serverless-spec-builder/test/fixtures/wrapper/aggre.js

This file was deleted.

57 changes: 0 additions & 57 deletions packages/serverless-spec-builder/test/fixtures/wrapper/index.js

This file was deleted.