submodule-version 1.0.2 → 1.1.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.
- package/README.md +12 -7
- package/index.js +47 -32
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# Install or update
|
|
2
2
|
|
|
3
|
-
`npx
|
|
4
|
-
|
|
5
|
-
`npx
|
|
6
|
-
|
|
3
|
+
`npx sv i repo.git`
|
|
4
|
+
|
|
5
|
+
`npx sv i repo.git@1.0.0`
|
|
6
|
+
|
|
7
|
+
`npx sv install repo.git@1.0.0`
|
|
8
|
+
|
|
9
|
+
`npx sv i repo.git@master`
|
|
7
10
|
|
|
8
11
|
# Validate
|
|
9
12
|
|
|
10
|
-
`npx
|
|
11
|
-
|
|
12
|
-
`npx
|
|
13
|
+
`npx sv`
|
|
14
|
+
|
|
15
|
+
`npx sv v`
|
|
16
|
+
|
|
17
|
+
`npx sv validate`
|
package/index.js
CHANGED
|
@@ -7,7 +7,11 @@ const yargs = require('yargs');
|
|
|
7
7
|
const JSON_NAME = 'package.json';
|
|
8
8
|
const cwd = process.cwd();
|
|
9
9
|
const VERSION_REGEX = /(^.*@.*)@(.*)$/;
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
const config = {
|
|
12
|
+
dir: 'modules',
|
|
13
|
+
tag: 'master',
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
const logger = (...message) => {
|
|
13
17
|
// eslint-disable-next-line no-console
|
|
@@ -19,6 +23,14 @@ const abort = (...message) => {
|
|
|
19
23
|
yargs.exit(1, message.join(' '));
|
|
20
24
|
};
|
|
21
25
|
|
|
26
|
+
const configPath = path.join(cwd, '.sw.config.json');
|
|
27
|
+
|
|
28
|
+
if (fs.existsSync(configPath)) {
|
|
29
|
+
const { dir, tag } = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
30
|
+
if (dir) config.dir = dir;
|
|
31
|
+
if (tag) config.tag = tag;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
const readProjectJSON = () => {
|
|
23
35
|
const jsonPath = path.join(cwd, JSON_NAME);
|
|
24
36
|
const isJsonExists = fs.existsSync(jsonPath);
|
|
@@ -41,12 +53,23 @@ const getName = url => {
|
|
|
41
53
|
return parts[parts.length - 1];
|
|
42
54
|
};
|
|
43
55
|
|
|
56
|
+
const checkout = (url, version) => {
|
|
57
|
+
const module = isGitUrl(url) ? `${config.dir}/${getName(url)}` : url;
|
|
58
|
+
logger('checkout', module);
|
|
59
|
+
try {
|
|
60
|
+
execSync(`git -C ${module} checkout ${version} -q`);
|
|
61
|
+
} catch {
|
|
62
|
+
abort('Checkout failded');
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
44
66
|
const install = (url, version, location) => {
|
|
45
67
|
const name = getName(url);
|
|
46
68
|
const targetLocation = path.join(location, name);
|
|
47
|
-
const gitCmd = `git submodule add
|
|
69
|
+
const gitCmd = `git submodule add ${url} ${targetLocation}`;
|
|
48
70
|
try {
|
|
49
71
|
execSync(gitCmd);
|
|
72
|
+
checkout(url, version);
|
|
50
73
|
} catch {
|
|
51
74
|
abort(url, 'Is not a git repo');
|
|
52
75
|
}
|
|
@@ -67,9 +90,9 @@ const buildGraph = (dependencies = {}, parent, location) => {
|
|
|
67
90
|
|
|
68
91
|
if (!dependencyIsInstalled) install(url, version, location);
|
|
69
92
|
const jsonString = fs.readFileSync(dependencyJSON, 'utf-8');
|
|
70
|
-
const {
|
|
93
|
+
const { sv } = JSON.parse(jsonString);
|
|
71
94
|
|
|
72
|
-
buildGraph(
|
|
95
|
+
buildGraph(sv, name, location);
|
|
73
96
|
});
|
|
74
97
|
};
|
|
75
98
|
|
|
@@ -87,61 +110,53 @@ const computeErrors = () => {
|
|
|
87
110
|
return errorList.join('\n');
|
|
88
111
|
};
|
|
89
112
|
|
|
90
|
-
const validate = (
|
|
91
|
-
buildGraph(
|
|
92
|
-
|
|
113
|
+
const validate = (sv, name) => {
|
|
114
|
+
buildGraph(sv, name, config.dir);
|
|
115
|
+
|
|
93
116
|
const errors = computeErrors();
|
|
94
|
-
if (
|
|
95
|
-
abort(errors);
|
|
96
|
-
};
|
|
117
|
+
if (errors) abort(errors);
|
|
97
118
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} catch {
|
|
104
|
-
abort('Checkout failded');
|
|
105
|
-
};
|
|
119
|
+
Object.entries(graph).forEach(([url, versions]) => {
|
|
120
|
+
checkout(url, versions[0]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
logger('Everything is up to date.');
|
|
106
124
|
};
|
|
107
125
|
|
|
108
126
|
const validationCommand = () => {
|
|
109
|
-
const { name,
|
|
110
|
-
validate(
|
|
127
|
+
const { name, sv } = readProjectJSON();
|
|
128
|
+
validate(sv, name);
|
|
111
129
|
};
|
|
112
130
|
|
|
113
131
|
const installCommand = arg => {
|
|
114
132
|
const { url } = arg;
|
|
115
133
|
const versionMatch = VERSION_REGEX.exec(url) || [];
|
|
116
|
-
const [, gitaddress = url, version =
|
|
134
|
+
const [, gitaddress = url, version = config.tag] = versionMatch;
|
|
117
135
|
|
|
118
136
|
if (!isGitUrl(gitaddress)) {
|
|
119
137
|
abort(gitaddress, 'is not a git URL');
|
|
120
138
|
}
|
|
121
139
|
|
|
122
140
|
const projectJSON = readProjectJSON();
|
|
123
|
-
const installedDep = projectJSON.
|
|
141
|
+
const installedDep = projectJSON.sv?.[gitaddress];
|
|
124
142
|
|
|
125
143
|
if (installedDep && installedDep !== version) {
|
|
126
|
-
|
|
144
|
+
checkout(gitaddress, version);
|
|
127
145
|
}
|
|
128
146
|
|
|
129
|
-
const
|
|
130
|
-
...(projectJSON.
|
|
131
|
-
|
|
132
|
-
...(projectJSON.wv?.dependencies || {}),
|
|
133
|
-
[gitaddress]: version,
|
|
134
|
-
},
|
|
147
|
+
const sv = {
|
|
148
|
+
...(projectJSON.sv || {}),
|
|
149
|
+
[gitaddress]: version,
|
|
135
150
|
};
|
|
136
151
|
|
|
137
152
|
if (!installedDep || installedDep !== version) {
|
|
138
|
-
writeProjectJSON({ ...projectJSON,
|
|
153
|
+
writeProjectJSON({ ...projectJSON, sv });
|
|
139
154
|
}
|
|
140
|
-
validate(
|
|
155
|
+
validate(sv, projectJSON.name);
|
|
141
156
|
};
|
|
142
157
|
|
|
143
158
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
144
|
-
yargs.scriptName('
|
|
159
|
+
yargs.scriptName('sv')
|
|
145
160
|
.usage('$0 <cmd> [args]')
|
|
146
161
|
.command(
|
|
147
162
|
['validate', '$0', 'v'],
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "submodule-version",
|
|
3
|
-
"description": "Git
|
|
4
|
-
"version": "1.
|
|
3
|
+
"description": "Git <S>ubmodule <V>ersioning tool",
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"bin": {
|
|
6
|
-
"
|
|
6
|
+
"sv": "index.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"lint": "npx eslint"
|