@tmsfe/tmskit 0.0.7 → 0.0.9-beta.1

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.
Files changed (46) hide show
  1. package/README.md +27 -27
  2. package/dist/index.cjs.js +1284 -983
  3. package/main.js +3 -3
  4. package/package.json +73 -75
  5. package/src/{gulp → compile}/build.js +5 -5
  6. package/src/{gulp → compile}/compile.js +90 -81
  7. package/src/{gulp → compile}/dev.js +129 -102
  8. package/src/{gulp → compile}/plugins/less.js +116 -116
  9. package/src/{gulp → compile}/plugins/mpCommonDep.js +131 -131
  10. package/src/{gulp → compile}/plugins/mpJsonDep.js +112 -108
  11. package/src/{gulp → compile}/plugins/mpWxmlDep.js +194 -194
  12. package/src/{gulp → compile}/plugins/postcss-font-base64.js +72 -72
  13. package/src/{gulp → compile}/plugins/replaceEnv.js +29 -29
  14. package/src/{gulp → compile}/plugins/utils/pluginError.js +25 -25
  15. package/src/config/constant.js +69 -71
  16. package/src/config/defaultTmsConfig.js +16 -16
  17. package/src/{utils → core}/buildAppJson.js +166 -221
  18. package/src/{utils → core}/checkDependencies.js +77 -77
  19. package/src/core/cloneModules.js +203 -0
  20. package/src/{utils → core}/handleError.js +18 -16
  21. package/src/core/isInIt.js +69 -0
  22. package/src/{utils/mpCiUtils.js → core/mpCi.js} +73 -73
  23. package/src/core/npm.js +218 -0
  24. package/src/core/symbolicLink.js +24 -0
  25. package/src/{utils/tkitUtils.js → core/tmsMpconfig.js} +234 -158
  26. package/src/entry.js +62 -60
  27. package/src/index.js +63 -62
  28. package/src/init.js +33 -33
  29. package/src/scripts/create/ask.js +63 -63
  30. package/src/scripts/create/generator.js +25 -25
  31. package/src/scripts/create/ignoreFiles.js +7 -7
  32. package/src/scripts/create/index.js +72 -72
  33. package/src/scripts/create/render.js +19 -19
  34. package/src/scripts/run/build/index.js +16 -17
  35. package/src/scripts/run/dev/index.js +42 -84
  36. package/src/scripts/run/index.js +97 -68
  37. package/src/scripts/run/init/index.js +95 -87
  38. package/src/scripts/run/install/index.js +31 -29
  39. package/src/utils/findCssImport.js +30 -30
  40. package/src/utils/global.js +22 -36
  41. package/src/utils/io.js +107 -106
  42. package/src/utils/log.js +47 -44
  43. package/src/utils/widgets.js +178 -167
  44. package/src/utils/cliUtils.js +0 -35
  45. package/src/utils/cloneModules.js +0 -116
  46. package/src/utils/npmUtils.js +0 -166
@@ -1,72 +1,72 @@
1
- /* eslint-disable no-param-reassign */
2
- const postcss = require('postcss');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { fail } = require('../../utils/log');
6
-
7
- module.exports = postcss.plugin('postcss-font-base64', (options) => {
8
- options = {
9
- ...options,
10
- ...{
11
- match: { Scrabble: ['fakefont'] },
12
- format: ['eot', 'woff', 'woff2', 'ttf'],
13
- },
14
- };
15
-
16
- return function (css, result) {
17
- css.walkAtRules('font-face', (fontFace) => {
18
- const fileTypeRegex = getRegexStringForFileTypes(options.format);
19
-
20
- fontFace.replaceValues(new RegExp(`url\\(["']?.+\\.${fileTypeRegex}["']?\\)`), (attr) => {
21
- const fontRePath = attr.replace(/(url|'|"|\(|\)|\?#iefix)/g, '');
22
- const fontAbPath = path.join(path.dirname(result.opts.from), fontRePath);
23
- const res64 = base64Encode(fontAbPath);
24
- const newUrlStr = 'url(data:'.concat(getMimeType(attr)).concat(';charset=utf-8;base64,')
25
- .concat(res64)
26
- .concat(')');
27
- return res64 ? newUrlStr : attr;
28
- });
29
- });
30
-
31
- function getRegexStringForFileTypes(fileTypes) {
32
- const regex = fileTypes.map(fileType => (
33
- fileType === 'eot'
34
- ? fileType.concat('(\\?#iefix)?')
35
- : fileType)).join('|');
36
- return regex ? `(${regex})` : '';
37
- }
38
-
39
- // helper functions
40
- function getMimeType(attribute) {
41
- const formats = {
42
- '.woff': 'application/font-woff',
43
- '.woff2': 'font/woff2',
44
- '.ttf': 'application/font-sfnt',
45
- '.eot': 'application/vnd.ms-fontobject',
46
- '.otf': 'application/font-sfnt',
47
- };
48
-
49
- let match = '';
50
- const extension = attribute.match(/\.[a-z]{3,4}/)[0];
51
-
52
- if (extension in formats) {
53
- match = formats[extension];
54
- };
55
- return match;
56
- };
57
-
58
- function base64Encode(file) {
59
- if (fs.existsSync(file)) {
60
- return readAndEncodeFile(file);
61
- }
62
-
63
- fail(`${file} does not exist.`);
64
- return '';
65
- }
66
-
67
- function readAndEncodeFile(file) {
68
- const bitmap = fs.readFileSync(file);
69
- return Buffer.from(bitmap).toString('base64');
70
- }
71
- };
72
- });
1
+ /* eslint-disable no-param-reassign */
2
+ const postcss = require('postcss');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { fail } = require('../../utils/log');
6
+
7
+ module.exports = postcss.plugin('postcss-font-base64', (options) => {
8
+ options = {
9
+ ...options,
10
+ ...{
11
+ match: { Scrabble: ['fakefont'] },
12
+ format: ['eot', 'woff', 'woff2', 'ttf'],
13
+ },
14
+ };
15
+
16
+ return function (css, result) {
17
+ css.walkAtRules('font-face', (fontFace) => {
18
+ const fileTypeRegex = getRegexStringForFileTypes(options.format);
19
+
20
+ fontFace.replaceValues(new RegExp(`url\\(["']?.+\\.${fileTypeRegex}["']?\\)`), (attr) => {
21
+ const fontRePath = attr.replace(/(url|'|"|\(|\)|\?#iefix)/g, '');
22
+ const fontAbPath = path.join(path.dirname(result.opts.from), fontRePath);
23
+ const res64 = base64Encode(fontAbPath);
24
+ const newUrlStr = 'url(data:'.concat(getMimeType(attr)).concat(';charset=utf-8;base64,')
25
+ .concat(res64)
26
+ .concat(')');
27
+ return res64 ? newUrlStr : attr;
28
+ });
29
+ });
30
+
31
+ function getRegexStringForFileTypes(fileTypes) {
32
+ const regex = fileTypes.map(fileType => (
33
+ fileType === 'eot'
34
+ ? fileType.concat('(\\?#iefix)?')
35
+ : fileType)).join('|');
36
+ return regex ? `(${regex})` : '';
37
+ }
38
+
39
+ // helper functions
40
+ function getMimeType(attribute) {
41
+ const formats = {
42
+ '.woff': 'application/font-woff',
43
+ '.woff2': 'font/woff2',
44
+ '.ttf': 'application/font-sfnt',
45
+ '.eot': 'application/vnd.ms-fontobject',
46
+ '.otf': 'application/font-sfnt',
47
+ };
48
+
49
+ let match = '';
50
+ const extension = attribute.match(/\.[a-z]{3,4}/)[0];
51
+
52
+ if (extension in formats) {
53
+ match = formats[extension];
54
+ };
55
+ return match;
56
+ };
57
+
58
+ function base64Encode(file) {
59
+ if (fs.existsSync(file)) {
60
+ return readAndEncodeFile(file);
61
+ }
62
+
63
+ fail(`${file} does not exist.`);
64
+ return '';
65
+ }
66
+
67
+ function readAndEncodeFile(file) {
68
+ const bitmap = fs.readFileSync(file);
69
+ return Buffer.from(bitmap).toString('base64');
70
+ }
71
+ };
72
+ });
@@ -1,29 +1,29 @@
1
- const through = require('through2');
2
- function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
3
- const stream = through.obj(function (file, enc, cb) {
4
- if (file.isBuffer()) {
5
- let contents = String(file.contents);
6
- let resReg;
7
- // eslint-disable-next-line
8
- while ((resReg = reg.exec(contents)) !== null) {
9
- const [reg1, reg2, reg3] = resReg;
10
- if (reg1 && reg2 && reg3) {
11
- const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
12
- contents = contents.replace(reg1, value);
13
- } else if (reg1 && !reg2 && !reg3) {
14
- contents = contents.replace(reg1, JSON.stringify(envData));
15
- }
16
- }
17
-
18
- // eslint-disable-next-line
19
- file.contents = Buffer.from(contents);
20
- }
21
-
22
- this.push(file);
23
- cb();
24
- });
25
-
26
- return stream;
27
- }
28
-
29
- module.exports = replaceEnv;
1
+ const through = require('through2');
2
+ function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
3
+ const stream = through.obj(function (file, enc, cb) {
4
+ if (file.isBuffer()) {
5
+ let contents = String(file.contents);
6
+ let resReg;
7
+ // eslint-disable-next-line
8
+ while ((resReg = reg.exec(contents)) !== null) {
9
+ const [reg1, reg2, reg3] = resReg;
10
+ if (reg1 && reg2 && reg3) {
11
+ const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
12
+ contents = contents.replace(reg1, value);
13
+ } else if (reg1 && !reg2 && !reg3) {
14
+ contents = contents.replace(reg1, JSON.stringify(envData));
15
+ }
16
+ }
17
+
18
+ // eslint-disable-next-line
19
+ file.contents = Buffer.from(contents);
20
+ }
21
+
22
+ this.push(file);
23
+ cb();
24
+ });
25
+
26
+ return stream;
27
+ }
28
+
29
+ module.exports = replaceEnv;
@@ -1,25 +1,25 @@
1
- /* eslint-disable no-param-reassign */
2
- const { fail } = require('../../../utils/log');
3
-
4
- function pluginError(error, isWatch) {
5
- const errorOptions = { showStack: true };
6
-
7
- errorOptions.error = error;
8
- errorOptions.fileName = error.file;
9
- errorOptions.lineNumber = error.line;
10
- errorOptions.showProperties = false;
11
- errorOptions.showStack = false;
12
-
13
- const errMsg = error.message;
14
-
15
- if (isWatch) {
16
- fail(errMsg);
17
- } else {
18
- fail(errMsg);
19
- process.exit(1);
20
- }
21
- }
22
-
23
- module.exports = {
24
- pluginError,
25
- };
1
+ /* eslint-disable no-param-reassign */
2
+ const { fail } = require('../../../utils/log');
3
+
4
+ function pluginError(error, isWatch) {
5
+ const errorOptions = { showStack: true };
6
+
7
+ errorOptions.error = error;
8
+ errorOptions.fileName = error.file;
9
+ errorOptions.lineNumber = error.line;
10
+ errorOptions.showProperties = false;
11
+ errorOptions.showStack = false;
12
+
13
+ const errMsg = error.message;
14
+
15
+ if (isWatch) {
16
+ fail(errMsg);
17
+ } else {
18
+ fail(errMsg);
19
+ process.exit(1);
20
+ }
21
+ }
22
+
23
+ module.exports = {
24
+ pluginError,
25
+ };
@@ -1,71 +1,69 @@
1
- const path = require('path');
2
-
3
- // 用户目录
4
- const HOME_DIR = process.env.HOME;
5
-
6
- // 所有文件的缓存目录
7
- const CACHE_DIR = path.resolve(HOME_DIR, '.tmskit');
8
-
9
- // 脚手架模板代码所在目录
10
- const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
11
-
12
- // 第三方模块源码存放的临时缓存目录
13
- const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
14
-
15
- // 脚手架模板代码的具体路径
16
- const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tms-cli-template');
17
-
18
- // 脚手架的名称
19
- const TMS_NAME = 'tmskit';
20
-
21
- // 脚手架的配置名称
22
- const TMS_CONFIG_FILENAME = 'tms.config.js';
23
-
24
- const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
25
-
26
- // 模块代码的默认在modules子目录
27
- const DEFAULT_MODULE_DIR = 'modules';
28
-
29
- // 模块的配置文件的名称
30
- const MODULE_CONFIG_FILENAME = 'module.config.json';
31
-
32
- // 默认的webpack entry
33
- const DEFAULT_WEBPACK_ENTRY = {
34
- app: path.resolve(process.cwd(), 'app'),
35
- };
36
-
37
- // 默认从源码拷贝到编译后的配置
38
- const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
39
-
40
- // 开发模式
41
- const MODE = {
42
- all: 'all',
43
- multi: 'multi',
44
- };
45
-
46
- const ENV = {
47
- dev: 'development',
48
- prod: 'production',
49
- };
50
-
51
- const TEMPLATE_TKIT_DIR = '_tmskit';
52
- const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
53
-
54
- export {
55
- HOME_DIR,
56
- CACHE_DIR,
57
- TEMPLATE_DIR,
58
- TEMPLATE_PATH,
59
- TMS_NAME,
60
- TMS_CONFIG_FILENAME,
61
- TMS_PRIVATE_FILENAME,
62
- DEFAULT_MODULE_DIR,
63
- MODULE_CONFIG_FILENAME,
64
- DEFAULT_WEBPACK_ENTRY,
65
- DEFAULT_COPY_CONFIG,
66
- MODULE_CODE_DIR,
67
- MODE,
68
- ENV,
69
- TEMPLATE_TKIT_DIR,
70
- MODULE_CONFIG_INVALID_KEY,
71
- };
1
+ const path = require('path');
2
+ const os = require('os');
3
+
4
+ // 用户目录
5
+ const HOME_DIR = os.homedir();
6
+
7
+ // 所有文件的缓存目录
8
+ const CACHE_DIR = path.resolve(HOME_DIR, '.tmskit');
9
+
10
+ // 脚手架模板代码所在目录
11
+ const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
12
+
13
+ // 第三方模块源码存放的临时缓存目录
14
+ const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
15
+
16
+ // 脚手架模板代码的具体路径
17
+ const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tms-cli-template');
18
+
19
+ // 脚手架的名称
20
+ const TMS_NAME = 'tmskit';
21
+
22
+ // 脚手架的配置名称
23
+ const TMS_CONFIG_FILENAME = 'tms.config.js';
24
+
25
+ const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
26
+
27
+ // 模块代码的默认在modules子目录
28
+ const DEFAULT_MODULE_DIR = 'modules';
29
+
30
+ // 模块代码的默认在modules子目录
31
+ const DEFAULT_CLOUD_MODULE_DIR = './cloud';
32
+
33
+ // 模块的配置文件的名称
34
+ const MODULE_CONFIG_FILENAME = 'module.config.json';
35
+
36
+ // 默认的webpack entry
37
+ const DEFAULT_WEBPACK_ENTRY = {
38
+ app: path.resolve(process.cwd(), 'app'),
39
+ };
40
+
41
+ // 默认从源码拷贝到编译后的配置
42
+ const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
43
+
44
+ const ENV = {
45
+ dev: 'development',
46
+ prod: 'production',
47
+ };
48
+
49
+ const TEMPLATE_TKIT_DIR = '_tmskit';
50
+ const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
51
+
52
+ export {
53
+ HOME_DIR,
54
+ CACHE_DIR,
55
+ TEMPLATE_DIR,
56
+ TEMPLATE_PATH,
57
+ TMS_NAME,
58
+ TMS_CONFIG_FILENAME,
59
+ TMS_PRIVATE_FILENAME,
60
+ DEFAULT_MODULE_DIR,
61
+ MODULE_CONFIG_FILENAME,
62
+ DEFAULT_WEBPACK_ENTRY,
63
+ DEFAULT_COPY_CONFIG,
64
+ MODULE_CODE_DIR,
65
+ ENV,
66
+ TEMPLATE_TKIT_DIR,
67
+ MODULE_CONFIG_INVALID_KEY,
68
+ DEFAULT_CLOUD_MODULE_DIR,
69
+ };
@@ -1,16 +1,16 @@
1
- // tmsConfig默认配置项
2
- module.exports = {
3
- // 全局的环境配置项
4
- envData: {},
5
- // 模块配置信息
6
- modules: [],
7
- cloudDir: 'cloud',
8
- // 第三方依赖代码需要拷贝到本项目的
9
- dependencies: {},
10
- /** 编译输出文件夹位置 */
11
- outputDir: 'dist',
12
- /** 源码监听路径 */
13
- sourceDir: './',
14
- /** 静态资源目录 */
15
- static: [],
16
- };
1
+ // tmsConfig默认配置项
2
+ module.exports = {
3
+ // 全局的环境配置项
4
+ envData: {},
5
+ // 模块配置信息
6
+ modules: [],
7
+ cloudDir: 'cloud',
8
+ // 第三方依赖代码需要拷贝到本项目的
9
+ dependencies: {},
10
+ /** 编译输出文件夹位置 */
11
+ outputDir: 'dist',
12
+ /** 源码监听路径 */
13
+ sourceDir: './',
14
+ /** 静态资源目录 */
15
+ static: [],
16
+ };