kn-cli 1.0.119 → 1.0.122

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.
@@ -21,6 +21,7 @@
21
21
  "@babel/plugin-proposal-private-methods": "~7.8.3",
22
22
  "@babel/plugin-transform-runtime": "7.5.0",
23
23
  "@babel/plugin-transform-regenerator": "~7.27.5",
24
+ "@babel/plugin-proposal-logical-assignment-operators": "~7.8.3",
24
25
  "@babel/polyfill": "~7.8.7",
25
26
  "@babel/preset-env": "7.7.7",
26
27
  "@babel/preset-react": "~7.8.3",
@@ -153,6 +153,8 @@ const LOADER_JS=[
153
153
  ['@babel/plugin-proposal-decorators', { legacy: true }],
154
154
  ['@babel/plugin-proposal-private-methods', { loose: true }],
155
155
  ['@babel/plugin-proposal-class-properties', { loose: true }],
156
+ ['@babel/plugin-proposal-logical-assignment-operators', { loose: true }],
157
+
156
158
  // ["import", {
157
159
  // style: false,//"css",
158
160
  // libraryName: "kn-hooks" ,
@@ -523,7 +525,7 @@ const config={
523
525
  path.resolve(webpackPath, 'node_modules'),
524
526
  'node_modules',
525
527
  ],
526
- extensions: ['.jsx', '.js', '.json'],
528
+ extensions: ['.jsx', '.js', '.json','.mjs'],
527
529
  alias: {
528
530
  '@': path.resolve(dirname, 'src/'),
529
531
  ...Alias,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kn-cli",
3
- "version": "1.0.119",
3
+ "version": "1.0.122",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -140,6 +140,9 @@ report
140
140
 
141
141
 
142
142
  # 更新日志
143
+ * 1.0.120
144
+ 支持??=语法编译
145
+
143
146
  * 1.0.97
144
147
  将Postcss版本锁定在8
145
148
 
package/src/clear.js ADDED
@@ -0,0 +1,64 @@
1
+
2
+ const path= require( "path");
3
+ const ROOT=path.resolve(__dirname,"../");
4
+ const fs = require('fs');
5
+ const inquirer = require('inquirer');
6
+
7
+
8
+ module.exports=async ()=> {
9
+ const sourceDir = process.cwd()
10
+ const tempDir = path.resolve(ROOT,'temp');
11
+ const now = new Date();
12
+ const threeMonthsAgo = new Date();
13
+ threeMonthsAgo.setMonth(now.getMonth() - 3);
14
+ let needClears=[];
15
+ try{
16
+ var files = fs.readdirSync(tempDir,{withFileTypes:true});
17
+ files.forEach(file=>{
18
+ if(/^[.]/.test(file.name))return;
19
+ const filename = path.resolve(tempDir,file.name,'_webpack');
20
+ if(!fs.existsSync(filename))return;
21
+ const fileStat = fs.statSync(filename);
22
+ if(fileStat.isDirectory()){
23
+ const isOlderThan3Months = fileStat.mtime < threeMonthsAgo;
24
+ if(isOlderThan3Months){
25
+ needClears.push(file.name)
26
+ }
27
+ }
28
+ })
29
+ if(needClears.length>0){
30
+ console.log(`以下缓存目录可以被清理:`);
31
+ needClears.forEach(file=>{
32
+ console.log(`${file}`);
33
+ })
34
+ answer = await inquirer.prompt([
35
+ {
36
+ name:'isClear',
37
+ type:'list',
38
+ message:'请选择是否清理这些项目的缓存:',
39
+ choices:['放弃清理','清理'],
40
+ default:'放弃清理'
41
+ },
42
+ ]);
43
+ if(answer.isClear == '清理'){
44
+ for(let dir of needClears){
45
+ try{
46
+ const filename = path.resolve(tempDir,dir);
47
+ console.log(`清理[${dir}]...`)
48
+ fs.rmdirSync(filename,{recursive:true,force:true});
49
+ console.log(`清理[${dir}]完毕`)
50
+ }catch(ex2){
51
+ console.log(`清理失败:`,ex2)
52
+ }
53
+ }
54
+
55
+ }
56
+
57
+ }else{
58
+ console.log('没有可清理的项目')
59
+ }
60
+ }catch(err){
61
+ throw new Error(err);
62
+ }
63
+ return 1;
64
+ }
package/src/cli.js CHANGED
@@ -5,6 +5,10 @@ const chalk = require("chalk");
5
5
  const createProject = require("./create");
6
6
  const build = require('./build');
7
7
  const getTool = require("./getTools");
8
+ const clear = require("./clear");
9
+ const help = require("./help");
10
+
11
+
8
12
 
9
13
  // const path= require("path");
10
14
  // const ROOT=path.resolve(__dirname,"../");
@@ -23,7 +27,7 @@ module.exports=async (args)=> {
23
27
  return console.log(pjson.version);
24
28
  }
25
29
  console.log(logVersion);
26
- console.log(options);
30
+ // console.log(options);
27
31
  if(get(options,"install")){
28
32
  const req = await createProject(options);
29
33
  if(!req){
@@ -57,6 +61,25 @@ module.exports=async (args)=> {
57
61
  process.exit(2);
58
62
  }
59
63
  return 1;
64
+ }else if(get(options,"clear")){
65
+ const req = await clear(options);
66
+ if(!req){
67
+ process.exit(2);
68
+ }
69
+ return 1;
70
+ }else if(get(options,"help")){
71
+ const req = await help(options);
72
+ if(!req){
73
+ process.exit(2);
74
+ }
75
+ return 1;
76
+ }else{
77
+ console.log('命令格式错误,请参考下面:')
78
+ const req = await help(options);
79
+ if(!req){
80
+ process.exit(2);
81
+ }
82
+ return 1;
60
83
  }
61
84
 
62
85
  }
package/src/help.js ADDED
@@ -0,0 +1,11 @@
1
+
2
+ const path= require( "path");
3
+
4
+
5
+ module.exports=async ()=> {
6
+ console.log('--create:创建项目');
7
+ console.log('--v:检查cli版本号');
8
+ console.log('--tool:创建工具');
9
+ console.log('--clear:清理缓存目录');
10
+ return 1;
11
+ }
@@ -16,14 +16,14 @@ module.exports = {
16
16
  })
17
17
  })
18
18
  },
19
- cleanDir:function(dir,option){
19
+ cleanDir:function(dir,option={}){
20
20
  const {exclude} = option;
21
21
  return new Promise(resolve=>{
22
22
  let filename='';
23
23
  try{
24
24
  var files = fs.readdirSync(dir);
25
25
  files.forEach(file=>{
26
- if(exclude(file) == false){
26
+ if(!exclude || exclude(file) == false){
27
27
  filename = path.resolve(dir,file);
28
28
  const fileStat = fs.statSync(filename);
29
29
  if(fileStat.isDirectory()){
@@ -12,6 +12,14 @@ module.exports=function(rawArgs) {
12
12
  "--report":Boolean,
13
13
  "-v": "--version",//-v 转译成 --version
14
14
  "--tool":Boolean,
15
+ "--clear":Boolean,// 清理缓存空间
16
+ "--help":Boolean,// 帮助,
17
+ "-h": "--help",
18
+ "--h":"--help",
19
+ "-help": "--help",
20
+ "-?": "--help",
21
+ "--?": "--help",
22
+
15
23
  },
16
24
  {
17
25
  permissive:true,
@@ -29,5 +37,8 @@ module.exports=function(rawArgs) {
29
37
  test: get(args, "--test", false),
30
38
  report: get(args, "--report", false),
31
39
  tool: get(args, "--tool", false),
40
+ clear: get(args, "--clear", false),
41
+ help: get(args, "--help", false),
42
+
32
43
  };
33
44
  }