Skip to content

Commit

Permalink
Merge pull request #2426 from alibaba/iceworks/sever-lint
Browse files Browse the repository at this point in the history
feat: lint for iceworks-server
  • Loading branch information
Orange-C authored Jul 15, 2019
2 parents ee197e8 + 60756d6 commit 6581d84
Show file tree
Hide file tree
Showing 48 changed files with 263 additions and 260 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
test/
tests/
node_modules/
dist/

# node 覆盖率文件
coverage/
Expand Down Expand Up @@ -33,5 +34,4 @@ packages/iceworks-scaffolder
tools/iceworks
tools/iceworks-cli
tools/ice-devtools
packages/iceworks-client
packages/iceworks-server
packages/iceworks-client
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { eslintTS, deepmerge } = require('@ice/spec');

module.exports = deepmerge(eslintTS, {
rules: {
// 禁止用var引入模块:取消
"@typescript-eslint/no-var-requires": 0
"@typescript-eslint/no-var-requires": 0,
"class-methods-use-this": 1,
}
});
4 changes: 2 additions & 2 deletions packages/iceworks-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import RemoteLogger from './lib/remoteLogger';

export default class AppBootHook {
app: any;
public app: any;

constructor(app) {
this.app = app;
}

async didLoad() {
public async didLoad() {
// send server log to remote in production
if (this.app.config.env === 'prod') {
this.app.getLogger().set('remote', new RemoteLogger({ level: 'INFO' }));
Expand Down
60 changes: 30 additions & 30 deletions packages/iceworks-server/src/app/controller/goldlog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ import * as rp from 'request';
@controller('/api/goldlog')
export class GoldlogController {

@post('/record')
async record(ctx) {
if (ctx.request.body) {
const data = ctx.request.body;
const dataKeyArray = Object.keys(data);
const gokey = dataKeyArray.reduce((finnalStr, currentKey, index) => {
const currentData =
@post('/record')
public async record(ctx) {
if (ctx.request.body) {
const data = ctx.request.body;
const dataKeyArray = Object.keys(data);
const gokey = dataKeyArray.reduce((finnalStr, currentKey, index) => {
const currentData =
typeof data[currentKey] === 'string'
? data[currentKey]
: JSON.stringify(data[currentKey]);
return `${finnalStr}${currentKey}=${currentData}${
dataKeyArray.length - 1 === index ? '' : '&'
}`;
}, '');
return `${finnalStr}${currentKey}=${currentData}${
dataKeyArray.length - 1 === index ? '' : '&'
}`;
}, '');

await rp({
method: 'post',
url: 'http://gm.mmstat.com/iceteam.iceworks.log3',
data: {
cache: Math.random(),
gmkey: 'CLK',
gokey: encodeURIComponent(gokey),
logtype: '2',
},
});
ctx.body = {
success: true
};
} else {
ctx.body = {
success: false,
};
}
await rp({
method: 'post',
url: 'http://gm.mmstat.com/iceteam.iceworks.log3',
data: {
cache: Math.random(),
gmkey: 'CLK',
gokey: encodeURIComponent(gokey),
logtype: '2',
},
});
ctx.body = {
success: true,
};
} else {
ctx.body = {
success: false,
};
}
};
}
};
2 changes: 1 addition & 1 deletion packages/iceworks-server/src/app/controller/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { controller, get, provide } from 'midway';
export class HomeController {

@get('*')
async render(ctx) {
public async render(ctx) {
await ctx.render('index.html');
await ctx.render('index.html', ctx.clientConfig);
}
Expand Down
18 changes: 9 additions & 9 deletions packages/iceworks-server/src/app/io/controller/home/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ export default (app) => {
const { Controller } = app;

return class ProjectController extends Controller {
async list() {
public async list() {
const { projectManager } = app;
const projects = await projectManager.getProjects();
return projects.map((project) => project.toJSON());
}

async create(ctx) {
public async create(ctx) {
const { projectManager } = app;
const { args } = ctx;

await projectManager.createProject(args);
}

async delete(ctx) {
public async delete(ctx) {
const { projectManager } = app;
const { args } = ctx;

await projectManager.deleteProject(args);
}

async add(ctx) {
public async add(ctx) {
const { projectManager } = app;
const { args } = ctx;
const { projectPath } = args;
await projectManager.addProject(projectPath);
}

async getCurrent() {
public async getCurrent() {
const { projectManager } = app;
const project = await projectManager.getCurrent();

return project.toJSON();
}

async setCurrent(ctx) {
public async setCurrent(ctx) {
const { projectManager } = app;
const { args } = ctx;
const { path } = args;
Expand All @@ -45,21 +45,21 @@ export default (app) => {
return project.toJSON();
}

async setPanel(ctx) {
public async setPanel(ctx) {
const { args } = ctx;
const { projectManager } = app;
const project = await projectManager.getCurrent();
return project.setPanel(args);
}

async sortPanels(ctx) {
public async sortPanels(ctx) {
const { args } = ctx;
const { projectManager } = app;
const project = await projectManager.getCurrent();
return project.sortPanels(args);
}

async reloadAdapter() {
public async reloadAdapter() {
const { projectManager, i18n } = app;
const project = await projectManager.getCurrent();
const result = await project.reloadAdapter(i18n);
Expand Down
20 changes: 10 additions & 10 deletions packages/iceworks-server/src/app/io/controller/home/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default (app) => {
const { Controller, i18n } = app;

return class HomeController extends Controller {
async getWorkFolder() {
public async getWorkFolder() {
const workFolder = storage.get('workFolder');
const directories = await scanDirectory(workFolder);
return {
Expand All @@ -16,7 +16,7 @@ export default (app) => {
};
}

async setWorkFolder(ctx) {
public async setWorkFolder(ctx) {
const { args } = ctx;
const { path: setPath } = args;

Expand All @@ -31,7 +31,7 @@ export default (app) => {
};
}

async setLocale(ctx) {
public async setLocale(ctx) {
const { projectManager, i18n } = app;
const project = await projectManager.getCurrent();

Expand All @@ -40,27 +40,27 @@ export default (app) => {
storage.set('locale', ctx.args.locale);
}

async getLocale() {
public async getLocale() {
return storage.get('locale');
}

async setTheme(ctx) {
public async setTheme(ctx) {
storage.set('theme', ctx.args.theme);
}

async getTheme() {
public async getTheme() {
return storage.get('theme');
}

async setEditor(ctx) {
public async setEditor(ctx) {
storage.set('editor', ctx.args.editor);
}

async getEditor() {
public async getEditor() {
return storage.get('editor');
}

async setUser({ args }) {
public async setUser({ args }) {
const { name, workId, avatarUrl } = args;
if (workId && name && avatarUrl) {
storage.set('user', { name, workId, avatarUrl, isLogin: true });
Expand All @@ -71,7 +71,7 @@ export default (app) => {
return storage.get('user');
}

async getUser() {
public async getUser() {
return storage.get('user');
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/iceworks-server/src/app/io/controller/home/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export default (app) => {

// System capability
return class SystemController extends Controller {
async getPath({ args }) {
public async getPath({ args }) {
return path.join(...args);
}

async openFolder(ctx) {
public async openFolder(ctx) {
const { args: { path } } = ctx;
return await openFolder(path);
}

openEditor(ctx) {
public openEditor(ctx) {
const { args: { path }, logger, socket } = ctx;
const editor = storage.get('editor');
logger.info('open editor:', path, editor);
Expand Down
14 changes: 7 additions & 7 deletions packages/iceworks-server/src/app/io/controller/material/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CATEGORY_ALL = '全部';

export default (app) => {
return class MaterialController extends app.Controller {
async getResources({ args }) {
public async getResources({ args }) {
const resources = storage.get('material');

if (args && args.type) {
Expand All @@ -22,7 +22,7 @@ export default (app) => {
return resources;
}

async getOne(ctx) {
public async getOne(ctx) {
const { args: { url }, logger } = ctx;

logger.info(`get material by url, url: ${url}`);
Expand Down Expand Up @@ -64,13 +64,13 @@ export default (app) => {
return {...formatMaterialData(data), name: currentItem.name };
}

async getRecommendScaffolds() {
public async getRecommendScaffolds() {
const material = storage.get('material')[0];
const { scaffolds = [] } = await request(material.source);
return scaffolds.filter(({ name }) => RECOMMEND_SCAFFOLDS.includes(name));
}

async add(ctx) {
public async add(ctx) {
const { args: { url, name }, logger } = ctx;
const allMaterials = storage.get('material');
const existed = allMaterials.some(m => m.source === url);
Expand All @@ -97,7 +97,7 @@ export default (app) => {

const material = storage.get('material');
const currentItem = {
official: false, name, description, homepage, logo, type, source
official: false, name, description, homepage, logo, type, source,
};
const newMaterials = material.filter((item) => item.name !== currentItem.name);
newMaterials.unshift(currentItem)
Expand All @@ -108,7 +108,7 @@ export default (app) => {
return { resource: storage.get('material'), current: { ...materialData, name } };
}

async delete(ctx) {
public async delete(ctx) {
const { args: { url }, logger } = ctx;
logger.info(`delete material, source URL: ${url}`);

Expand Down Expand Up @@ -199,6 +199,6 @@ const updateArrayItem = (array, item, itemIdx) => {
return [
...array.slice(0, itemIdx),
item,
...array.slice(itemIdx + 1)
...array.slice(itemIdx + 1),
];
};
4 changes: 2 additions & 2 deletions packages/iceworks-server/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export = (appInfo: any) => {
const config: any = (exports = {});
const config: any = {};

// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1555062042825_9790';
config.keys = `${appInfo.name }_1555062042825_9790`;

// middleware config
config.middleware = ['client'];
Expand Down
2 changes: 1 addition & 1 deletion packages/iceworks-server/src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export = {
i18n: {
enable: true,
path: path.join(__dirname, '../lib/plugin/i18n'),
}
},
};
6 changes: 3 additions & 3 deletions packages/iceworks-server/src/interface/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ export interface IDependencyModule extends IBaseModule {
/**
* 获取项目内的依赖
*/
getAll(): Promise<{ dependencies: IDependency[], devDependencies: IDependency[] }>;
getAll(): Promise<{ dependencies: IDependency[]; devDependencies: IDependency[] }>;

/**
* 添加依赖到项目
*
* @param dependency 依赖信息
*/
create(params: {dependency: ICreateDependencyParam, isDev?: boolean; }, ctx: IContext): Promise<void>;
create(params: {dependency: ICreateDependencyParam; isDev?: boolean }, ctx: IContext): Promise<void>;

/**
* 添加多个依赖到项目
*
* @param dependencies 依赖列表
*/
bulkCreate(params: {dependencies: ICreateDependencyParam[], isDev?: boolean; }, ctx: IContext): Promise<void>;
bulkCreate(params: {dependencies: ICreateDependencyParam[]; isDev?: boolean }, ctx: IContext): Promise<void>;

/**
* 重装依赖
Expand Down
2 changes: 1 addition & 1 deletion packages/iceworks-server/src/interface/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ export interface IMenuModule extends IBaseModule {
/**
* bulk create menus
*/
bulkCreate(params: {data: IMenu[], options: IMenuOptions}): Promise<void>;
bulkCreate(params: {data: IMenu[]; options: IMenuOptions}): Promise<void>;
}
Loading

0 comments on commit 6581d84

Please # to comment.