@farris/cli 1.0.1 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/ci/cli.js +124 -107
  3. package/package.json +25 -25
package/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # farris-cli
2
-
1
+ # farris-cli
2
+
package/ci/cli.js CHANGED
@@ -1,107 +1,124 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const childProcess = require("@lerna/child-process");
8
-
9
- const yargs = require('yargs/yargs');
10
- const cli = yargs(process.argv.slice(2), process.cwd())
11
-
12
- cli
13
- .command(
14
- 'prerelease',
15
- 'Update package prerelease version when package has changed.',
16
- (yargs) => {
17
- return yargs;
18
- },
19
- (argv) => {
20
- const project = argv.project;
21
- let chain = Promise.resolve();
22
-
23
- chain = chain.then(() => checkProjectChanges(project));
24
- chain = chain.then((hasChanged) => {
25
- if (hasChanged) {
26
- return updateProjectPrereleaseVersion(project)
27
- }
28
- });
29
- }
30
- )
31
- .command(
32
- 'publish',
33
- 'Publish package which has changed sence last commit.',
34
- (yargs) => {
35
- return yargs;
36
- },
37
- (argv) => {
38
- const project = argv.project;
39
- let chain = Promise.resolve();
40
-
41
- chain = chain.then(() => checkProjectChanges(project));
42
- chain = chain.then((hasChanged) => {
43
- if (hasChanged) {
44
- return publish(project)
45
- }
46
- });
47
- }
48
- )
49
- .argv;
50
-
51
- /**
52
- * 检查指定工程目录下是否存在变更文件
53
- * @param {string} projectPath 目标工程路径
54
- * @returns 检查结果
55
- */
56
- function checkProjectChanges(projectPath) {
57
- return childProcess
58
- // 使用 git diff 命令查询自上传提交以来,目标工程路径下是否有变更的文件
59
- .exec("git", ["diff", "--name-only", "HEAD^", projectPath])
60
- .then((returnValue) => {
61
- // 提取命令输出结果中的文件集合
62
- const changedFiles = returnValue.stdout.split("\n").filter(Boolean);
63
- // 根据文件个数确定是否存在变更
64
- const hasChanges = changedFiles.length > 0;
65
- // 返回检测结果
66
- return hasChanges;
67
- });
68
- }
69
-
70
- /**
71
- * 更新指定工程的预发布版本
72
- * @param {string} projectPath 目标工程路径
73
- * @returns 更新后的版本
74
- */
75
- function updateProjectPrereleaseVersion(projectPath) {
76
- return childProcess
77
- // 使用 npm version prerelease 更新指定工程的预发布版本
78
- .exec('npm', ['version', 'prerelease', '--preid=beta', '--prefix', projectPath])
79
- .then((returnValue) => {
80
- // 读取目标工程的package.json文件
81
- const packageJsonFilePath = `${projectPath}/package.json`;
82
- const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
83
- // 提取更新后的版本
84
- const updatedVersion = returnValue.stdout;
85
- // 向git缓冲区中添加变更
86
- childProcess.execSync('git', ['add', '.']);
87
- // 提交变更记录
88
- childProcess.execSync('git', ['commit', '-m', `update ${packageConfig.name} prerelease version to ${updatedVersion}`]);
89
- // 提交变更集
90
- return childProcess.exec('git', ['push']);
91
- })
92
- }
93
-
94
- /**
95
- * 发布指定路径下的npm包
96
- * @param {string} projectPath 目标工程路径
97
- * @returns 发布结果
98
- */
99
- function publish(projectPath) {
100
- // 读取目标工程的package.json文件
101
- const ngPackageJsonFilePath = `${projectPath}/ng-package.json`;
102
- const ngPackageConfig = JSON.parse(fs.readFileSync(ngPackageJsonFilePath, 'utf-8'));
103
- const dest = ngPackageConfig.dest;
104
- const packagePath = path.normalize(`${projectPath}/${dest}`);
105
- // 调用 npm publish 发布指定路径下的npm包
106
- return childProcess.exec('npm', ['publish', packagePath])
107
- }
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const childProcess = require("@lerna/child-process");
8
+
9
+ const yargs = require('yargs/yargs');
10
+ const cli = yargs(process.argv.slice(2), process.cwd())
11
+
12
+ cli
13
+ .command(
14
+ 'check',
15
+ 'check file changes from last commit.',
16
+ (yargs) => {
17
+ return yargs;
18
+ },
19
+ (argv) => {
20
+ const project = argv.project;
21
+ checkProjectChanges(project);
22
+ }
23
+ )
24
+ .command(
25
+ 'prerelease',
26
+ 'Update package prerelease version when package has changed.',
27
+ (yargs) => {
28
+ return yargs;
29
+ },
30
+ (argv) => {
31
+ const project = argv.project;
32
+ let chain = Promise.resolve();
33
+
34
+ chain = chain.then(() => checkProjectChanges(project));
35
+ chain = chain.then((hasChanged) => {
36
+ if (hasChanged) {
37
+ return updateProjectPrereleaseVersion(project)
38
+ }
39
+ });
40
+ }
41
+ )
42
+ .command(
43
+ 'publish',
44
+ 'Publish package which has changed sence last commit.',
45
+ (yargs) => {
46
+ return yargs;
47
+ },
48
+ (argv) => {
49
+ const project = argv.project;
50
+ let chain = Promise.resolve();
51
+
52
+ chain = chain.then(() => checkProjectChanges(project));
53
+ chain = chain.then((hasChanged) => {
54
+ if (hasChanged) {
55
+ return publish(project)
56
+ }
57
+ });
58
+ }
59
+ )
60
+ .argv;
61
+
62
+ /**
63
+ * 检查指定工程目录下是否存在变更文件
64
+ * @param {string} projectPath 目标工程路径
65
+ * @returns 检查结果
66
+ */
67
+ function checkProjectChanges(projectPath) {
68
+ return childProcess
69
+ // 使用 git diff 命令查询自上传提交以来,目标工程路径下是否有变更的文件
70
+ .exec("git", ["diff", "--name-only", "HEAD^", projectPath])
71
+ .then((returnValue) => {
72
+ // 提取命令输出结果中的文件集合
73
+ const changedFiles = returnValue.stdout.split("\n").filter(Boolean);
74
+ // 根据文件个数确定是否存在变更
75
+ const hasChanges = changedFiles.length > 0;
76
+ if (hasChanges) {
77
+ console.log(`${projectPath} has changed.`)
78
+ } else {
79
+ console.log(`Did not detect any changes from ${projectPath} sence last commit.`)
80
+ }
81
+ // 返回检测结果
82
+ return hasChanges;
83
+ });
84
+ }
85
+
86
+ /**
87
+ * 更新指定工程的预发布版本
88
+ * @param {string} projectPath 目标工程路径
89
+ * @returns 更新后的版本
90
+ */
91
+ function updateProjectPrereleaseVersion(projectPath) {
92
+ return childProcess
93
+ // 使用 npm version prerelease 更新指定工程的预发布版本
94
+ .exec('npm', ['version', 'prerelease', '--preid=beta', '--prefix', projectPath])
95
+ .then((returnValue) => {
96
+ // 读取目标工程的package.json文件
97
+ const packageJsonFilePath = `${projectPath}/package.json`;
98
+ const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
99
+ // 提取更新后的版本
100
+ const updatedVersion = returnValue.stdout;
101
+ // 向git缓冲区中添加变更
102
+ childProcess.execSync('git', ['add', '.']);
103
+ // 提交变更记录
104
+ childProcess.execSync('git', ['commit', '-m', `update ${packageConfig.name} prerelease version to ${updatedVersion}`]);
105
+ console.log(`update ${packageConfig.name} prerelease version to ${updatedVersion}`);
106
+ // 提交变更集
107
+ return childProcess.exec('git', ['push']);
108
+ })
109
+ }
110
+
111
+ /**
112
+ * 发布指定路径下的npm包
113
+ * @param {string} projectPath 目标工程路径
114
+ * @returns 发布结果
115
+ */
116
+ function publish(projectPath) {
117
+ // 读取目标工程的package.json文件
118
+ const ngPackageJsonFilePath = `${projectPath}/ng-package.json`;
119
+ const ngPackageConfig = JSON.parse(fs.readFileSync(ngPackageJsonFilePath, 'utf-8'));
120
+ const dest = ngPackageConfig.dest;
121
+ const packagePath = path.normalize(`${projectPath}/${dest}`);
122
+ // 调用 npm publish 发布指定路径下的npm包
123
+ return childProcess.exec('npm', ['publish', packagePath])
124
+ }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
- {
2
- "name": "@farris/cli",
3
- "version": "1.0.1",
4
- "description": "Farris command line interface",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "https://git.iec.io/webadp/farris-cli.git"
12
- },
13
- "keywords": [
14
- "Farris",
15
- "CLI"
16
- ],
17
- "bin": {
18
- "farris": "ci/cli.js"
19
- },
20
- "author": "Sagi Chen",
21
- "license": "ISC",
22
- "dependencies": {
23
- "lerna": "^4.0.0"
24
- }
25
- }
1
+ {
2
+ "name": "@farris/cli",
3
+ "version": "1.0.4",
4
+ "description": "Farris command line interface",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://git.iec.io/webadp/farris-cli.git"
12
+ },
13
+ "keywords": [
14
+ "Farris",
15
+ "CLI"
16
+ ],
17
+ "bin": {
18
+ "farris": "ci/cli.js"
19
+ },
20
+ "author": "Sagi Chen",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "lerna": "^4.0.0"
24
+ }
25
+ }