Skip to content

Commit

Permalink
chore: JSON 输出时自动格式化,确保可读性 (#563)
Browse files Browse the repository at this point in the history
* chore: JSON 输出时自动格式化,确保可读性

* fix: lint
  • Loading branch information
Lxxyx authored Jul 27, 2020
1 parent e91983e commit d9ee485
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions packages/faas-cli-plugin-invoke/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class FaaSInvokePlugin extends BasePlugin {
this.setStore('functions', this.core.service.functions);
writeFileSync(
this.analysisCodeInfoPath,
JSON.stringify(newSpec.functions)
JSON.stringify(newSpec.functions, null, 2)
);
}
if (this.core.pluginManager.options.stopLifecycle === 'invoke:compile') {
Expand Down Expand Up @@ -342,7 +342,10 @@ export class FaaSInvokePlugin extends BasePlugin {
}
});
ensureFileSync(this.buildLockPath);
writeFileSync(this.buildLockPath, JSON.stringify(this.fileChanges));
writeFileSync(
this.buildLockPath,
JSON.stringify(this.fileChanges, null, 2)
);
}

async setFunctionList() {
Expand All @@ -351,7 +354,7 @@ export class FaaSInvokePlugin extends BasePlugin {
// 将函数信息放入代码分析结果缓存中,便于下次跳过ts编译时使用
writeFileSync(
this.analysisCodeInfoPath,
JSON.stringify(this.core.service.functions)
JSON.stringify(this.core.service.functions, null, 2)
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/faas-cli-plugin-package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class PackagePlugin extends BasePlugin {
pkgJson.dependencies[depName] = depVersion;
}
}
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, ' '));
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
await this.npmInstall({
production: true,
});
Expand Down
8 changes: 4 additions & 4 deletions packages/serverless-spec-builder/wrapper.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const initializeMethod = async (initializeContext = {}) => {
layers: [<%= layers.join(", ") %>],
getHandler: getHandler
});
starter = new <%=faasStarterName %>({ baseDir: __dirname, initializeContext, applicationAdapter: runtime, middleware: <%-JSON.stringify(middleware)%> });
starter = new <%=faasStarterName %>({ baseDir: __dirname, initializeContext, applicationAdapter: runtime, middleware: <%-JSON.stringify(middleware, null, 2)%> });
<% loadDirectory.forEach(function(dirName){ %>
starter.loader.loadDirectory({ baseDir: '<%=dirName%>'});<% }) %>
<% if (functionMap) { %>
registerFunctionToIocByConfig(<%-JSON.stringify(functionMap)%>, {
registerFunctionToIocByConfig(<%-JSON.stringify(functionMap, null, 2)%>, {
baseDir: join(__dirname, 'dist'),
context: starter.loader.getApplicationContext()
});
Expand All @@ -46,7 +46,7 @@ const getHandler = (hanlderName) => {
return <% if (handlerData.handler) {
%> starter.handleInvokeWrapper('<%=handlerData.handler%>'); <% } else {
%> async (ctx) => {
const allHandlers = <%-JSON.stringify(handlerData.handlers)%>;
const allHandlers = <%-JSON.stringify(handlerData.handlers, null, 2)%>;
let handler = null;
let ctxPath = ctx && ctx.path || '';
if (ctxPath) {
Expand Down Expand Up @@ -100,4 +100,4 @@ exports.<%=handlerData.name%> = asyncWrapper(async (...args) => {
const handler = getHandler('<%=handlerData.name%>');
return runtime.asyncEvent(handler)(...args);
});
<% }); %>
<% }); %>

0 comments on commit d9ee485

Please sign in to comment.