@tmsfe/tmskit 0.0.2 → 0.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "tmskit",
5
5
  "main": "main.js",
6
6
  "bin": {
@@ -21,47 +21,48 @@
21
21
  "@rollup/plugin-babel": "^5.0.2",
22
22
  "@rollup/plugin-commonjs": "^19.0.0",
23
23
  "@rollup/plugin-dynamic-import-vars": "^1.1.1",
24
- "@rollup/plugin-json": "^4.0.3"
24
+ "@rollup/plugin-json": "^4.0.3",
25
+ "rollup": "^2.6.1",
26
+ "rollup-plugin-node-resolve": "^5.2.0",
27
+ "rollup-plugin-replace": "^2.2.0",
28
+ "rollup-plugin-terser": "^6.1.0",
29
+ "rollup-plugin-typescript2": "0.27.0"
25
30
  },
26
31
  "dependencies": {
27
32
  "@babel/core": "^7.15.0",
28
33
  "@babel/plugin-transform-modules-commonjs": "^7.16.0",
29
34
  "@babel/preset-env": "^7.16.0",
30
35
  "async": "^3.2.2",
36
+ "axios": "^0.21.4",
31
37
  "babel-core": "^6.26.3",
32
38
  "babel-loader": "^8.2.3",
33
- "copy-webpack-plugin": "^9.1.0",
34
- "cross-env": "^7.0.3",
35
- "leven": "3.1.0",
36
- "metalsmith": "^2.3.0",
37
- "minimist": "^1.2.5",
38
- "rollup": "^2.6.1",
39
- "rollup-plugin-node-resolve": "^5.2.0",
40
- "rollup-plugin-terser": "^6.1.0",
41
- "rollup-plugin-typescript2": "0.27.0",
42
- "ts-loader": "^9.2.6",
43
- "url-loader": "^4.1.1",
44
- "webpack": "^5.64.0",
45
- "webpack-cli": "^4.9.1",
46
- "axios": "^0.21.4",
47
39
  "chalk": "^4.1.0",
48
40
  "commander": "^6.2.1",
41
+ "copy-webpack-plugin": "^9.1.0",
42
+ "cross-env": "^7.0.3",
49
43
  "download-git-repo": "^3.0.2",
50
44
  "ejs": "^3.1.5",
51
45
  "file-loader": "^6.2.0",
52
46
  "fs-extra": "^9.0.1",
47
+ "glob-ignore": "^1.0.2",
53
48
  "inquirer": "^7.3.3",
49
+ "leven": "3.1.0",
54
50
  "lodash": "^4.17.21",
51
+ "metalsmith": "^2.3.0",
55
52
  "mini-css-extract-plugin": "^2.4.5",
53
+ "minimist": "^1.2.5",
56
54
  "miniprogram-ci": "1.4.13",
57
55
  "ora": "^5.1.0",
58
56
  "replace-ext": "^2.0.0",
59
- "rollup-plugin-replace": "^2.2.0",
60
57
  "shelljs": "^0.8.4",
58
+ "ts-loader": "^9.2.6",
61
59
  "tslib": "^1.14.1",
62
60
  "typescript": "^3.8.3",
61
+ "url-loader": "^4.1.1",
63
62
  "username": "5.1.0",
64
- "webpack-chain": "^6.5.1"
63
+ "webpack": "^5.64.0",
64
+ "webpack-chain": "^6.5.1",
65
+ "webpack-cli": "^4.9.1"
65
66
  },
66
67
  "engines": {
67
68
  "node": "^12.17.0 || >= 14.0.0"
@@ -48,6 +48,8 @@ const ENV = {
48
48
  prod: 'production',
49
49
  };
50
50
 
51
+ const TEMPLATE_TKIT_DIR = '_tmskit';
52
+
51
53
  export {
52
54
  HOME_DIR,
53
55
  CACHE_DIR,
@@ -62,4 +64,5 @@ export {
62
64
  MODULE_CODE_DIR,
63
65
  MODE,
64
66
  ENV,
67
+ TEMPLATE_TKIT_DIR,
65
68
  };
@@ -1,17 +1,19 @@
1
1
  const fs = require('fs');
2
2
  const inquirer = require('inquirer');
3
+ const { resolve } = require('../../utils/widgets');
4
+ const { TEMPLATE_TKIT_DIR } = require('../../config/constant');
3
5
  /**
4
6
  * 获取模板内的问题
5
- * @param {string} templateDir 模板目录
7
+ * @param {string} dir questions.json所在的目录
6
8
  * @returns {Array} inquirer 问题数组
7
9
  */
8
- const parseTemplateQuestions = (templateDir) => {
10
+ const parseTemplateQuestions = (dir) => {
9
11
  let prompts = [];
10
- if (!fs.existsSync(`${templateDir}/questions.json`)) {
12
+ if (!fs.existsSync(`${dir}/questions.json`)) {
11
13
  return prompts;
12
14
  }
13
15
  try {
14
- const json = JSON.parse(fs.readFileSync(`${templateDir}/questions.json`));
16
+ const json = JSON.parse(fs.readFileSync(`${dir}/questions.json`));
15
17
  if (Array.isArray(json) && json.length > 0) {
16
18
  json.forEach((item, index) => {
17
19
  if (!isQuestionType(item)) {
@@ -38,7 +40,7 @@ const isQuestionType = (result) => {
38
40
  };
39
41
 
40
42
  const ask = templateDir => (files, metalsmith, next) => {
41
- const prompts = parseTemplateQuestions(templateDir);
43
+ const prompts = parseTemplateQuestions(resolve(templateDir, TEMPLATE_TKIT_DIR));
42
44
  const metadata = metalsmith.metadata();
43
45
  const filteredPrompts = prompts.filter((prompt) => {
44
46
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -18,7 +18,6 @@ const generator = (buildDir, distDir, preMetadata) => new Promise((resolve, reje
18
18
  if (err) {
19
19
  reject(err);
20
20
  } else {
21
- fs.unlinkSync(`${distDir}/questions.json`);
22
21
  resolve('finish');
23
22
  }
24
23
  });
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
  const shelljs = require('shelljs');
4
- const { TEMPLATE_DIR, TEMPLATE_PATH } = require('../../config/constant.js');
4
+ const { TEMPLATE_DIR, TEMPLATE_PATH, TEMPLATE_TKIT_DIR } = require('../../config/constant.js');
5
5
  const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
6
6
  const io = require('../../utils/io');
7
7
  const { fail, succeed } = require('../../utils/log');
@@ -41,7 +41,7 @@ async function create(appName) {
41
41
  await createTask(downloadRepoForGit, '拉取模板仓库', '拉取模板仓库完成')(
42
42
  'https://git.woa.com/tmsfe/tms-frontend.git',
43
43
  TEMPLATE_DIR,
44
- 'master',
44
+ 'feat-albertluo-template82b',
45
45
  );
46
46
 
47
47
  // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
@@ -50,11 +50,19 @@ async function create(appName) {
50
50
  appType,
51
51
  }).then(() => {
52
52
  succeed('项目创建完成,开始初始化...');
53
+
53
54
  shelljs.cd(appName);
54
- // 初始化构件主包的代码, 让用户打开项目可以跑起来
55
- if (fs.existsSync(resolve(`${appName}/tms.config.js`))) {
56
- shelljs.exec('tmskit run build');
55
+ const hooks = require(resolve(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
56
+ if (hooks.afterCreate) {
57
+ hooks.afterCreate.forEach((item) => {
58
+ if (typeof item === 'function') {
59
+ item.call(null, shelljs, { appName });
60
+ } else {
61
+ shelljs.exec(item);
62
+ }
63
+ });
57
64
  }
65
+ shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
58
66
  })
59
67
  .catch((err) => {
60
68
  fail(err.message);
@@ -1,7 +1,8 @@
1
1
  const init = require('./init/index');
2
2
  const dev = require('./dev/index');
3
3
  const build = require('./build/index');
4
- const { createTask } = require('../../utils/widgets');
4
+ const install = require('./install/index');
5
+ const { createTask, resolve } = require('../../utils/widgets');
5
6
  const { MODE } = require('../../config/constant');
6
7
  const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
7
8
 
@@ -22,6 +23,11 @@ const handleModulesArg = (cmd) => {
22
23
  };
23
24
 
24
25
  async function run(commandName, cmd) {
26
+ if (commandName === 'install') {
27
+ install(resolve('./'));
28
+ return;
29
+ }
30
+
25
31
  const moduleArg = handleModulesArg(cmd);
26
32
  const { env } = cmd;
27
33
 
@@ -0,0 +1,40 @@
1
+ const shelljs = require('shelljs');
2
+ const { createTask } = require('../../../utils/widgets');
3
+ const { buildMpNpm } = require('../../../utils/mpCiUtils');
4
+ const glob = require('glob-ignore');
5
+ const path = require('path');
6
+
7
+ function npmInstall(contextDir) {
8
+ return new Promise((resolve, reject) => {
9
+ glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
10
+ console.log('files', files);
11
+ if (err) {
12
+ reject(err);
13
+ }
14
+ files.forEach((file) => {
15
+ const dir = path.dirname(file);
16
+ shelljs.cd(dir);
17
+ shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', { silent: false });
18
+ });
19
+ resolve();
20
+ });
21
+ });
22
+ }
23
+
24
+ async function install(contextDir) {
25
+ // npm install
26
+ await createTask(
27
+ npmInstall,
28
+ '开始npm install',
29
+ 'npm install完成',
30
+ )(contextDir);
31
+
32
+ // 构建miniprograme_npm
33
+ await createTask(
34
+ buildMpNpm,
35
+ '开始构建miniprogram_npm',
36
+ '构建miniprogram_npm 完成',
37
+ )({ appId: 'null', projectPath: contextDir, privateKey: 'null' });
38
+ }
39
+
40
+ module.exports = install;
@@ -96,7 +96,7 @@ function downloadRepo(dest, downloadOptions = { repoUrl: '', gitUrl: '', branch:
96
96
  function downloadRepoForGit(url, dest, branch) {
97
97
  const cwd = process.cwd();
98
98
 
99
- return new Promise((resolve, reject) => {
99
+ return new Promise((resolve) => {
100
100
  // 如果目标目录不存在
101
101
  if (fs.existsSync(dest)) {
102
102
  shelljs.rm('-rf', path.join(dest));
@@ -105,17 +105,10 @@ function downloadRepoForGit(url, dest, branch) {
105
105
  shelljs.mkdir('-p', dest);
106
106
  shelljs.cd(dest);
107
107
 
108
- shelljs.exec(`git clone ${url} ${dest} --depth=1`, shelljsOptons);
109
-
110
- shelljs.exec(`git checkout ${branch}`, (code) => {
111
- if (code === 0) {
112
- shelljs.cd(cwd);
108
+ shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
113
109
 
114
- resolve();
115
- }
116
-
117
- reject();
118
- });
110
+ shelljs.cd(cwd);
111
+ resolve();
119
112
  });
120
113
  }
121
114
 
@@ -5,7 +5,6 @@ const { getEntry } = require('../../utils');
5
5
  class EntryExtraPlugin {
6
6
  constructor(options = {}) {
7
7
  this.options = options;
8
- this.scriptExtensions = options.scriptExtensions || ['.ts', '.js'];
9
8
  }
10
9
 
11
10
  applyEntry(compiler, entry) {
@@ -1,14 +0,0 @@
1
- const px2rpx = postcss.plugin('postcss-px2rpx', (opts = {}) => {
2
- const { proportion = 1, minPixelValue = 0 } = opts;
3
-
4
- return (root) => {
5
- root.replaceValues(pxRegExp, { fast: 'px' }, (string) => {
6
- const pixels = parseInt(string, 10);
7
- if (pixels < minPixelValue) return `${pixels}px`;
8
- return `${proportion * parseInt(string, 10)}rpx`;
9
- });
10
- };
11
- });
12
-
13
-
14
- export default px2rpx;