contensis-cli 1.0.0-beta.83 → 1.0.0-beta.85
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/dist/commands/dev.js +23 -2
- package/dist/commands/dev.js.map +2 -2
- package/dist/localisation/en-GB.js +52 -0
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/providers/file-provider.js +4 -2
- package/dist/providers/file-provider.js.map +2 -2
- package/dist/services/ContensisCliService.js +3 -53
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/services/ContensisDevService.js +203 -0
- package/dist/services/ContensisDevService.js.map +7 -0
- package/dist/shell.js +2 -9
- package/dist/shell.js.map +2 -2
- package/dist/util/git.js +119 -0
- package/dist/util/git.js.map +7 -0
- package/dist/util/os.js +39 -0
- package/dist/util/os.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +8 -2
- package/src/commands/dev.ts +29 -2
- package/src/localisation/en-GB.ts +85 -0
- package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/models/JsModules.d.ts +1 -0
- package/src/providers/file-provider.ts +5 -2
- package/src/services/ContensisCliService.ts +24 -78
- package/src/services/ContensisDevService.ts +243 -0
- package/src/shell.ts +3 -12
- package/src/util/git.ts +118 -0
- package/src/util/os.ts +7 -0
- package/src/version.ts +1 -1
package/src/util/git.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import giturl from 'giturl';
|
|
2
|
+
import hostedGitInfo from 'hosted-git-info';
|
|
3
|
+
import parseGitConfig from 'parse-git-config';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
import { linuxSlash } from './os';
|
|
7
|
+
import { readFile, readFiles } from '~/providers/file-provider';
|
|
8
|
+
|
|
9
|
+
const GITLAB_CI_FILENAME = '.gitlab-ci.yml';
|
|
10
|
+
|
|
11
|
+
type GitConfig = parseGitConfig.Config;
|
|
12
|
+
|
|
13
|
+
export type GitTypes = hostedGitInfo.Hosts;
|
|
14
|
+
|
|
15
|
+
export class GitHelper {
|
|
16
|
+
private gitRepoPath: string;
|
|
17
|
+
config = {} as GitConfig;
|
|
18
|
+
info: hostedGitInfo | undefined;
|
|
19
|
+
home: string | undefined;
|
|
20
|
+
|
|
21
|
+
get ciFileName() {
|
|
22
|
+
return this.workflows
|
|
23
|
+
? this.type === 'github'
|
|
24
|
+
? this.workflows.length > 1
|
|
25
|
+
? '[multiple workflows]'
|
|
26
|
+
: this.workflows?.[0]
|
|
27
|
+
: GITLAB_CI_FILENAME
|
|
28
|
+
: '[unknown]';
|
|
29
|
+
}
|
|
30
|
+
get name() {
|
|
31
|
+
return (
|
|
32
|
+
this.info?.project || this.home?.split('/').pop() || '[set arg --name]'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
get originUrl() {
|
|
36
|
+
return this.config.remote.origin.url;
|
|
37
|
+
}
|
|
38
|
+
get secretsUri() {
|
|
39
|
+
return `${
|
|
40
|
+
this.type === 'github'
|
|
41
|
+
? `${this.home}/settings/secrets/actions`
|
|
42
|
+
: `${this.home}/-/settings/ci_cd`
|
|
43
|
+
}`;
|
|
44
|
+
}
|
|
45
|
+
get type() {
|
|
46
|
+
return this.info?.type || this.hostType();
|
|
47
|
+
}
|
|
48
|
+
get workflows() {
|
|
49
|
+
return this.type === 'github'
|
|
50
|
+
? this.githubWorkflows()
|
|
51
|
+
: this.gitlabWorkflow();
|
|
52
|
+
}
|
|
53
|
+
constructor(gitRepoPath: string = process.cwd()) {
|
|
54
|
+
this.gitRepoPath = gitRepoPath;
|
|
55
|
+
this.config = this.gitConfig();
|
|
56
|
+
this.home = giturl.parse(this.originUrl);
|
|
57
|
+
this.info = this.gitInfo();
|
|
58
|
+
// console.log(this.config);
|
|
59
|
+
// console.log(this.home);
|
|
60
|
+
// console.log(this.info);
|
|
61
|
+
}
|
|
62
|
+
gitcwd = () => path.join(this.gitRepoPath);
|
|
63
|
+
gitInfo = (url: string = this.originUrl) => hostedGitInfo.fromUrl(url);
|
|
64
|
+
hostType = (url: string = this.originUrl): GitTypes => {
|
|
65
|
+
if (url.includes('github.com')) return 'github';
|
|
66
|
+
return 'gitlab';
|
|
67
|
+
// if (url.includes('gitlab.com')) return 'gl';
|
|
68
|
+
// if (url.includes('gitlab.zengenti.com')) return 'gl';
|
|
69
|
+
};
|
|
70
|
+
gitConfig = (cwd = this.gitRepoPath) => {
|
|
71
|
+
// Find .git/config in project cwd
|
|
72
|
+
const config = parseGitConfig.sync({
|
|
73
|
+
path: '.git/config',
|
|
74
|
+
expandKeys: true,
|
|
75
|
+
});
|
|
76
|
+
// console.log(cwd, config);
|
|
77
|
+
if (Object.keys(config || {}).length) return config;
|
|
78
|
+
|
|
79
|
+
// Recursively check the directory heirarchy for existance of a .git/config
|
|
80
|
+
const pathParts = linuxSlash(cwd).split('/');
|
|
81
|
+
for (let i = 1; i <= pathParts.length; i++) {
|
|
82
|
+
const relPath = `${Array(i).fill('..').join('/')}/.git/config`;
|
|
83
|
+
// Does not appear to work when using a shortened cwd, using relative path instead
|
|
84
|
+
const config = parseGitConfig.sync({
|
|
85
|
+
path: relPath,
|
|
86
|
+
expandKeys: true,
|
|
87
|
+
});
|
|
88
|
+
// console.log(relPath, config);
|
|
89
|
+
if (Object.keys(config || {}).length) {
|
|
90
|
+
this.gitRepoPath = path.join(
|
|
91
|
+
this.gitRepoPath,
|
|
92
|
+
Array(i).fill('..').join('/')
|
|
93
|
+
);
|
|
94
|
+
return config;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return config;
|
|
98
|
+
};
|
|
99
|
+
githubWorkflows = () => {
|
|
100
|
+
const workflowPath = path.join(this.gitcwd(), '.github/workflows');
|
|
101
|
+
const workflowFiles = readFiles(workflowPath, false);
|
|
102
|
+
// console.log('gh workflows: ', workflowFiles);
|
|
103
|
+
const addFolderSuffix = (files: string[]) =>
|
|
104
|
+
files.map(f => `.github/workflows/${f}`);
|
|
105
|
+
|
|
106
|
+
if (workflowFiles.some(f => f.includes('build')))
|
|
107
|
+
return addFolderSuffix(workflowFiles.filter(f => f.includes('build')));
|
|
108
|
+
return addFolderSuffix(workflowFiles);
|
|
109
|
+
};
|
|
110
|
+
gitlabWorkflow = (ciFileName = GITLAB_CI_FILENAME) => {
|
|
111
|
+
const workflowPath = this.gitcwd();
|
|
112
|
+
const workflowFilePath = path.join(workflowPath, ciFileName);
|
|
113
|
+
const workflowFile = readFile(workflowFilePath);
|
|
114
|
+
// console.log(ciFileName, workflowFile);
|
|
115
|
+
|
|
116
|
+
return workflowFile;
|
|
117
|
+
};
|
|
118
|
+
}
|
package/src/util/os.ts
ADDED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.0-beta.
|
|
1
|
+
export const LIB_VERSION = "1.0.0-beta.85";
|