ko 5.2.1 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -128
- package/lib/actions/build.js +74 -0
- package/lib/actions/creator.js +42 -0
- package/lib/actions/dev.js +110 -0
- package/lib/cli.js +41 -0
- package/lib/interfaces.js +2 -0
- package/lib/utils/config.js +42 -0
- package/lib/utils/config.test.js +30 -0
- package/lib/webpack/index.js +55 -0
- package/lib/webpack/loaders/asset.js +19 -0
- package/lib/webpack/loaders/index.js +12 -0
- package/lib/webpack/loaders/script.js +59 -0
- package/lib/webpack/loaders/style.js +72 -0
- package/lib/webpack/plugins.js +61 -0
- package/package.json +43 -85
- package/{preinstall.js → scripts/preinstall.js} +6 -5
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -96
- package/.github/workflows/auto-publish.yml +0 -32
- package/.github/workflows/ci.yml +0 -67
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -5
- package/CHANGELOG.md +0 -115
- package/bin/ko-build.js +0 -30
- package/bin/ko-create.js +0 -14
- package/bin/ko-dev.js +0 -31
- package/bin/ko-init.js +0 -14
- package/bin/ko-install.js +0 -27
- package/bin/ko-lint.js +0 -18
- package/bin/ko-move.js +0 -14
- package/bin/ko-preview.js +0 -27
- package/bin/ko-swagger.js +0 -41
- package/bin/ko.js +0 -29
- package/commitlint.config.js +0 -7
- package/config/defaultPaths.js +0 -26
- package/config/lint/getEslintConf.js +0 -23
- package/config/lint/getPrettierConf.js +0 -14
- package/config/lint/index.js +0 -14
- package/config/webpack/base.js +0 -77
- package/config/webpack/devServer.js +0 -39
- package/config/webpack/index.js +0 -63
- package/config/webpack/loaders.js +0 -142
- package/config/webpack/plugins.js +0 -70
- package/constants/default.js +0 -7
- package/constants/env.js +0 -7
- package/jest.config.js +0 -44
- package/prettier.config.js +0 -8
- package/script/build.js +0 -23
- package/script/create.js +0 -31
- package/script/dev.js +0 -96
- package/script/init.js +0 -129
- package/script/install.js +0 -91
- package/script/lint.js +0 -24
- package/script/move.js +0 -38
- package/script/preview.js +0 -22
- package/script/swagger.js +0 -239
- package/template/index.html +0 -0
- package/template/pageTemplate.mustache +0 -21
- package/template/pageTemplateTS.mustache +0 -29
- package/template/restful.hbs +0 -14
- package/template/restfulTemplate.mustache +0 -12
- package/template/routerConfTemplate.mustache +0 -15
- package/template/styleTemplate.mustache +0 -3
- package/template/tsconfig.json +0 -22
- package/util/__tests__/file.test.js +0 -16
- package/util/__tests__/fileService.test.js +0 -101
- package/util/__tests__/index.test.js +0 -51
- package/util/__tests__/userConfig.test.js +0 -83
- package/util/__tests__/verifyHtml.test.js +0 -81
- package/util/createComp.js +0 -71
- package/util/createPage.js +0 -141
- package/util/defaultData.js +0 -64
- package/util/file.js +0 -9
- package/util/fileService.js +0 -55
- package/util/index.js +0 -25
- package/util/prepareUrl.js +0 -69
- package/util/program.js +0 -20
- package/util/request.js +0 -18
- package/util/stdout.js +0 -36
- package/util/userConfig.js +0 -40
- package/util/verifyHtml.js +0 -63
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
const { appPublic } = require('../../config/defaultPaths');
|
|
2
|
-
const verifyHtml = require('../verifyHtml');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
|
|
6
|
-
const txt = `<!DOCTYPE html>
|
|
7
|
-
<html>
|
|
8
|
-
<head>
|
|
9
|
-
<meta charset="utf-8" />
|
|
10
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
11
|
-
<title>page</title>
|
|
12
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
13
|
-
<%= htmlWebpackPlugin.options.assets.config %>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<div id='root'></div><div class="dll">
|
|
17
|
-
<%= htmlWebpackPlugin.options.assets.scripts %>
|
|
18
|
-
</div>
|
|
19
|
-
</body>
|
|
20
|
-
</html>
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
const workspace = process.cwd();
|
|
24
|
-
const filename = 'index.html';
|
|
25
|
-
const completePath = path.resolve(appPublic, filename);
|
|
26
|
-
const errorTestingFileNotPrepared = new Error(
|
|
27
|
-
'testing file is not prepared...'
|
|
28
|
-
);
|
|
29
|
-
const regConfig = /<%= htmlWebpackPlugin.options.assets.config %>/g;
|
|
30
|
-
const regScripts = /<%= htmlWebpackPlugin.options.assets.scripts %>/g;
|
|
31
|
-
|
|
32
|
-
describe('verify html:', () => {
|
|
33
|
-
it('whithout directory:', () => {
|
|
34
|
-
expect(appPublic).toBe(path.resolve(workspace, 'public'));
|
|
35
|
-
verifyHtml(completePath);
|
|
36
|
-
expect(fs.existsSync(appPublic)).toBe(true);
|
|
37
|
-
expect(fs.existsSync(completePath)).toBe(true);
|
|
38
|
-
const content = fs.readFileSync(completePath).toString();
|
|
39
|
-
expect(content.replace(/\s/g, '')).toBe(txt.replace(/\s/g, ''));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('with directory:', () => {
|
|
43
|
-
expect(appPublic).toBe(path.resolve(workspace, 'public'));
|
|
44
|
-
fs.mkdirSync(path.resolve(workspace, 'public'));
|
|
45
|
-
if (!fs.existsSync(appPublic)) throw errorTestingFileNotPrepared;
|
|
46
|
-
verifyHtml(completePath);
|
|
47
|
-
expect(fs.existsSync(appPublic)).toBe(true);
|
|
48
|
-
expect(fs.existsSync(completePath)).toBe(true);
|
|
49
|
-
const content = fs.readFileSync(completePath).toString();
|
|
50
|
-
expect(content.replace(/\s/g, '')).toBe(txt.replace(/\s/g, ''));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('without scripts:', () => {
|
|
54
|
-
const filterText = txt.replace(regScripts, '');
|
|
55
|
-
expect(filterText).not.toMatch(regScripts);
|
|
56
|
-
fs.mkdirSync(appPublic);
|
|
57
|
-
fs.writeFileSync(completePath, filterText);
|
|
58
|
-
if (!fs.existsSync(completePath)) throw errorTestingFileNotPrepared;
|
|
59
|
-
verifyHtml(completePath);
|
|
60
|
-
const content = fs.readFileSync(completePath).toString();
|
|
61
|
-
expect(content).toMatch(regConfig);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('without config:', () => {
|
|
65
|
-
const filterText = txt.replace(regConfig, '');
|
|
66
|
-
expect(filterText).not.toMatch(regConfig);
|
|
67
|
-
fs.mkdirSync(appPublic);
|
|
68
|
-
fs.writeFileSync(completePath, filterText);
|
|
69
|
-
if (!fs.existsSync(completePath)) throw errorTestingFileNotPrepared;
|
|
70
|
-
verifyHtml(completePath);
|
|
71
|
-
const content = fs.readFileSync(completePath).toString();
|
|
72
|
-
expect(content).toMatch(regScripts);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
afterEach(() => {
|
|
76
|
-
if (fs.existsSync(completePath))
|
|
77
|
-
fs.rmdirSync(appPublic, {
|
|
78
|
-
recursive: true,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
package/util/createComp.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const PAGE_TEMPLATE_PATH = '../template/pageTemplate.mustache';
|
|
2
|
-
const PAGE_TS_TEMPLATE_PATH = '../template/pageTemplateTS.mustache';
|
|
3
|
-
const STYLE_TEMPLATE_PATH = '../template/styleTemplate.mustache';
|
|
4
|
-
const INDEX_TS_N = 'index.tsx';
|
|
5
|
-
const INDEX_N = 'index.js';
|
|
6
|
-
const STYLE_N = 'style.scss';
|
|
7
|
-
|
|
8
|
-
const Colors = require('colors');
|
|
9
|
-
const Log = console.log;
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const Mustache = require('mustache');
|
|
12
|
-
const Path = require('path');
|
|
13
|
-
|
|
14
|
-
const { existsSync, mkdir } = require('./fileService');
|
|
15
|
-
|
|
16
|
-
function toLine(str) {
|
|
17
|
-
// 大驼峰转连字符 loginIn -> login-in
|
|
18
|
-
let temp = str.replace(/[A-Z]/g, function (match) {
|
|
19
|
-
return '-' + match.toLowerCase();
|
|
20
|
-
});
|
|
21
|
-
if (temp.slice(0, 1) === '-') {
|
|
22
|
-
temp = temp.slice(1);
|
|
23
|
-
}
|
|
24
|
-
return temp;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function toCamel(str) {
|
|
28
|
-
// 大驼峰转小驼峰 首字母转为小写
|
|
29
|
-
return str[0].toLowerCase() + str.substring(1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function writerFile(filePath, renderString) {
|
|
33
|
-
fs.writeFile(filePath, renderString, function (err) {
|
|
34
|
-
if (err) Log(Colors.red('生成操作失败'));
|
|
35
|
-
else Log(Colors.green(`生成操作成功,生成目录: ${filePath} `));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/* 渲染获取字符串 */
|
|
40
|
-
function renderMustache(path, data) {
|
|
41
|
-
const temp = fs.readFileSync(require.resolve(path), 'utf-8').toString();
|
|
42
|
-
const renderString = Mustache.render(temp, data);
|
|
43
|
-
return renderString;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = (compName, compPath, isTs) => {
|
|
47
|
-
const folderName = toCamel(compName); // 文件夹名称
|
|
48
|
-
const className = toLine(compName); // 类名
|
|
49
|
-
const folderPath = `${compPath}/${folderName}`;
|
|
50
|
-
const folderExist = existsSync(folderPath); // 文件夹是否存在
|
|
51
|
-
if (folderExist) {
|
|
52
|
-
Log(Colors.red(`指定路径下组件已存在,请重新输入组件名`));
|
|
53
|
-
} else {
|
|
54
|
-
mkdir(folderPath);
|
|
55
|
-
const indexContent = renderMustache(
|
|
56
|
-
isTs == 'y' ? PAGE_TS_TEMPLATE_PATH : PAGE_TEMPLATE_PATH,
|
|
57
|
-
{
|
|
58
|
-
name: compName,
|
|
59
|
-
className,
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
const styleContent = renderMustache(STYLE_TEMPLATE_PATH, {
|
|
63
|
-
className,
|
|
64
|
-
});
|
|
65
|
-
writerFile(
|
|
66
|
-
Path.join(folderPath, isTs == 'y' ? INDEX_TS_N : INDEX_N),
|
|
67
|
-
indexContent
|
|
68
|
-
);
|
|
69
|
-
writerFile(Path.join(folderPath, STYLE_N), styleContent);
|
|
70
|
-
}
|
|
71
|
-
};
|
package/util/createPage.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
const PAGE_TEMPLATE_PATH = '../template/pageTemplate.mustache';
|
|
2
|
-
const STYLE_TEMPLATE_PATH = '../template/styleTemplate.mustache';
|
|
3
|
-
const ROUTERTC_TEMPLATE_PATH = '../template/routerConfTemplate.mustache';
|
|
4
|
-
const INDEX_N = 'index.js';
|
|
5
|
-
const STYLE_N = 'style.scss';
|
|
6
|
-
const ROUTERTC_N = 'routerConf.js';
|
|
7
|
-
|
|
8
|
-
const ROUTERTC_N_TS = 'routerConf.tsx';
|
|
9
|
-
const INDEX_TS_N = 'index.tsx';
|
|
10
|
-
const PAGE_TS_TEMPLATE_PATH = '../template/pageTemplateTS.mustache';
|
|
11
|
-
|
|
12
|
-
const Colors = require('colors');
|
|
13
|
-
const Log = console.log;
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
const Mustache = require('mustache');
|
|
16
|
-
const Path = require('path');
|
|
17
|
-
const _ = require('lodash');
|
|
18
|
-
|
|
19
|
-
const { resolveApp } = require('../config/defaultPaths');
|
|
20
|
-
const { existsSync, mkdir, readFileSync } = require('./fileService');
|
|
21
|
-
|
|
22
|
-
function toLine(str) {
|
|
23
|
-
// 大驼峰转连字符 loginIn -> login-in
|
|
24
|
-
let temp = str.replace(/[A-Z]/g, function (match) {
|
|
25
|
-
return '-' + match.toLowerCase();
|
|
26
|
-
});
|
|
27
|
-
if (temp.slice(0, 1) === '-') {
|
|
28
|
-
temp = temp.slice(1);
|
|
29
|
-
}
|
|
30
|
-
return temp;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function toCamel(str) {
|
|
34
|
-
// 大驼峰转小驼峰 首字母转为小写
|
|
35
|
-
return str[0].toLowerCase() + str.substring(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function writerFile(filePath, renderString) {
|
|
39
|
-
// 生成指定文件并填入内容
|
|
40
|
-
fs.writeFile(filePath, renderString, function (err) {
|
|
41
|
-
if (err) Log(Colors.red('生成操作失败'));
|
|
42
|
-
else Log(Colors.green(`生成操作成功,生成目录: ${filePath} `));
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function renderMustache(path, data) {
|
|
47
|
-
// 渲染获取字符串
|
|
48
|
-
const temp = fs.readFileSync(require.resolve(path), 'utf-8').toString();
|
|
49
|
-
const renderString = Mustache.render(temp, data);
|
|
50
|
-
return renderString;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function parseString(str) {
|
|
54
|
-
// 解析文件内已有字符串
|
|
55
|
-
const tempArr = str.trim().split('const routerConf = [');
|
|
56
|
-
const importedPks = tempArr[0].split('\n');
|
|
57
|
-
const importPackages = importedPks.filter((str) => {
|
|
58
|
-
return str != '';
|
|
59
|
-
});
|
|
60
|
-
// let initReg=/{(\n*.*)+}/g;
|
|
61
|
-
// let initStr=tempArr[1].match(initReg)[0];
|
|
62
|
-
const index = tempArr[1].indexOf('];');
|
|
63
|
-
const initStr = tempArr[1].substring(0, index + 1);
|
|
64
|
-
return {
|
|
65
|
-
initStr,
|
|
66
|
-
importPackages,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function mergeRouterCData(path, newData) {
|
|
71
|
-
// 合并新旧数据
|
|
72
|
-
const fileData = null;
|
|
73
|
-
if (existsSync(path)) {
|
|
74
|
-
let fileContent = readFileSync(path);
|
|
75
|
-
console.time('test');
|
|
76
|
-
fileContent = parseString(fileContent);
|
|
77
|
-
console.timeEnd('test');
|
|
78
|
-
newData.initRoutConf = fileContent.initStr; // importPackages: importedPks,
|
|
79
|
-
const importPackages = [
|
|
80
|
-
...fileContent.importPackages,
|
|
81
|
-
...newData.importPackages,
|
|
82
|
-
];
|
|
83
|
-
console.log(importPackages, 'importPackages');
|
|
84
|
-
return {
|
|
85
|
-
importPackages,
|
|
86
|
-
...newData,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = (compName, compPath, url, layoutName, isTs) => {
|
|
92
|
-
const folderName = toCamel(compName); // 文件夹名称
|
|
93
|
-
const className = toLine(compName); // 类名
|
|
94
|
-
const folderPath = `${resolveApp(compPath)}/${folderName}`;
|
|
95
|
-
const folderExist = existsSync(folderPath); // 文件夹是否存在
|
|
96
|
-
|
|
97
|
-
const importPackages = [`import ${compName} from 'pages/${folderName}';`];
|
|
98
|
-
|
|
99
|
-
if (folderExist) {
|
|
100
|
-
Log(Colors.red(`指定路径下页面已存在,请重新输入页面名`));
|
|
101
|
-
} else {
|
|
102
|
-
// 生成文件
|
|
103
|
-
mkdir(folderPath);
|
|
104
|
-
const indexContent = renderMustache(
|
|
105
|
-
isTs == 'y' ? PAGE_TS_TEMPLATE_PATH : PAGE_TEMPLATE_PATH,
|
|
106
|
-
{
|
|
107
|
-
name: compName,
|
|
108
|
-
className,
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
console.log(indexContent, 'indexContent');
|
|
112
|
-
const styleContent = renderMustache(STYLE_TEMPLATE_PATH, {
|
|
113
|
-
className,
|
|
114
|
-
});
|
|
115
|
-
writerFile(
|
|
116
|
-
Path.join(folderPath, isTs == 'y' ? INDEX_TS_N : INDEX_N),
|
|
117
|
-
indexContent
|
|
118
|
-
);
|
|
119
|
-
writerFile(Path.join(folderPath, STYLE_N), styleContent);
|
|
120
|
-
|
|
121
|
-
// 配置路由
|
|
122
|
-
const newConf = {
|
|
123
|
-
importPackages,
|
|
124
|
-
initRoutConf: '',
|
|
125
|
-
linkPath: url == '' ? `/${className}` : url,
|
|
126
|
-
layoutName,
|
|
127
|
-
compName,
|
|
128
|
-
};
|
|
129
|
-
const routerCPath = resolveApp(
|
|
130
|
-
isTs == 'y' ? `src/router/${ROUTERTC_N_TS}` : `src/router/${ROUTERTC_N}`
|
|
131
|
-
);
|
|
132
|
-
const allRouterConf = mergeRouterCData(routerCPath, newConf);
|
|
133
|
-
console.log(allRouterConf, 'allRouterConf');
|
|
134
|
-
const routerConfContent = renderMustache(
|
|
135
|
-
ROUTERTC_TEMPLATE_PATH,
|
|
136
|
-
allRouterConf
|
|
137
|
-
);
|
|
138
|
-
console.log(routerConfContent, 'routerConfContent');
|
|
139
|
-
writerFile(routerCPath, routerConfContent);
|
|
140
|
-
}
|
|
141
|
-
};
|
package/util/defaultData.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
createChoiceData: [
|
|
3
|
-
{
|
|
4
|
-
name: 'component-创建基于react组件的目录',
|
|
5
|
-
value: 'component',
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
name: 'page-创建基于react页面的目录',
|
|
9
|
-
value: 'page',
|
|
10
|
-
},
|
|
11
|
-
],
|
|
12
|
-
createComData: [
|
|
13
|
-
{
|
|
14
|
-
type: 'Input',
|
|
15
|
-
name: 'name',
|
|
16
|
-
message: '请输入组件名(以大驼峰法命名,如:HelloTable)',
|
|
17
|
-
default: 'HelloTable',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
type: 'Input',
|
|
21
|
-
name: 'ts',
|
|
22
|
-
message: '是否使用TS?(y/n)',
|
|
23
|
-
default: 'y',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
type: 'Input',
|
|
27
|
-
name: 'path',
|
|
28
|
-
message: '请输入生成目录(当前项目为根目录,默认为src/components/)',
|
|
29
|
-
default: 'src/components/',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
createPageData: [
|
|
33
|
-
{
|
|
34
|
-
type: 'Input',
|
|
35
|
-
name: 'name',
|
|
36
|
-
message: '请输入页面名称名(以小驼峰法命名,如:UserLogin)',
|
|
37
|
-
default: 'UserLogin',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: 'Input',
|
|
41
|
-
name: 'ts',
|
|
42
|
-
message: '是否使用typescript?(y/n)',
|
|
43
|
-
default: 'y',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: 'Input',
|
|
47
|
-
name: 'path',
|
|
48
|
-
message: '请输入生成目录(当前项目为根目录,默认为src/pages/)',
|
|
49
|
-
default: 'src/pages/',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
type: 'Input',
|
|
53
|
-
name: 'route',
|
|
54
|
-
message: '请输入访问路径(默认为当前项目名称,如:/user-login)',
|
|
55
|
-
default: '/user-login',
|
|
56
|
-
},
|
|
57
|
-
// {
|
|
58
|
-
// type: 'Input',
|
|
59
|
-
// name: 'layout',
|
|
60
|
-
// message: '请输入布局组件名(默认为:null)',
|
|
61
|
-
// default: 'null'
|
|
62
|
-
// }
|
|
63
|
-
],
|
|
64
|
-
};
|
package/util/file.js
DELETED
package/util/fileService.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Description: 文件
|
|
3
|
-
* @version: 1.0.0
|
|
4
|
-
* @Company: 袋鼠云
|
|
5
|
-
* @Author: Charles
|
|
6
|
-
* @Date: 2018-12-19 11:34:43
|
|
7
|
-
* @LastEditors: Charles
|
|
8
|
-
* @LastEditTime: 2019-07-10 11:58:27
|
|
9
|
-
*/
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const colors = require('colors');
|
|
12
|
-
const { appDirectory } = require('../config/defaultPaths');
|
|
13
|
-
const { resolve, isAbsolute } = require('path');
|
|
14
|
-
/**
|
|
15
|
-
* @description: 文件操作相关
|
|
16
|
-
* @param1: param
|
|
17
|
-
* @param2: param
|
|
18
|
-
* @return: ret
|
|
19
|
-
* @Author: Charles
|
|
20
|
-
* @Date: 2018-12-26 11:30:16
|
|
21
|
-
*/
|
|
22
|
-
module.exports = {
|
|
23
|
-
createFileSync: function (filePath, txt) {
|
|
24
|
-
fs.writeFileSync(filePath, txt, function (err) {
|
|
25
|
-
if (err) {
|
|
26
|
-
console.log(colors.grey(err));
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
createWriteStream: function (filePath) {
|
|
31
|
-
const stream = fs.createWriteStream(filePath);
|
|
32
|
-
return stream;
|
|
33
|
-
},
|
|
34
|
-
readFileSync: function (filePath) {
|
|
35
|
-
const txt = fs.readFileSync(filePath, 'utf8');
|
|
36
|
-
return txt;
|
|
37
|
-
},
|
|
38
|
-
existsSync: function (filePath) {
|
|
39
|
-
return fs.existsSync(filePath);
|
|
40
|
-
},
|
|
41
|
-
mkdir: function (path) {
|
|
42
|
-
// 严格模式下不支持使用0开头声明八进制数
|
|
43
|
-
fs.mkdirSync(path, 0o777);
|
|
44
|
-
},
|
|
45
|
-
getCurFilePath: function (relativePath) {
|
|
46
|
-
const curDirPath = process.cwd();
|
|
47
|
-
return resolve(curDirPath, relativePath);
|
|
48
|
-
},
|
|
49
|
-
isAbsolute: function (curPath) {
|
|
50
|
-
if (isAbsolute(curPath)) {
|
|
51
|
-
return curPath;
|
|
52
|
-
}
|
|
53
|
-
return resolve(appDirectory, curPath);
|
|
54
|
-
},
|
|
55
|
-
};
|
package/util/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const { realpathSync } = require('fs');
|
|
2
|
-
const { resolve } = require('path');
|
|
3
|
-
module.exports = {
|
|
4
|
-
getCurDirPath: function (cwd) {
|
|
5
|
-
return realpathSync(cwd);
|
|
6
|
-
},
|
|
7
|
-
getCurFilePath: function (relativePath) {
|
|
8
|
-
const curDirPath = process.cwd();
|
|
9
|
-
return resolve(curDirPath, relativePath);
|
|
10
|
-
},
|
|
11
|
-
formatBundle: function (data, s) {
|
|
12
|
-
const obj = {};
|
|
13
|
-
const entryLen = Math.ceil(data.length / s) + 1;
|
|
14
|
-
for (let i = 1; i < entryLen; i++) {
|
|
15
|
-
obj[`vendor_${i}`] = data.slice((i - 1) * s, i * s);
|
|
16
|
-
}
|
|
17
|
-
return obj;
|
|
18
|
-
},
|
|
19
|
-
getUserServer: function (data) {
|
|
20
|
-
return data;
|
|
21
|
-
},
|
|
22
|
-
getUserWebpack: function (data) {
|
|
23
|
-
return data;
|
|
24
|
-
},
|
|
25
|
-
};
|
package/util/prepareUrl.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file at
|
|
6
|
-
* https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const url = require('url');
|
|
10
|
-
const colors = require('colors');
|
|
11
|
-
const address = require('address');
|
|
12
|
-
|
|
13
|
-
module.exports = function prepareUrls(protocol, host, port, pathname = '/') {
|
|
14
|
-
const formatUrl = (hostname) =>
|
|
15
|
-
url.format({
|
|
16
|
-
protocol,
|
|
17
|
-
hostname,
|
|
18
|
-
port,
|
|
19
|
-
pathname,
|
|
20
|
-
});
|
|
21
|
-
const prettyPrintUrl = (hostname) =>
|
|
22
|
-
url.format({
|
|
23
|
-
protocol,
|
|
24
|
-
hostname,
|
|
25
|
-
port: colors.bold(port),
|
|
26
|
-
pathname,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const isUnspecifiedHost =
|
|
30
|
-
host === '127.0.0.1' || host === '0.0.0.0' || host === '::';
|
|
31
|
-
let prettyHost;
|
|
32
|
-
let lanUrlForConfig;
|
|
33
|
-
let lanUrlForTerminal;
|
|
34
|
-
let lanUrlForBrowser;
|
|
35
|
-
if (isUnspecifiedHost) {
|
|
36
|
-
prettyHost = 'localhost';
|
|
37
|
-
try {
|
|
38
|
-
// This can only return an IPv4 address
|
|
39
|
-
lanUrlForConfig = address.ip();
|
|
40
|
-
if (lanUrlForConfig) {
|
|
41
|
-
if (
|
|
42
|
-
/^10[.]|^30[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
|
|
43
|
-
lanUrlForConfig
|
|
44
|
-
)
|
|
45
|
-
) {
|
|
46
|
-
// Address is private, format it for later use
|
|
47
|
-
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
|
|
48
|
-
lanUrlForBrowser = formatUrl(lanUrlForConfig);
|
|
49
|
-
} else {
|
|
50
|
-
// Address is not private, so we will discard it
|
|
51
|
-
lanUrlForConfig = undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} catch (_e) {
|
|
55
|
-
// ignored
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
prettyHost = host;
|
|
59
|
-
}
|
|
60
|
-
const localUrlForTerminal = prettyPrintUrl(prettyHost);
|
|
61
|
-
const localUrlForBrowser = formatUrl(prettyHost);
|
|
62
|
-
return {
|
|
63
|
-
lanUrlForConfig,
|
|
64
|
-
lanUrlForTerminal,
|
|
65
|
-
lanUrlForBrowser,
|
|
66
|
-
localUrlForTerminal,
|
|
67
|
-
localUrlForBrowser,
|
|
68
|
-
};
|
|
69
|
-
};
|
package/util/program.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const { Command } = require('commander');
|
|
2
|
-
const program = new Command();
|
|
3
|
-
|
|
4
|
-
const opts = {};
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* attach program.opts() to process.env object
|
|
8
|
-
* NOTICE:
|
|
9
|
-
* Multi-word options such as "--template-engine" are camel-cased, becoming program.opts().templateEngine etc
|
|
10
|
-
*/
|
|
11
|
-
function attachOptions(program) {
|
|
12
|
-
const options = program.opts();
|
|
13
|
-
Object.assign(opts, options);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = {
|
|
17
|
-
program,
|
|
18
|
-
opts,
|
|
19
|
-
attachOptions,
|
|
20
|
-
};
|
package/util/request.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const urllib = require('urllib');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
get: (data, url) => {
|
|
5
|
-
return urllib.request(url, {
|
|
6
|
-
method: 'GET',
|
|
7
|
-
dataType: 'json',
|
|
8
|
-
data,
|
|
9
|
-
});
|
|
10
|
-
},
|
|
11
|
-
post: (data, url) => {
|
|
12
|
-
return urllib.request(url, {
|
|
13
|
-
method: 'POST',
|
|
14
|
-
dataType: 'json',
|
|
15
|
-
data,
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
};
|
package/util/stdout.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const colors = require('colors');
|
|
2
|
-
const ora = require('ora');
|
|
3
|
-
|
|
4
|
-
function inProcess(conf) {
|
|
5
|
-
const {
|
|
6
|
-
initStr = 'process start',
|
|
7
|
-
spinStr = 'in process',
|
|
8
|
-
spinColor = 'yellow',
|
|
9
|
-
process,
|
|
10
|
-
} = conf;
|
|
11
|
-
if (!process) throw new TypeError('argument process must been defined!');
|
|
12
|
-
const spinner = ora(initStr).start();
|
|
13
|
-
setTimeout(() => {
|
|
14
|
-
spinner.text = spinStr;
|
|
15
|
-
spinner.color = spinColor;
|
|
16
|
-
}, 100);
|
|
17
|
-
process();
|
|
18
|
-
spinner.stop();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function logWithColor(color, text) {
|
|
22
|
-
try {
|
|
23
|
-
if (color) {
|
|
24
|
-
console.log(colors[color](text));
|
|
25
|
-
} else {
|
|
26
|
-
console.log(text);
|
|
27
|
-
}
|
|
28
|
-
} catch (ex) {
|
|
29
|
-
console.error(ex);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
inProcess,
|
|
35
|
-
logWithColor,
|
|
36
|
-
};
|
package/util/userConfig.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const { existsSync } = require('fs');
|
|
2
|
-
const { resolve } = require('path');
|
|
3
|
-
const webpack = require('webpack');
|
|
4
|
-
const userConfFileName = 'ko.config.js';
|
|
5
|
-
|
|
6
|
-
const emptyObject = {};
|
|
7
|
-
const emptyString = '';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @returns {
|
|
11
|
-
* webpack: webpack user-defined configs
|
|
12
|
-
* babel: babel user-defined configs, Object
|
|
13
|
-
* prettier: prettier user-defined configs
|
|
14
|
-
* eslint: eslint user-defined configs
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
function getUserConf() {
|
|
19
|
-
const userConfFile = resolve(process.cwd(), userConfFileName);
|
|
20
|
-
if (existsSync(userConfFile)) {
|
|
21
|
-
const userConf =
|
|
22
|
-
require(userConfFile)({ webpack, env: process.env.NODE_ENV }) || {};
|
|
23
|
-
return {
|
|
24
|
-
webpack: userConf.webpack || emptyObject,
|
|
25
|
-
babel: userConf.babel || emptyObject,
|
|
26
|
-
prettier: userConf.prettier || emptyString,
|
|
27
|
-
eslint: userConf.eslint || emptyString,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
webpack: emptyObject,
|
|
32
|
-
babel: emptyObject,
|
|
33
|
-
prettier: emptyString,
|
|
34
|
-
eslint: emptyString,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const userConf = getUserConf();
|
|
39
|
-
|
|
40
|
-
module.exports = userConf;
|