submodule-version 1.0.2 → 1.1.0
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 +28 -19
- 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);
|
|
@@ -67,9 +79,9 @@ const buildGraph = (dependencies = {}, parent, location) => {
|
|
|
67
79
|
|
|
68
80
|
if (!dependencyIsInstalled) install(url, version, location);
|
|
69
81
|
const jsonString = fs.readFileSync(dependencyJSON, 'utf-8');
|
|
70
|
-
const {
|
|
82
|
+
const { sv } = JSON.parse(jsonString);
|
|
71
83
|
|
|
72
|
-
buildGraph(
|
|
84
|
+
buildGraph(sv, name, location);
|
|
73
85
|
});
|
|
74
86
|
};
|
|
75
87
|
|
|
@@ -87,8 +99,8 @@ const computeErrors = () => {
|
|
|
87
99
|
return errorList.join('\n');
|
|
88
100
|
};
|
|
89
101
|
|
|
90
|
-
const validate = (
|
|
91
|
-
buildGraph(
|
|
102
|
+
const validate = (sv, name) => {
|
|
103
|
+
buildGraph(sv, name, config.dir);
|
|
92
104
|
logger('Everything is up to date.');
|
|
93
105
|
const errors = computeErrors();
|
|
94
106
|
if (!errors) return;
|
|
@@ -96,7 +108,7 @@ const validate = (wv, name) => {
|
|
|
96
108
|
};
|
|
97
109
|
|
|
98
110
|
const checkoutModule = (url, version) => {
|
|
99
|
-
const module = isGitUrl(url) ? `${
|
|
111
|
+
const module = isGitUrl(url) ? `${config.dir}/${getName(url)}` : url;
|
|
100
112
|
logger('checkout', module);
|
|
101
113
|
try {
|
|
102
114
|
execSync(`git -C ${module} checkout ${version} -q`);
|
|
@@ -106,42 +118,39 @@ const checkoutModule = (url, version) => {
|
|
|
106
118
|
};
|
|
107
119
|
|
|
108
120
|
const validationCommand = () => {
|
|
109
|
-
const { name,
|
|
110
|
-
validate(
|
|
121
|
+
const { name, sv } = readProjectJSON();
|
|
122
|
+
validate(sv, name);
|
|
111
123
|
};
|
|
112
124
|
|
|
113
125
|
const installCommand = arg => {
|
|
114
126
|
const { url } = arg;
|
|
115
127
|
const versionMatch = VERSION_REGEX.exec(url) || [];
|
|
116
|
-
const [, gitaddress = url, version =
|
|
128
|
+
const [, gitaddress = url, version = config.tag] = versionMatch;
|
|
117
129
|
|
|
118
130
|
if (!isGitUrl(gitaddress)) {
|
|
119
131
|
abort(gitaddress, 'is not a git URL');
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
const projectJSON = readProjectJSON();
|
|
123
|
-
const installedDep = projectJSON.
|
|
135
|
+
const installedDep = projectJSON.sv?.[gitaddress];
|
|
124
136
|
|
|
125
137
|
if (installedDep && installedDep !== version) {
|
|
126
138
|
checkoutModule(gitaddress, version);
|
|
127
139
|
}
|
|
128
140
|
|
|
129
|
-
const
|
|
130
|
-
...(projectJSON.
|
|
131
|
-
|
|
132
|
-
...(projectJSON.wv?.dependencies || {}),
|
|
133
|
-
[gitaddress]: version,
|
|
134
|
-
},
|
|
141
|
+
const sv = {
|
|
142
|
+
...(projectJSON.sv || {}),
|
|
143
|
+
[gitaddress]: version,
|
|
135
144
|
};
|
|
136
145
|
|
|
137
146
|
if (!installedDep || installedDep !== version) {
|
|
138
|
-
writeProjectJSON({ ...projectJSON,
|
|
147
|
+
writeProjectJSON({ ...projectJSON, sv });
|
|
139
148
|
}
|
|
140
|
-
validate(
|
|
149
|
+
validate(sv, projectJSON.name);
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
144
|
-
yargs.scriptName('
|
|
153
|
+
yargs.scriptName('sv')
|
|
145
154
|
.usage('$0 <cmd> [args]')
|
|
146
155
|
.command(
|
|
147
156
|
['validate', '$0', 'v'],
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "submodule-version",
|
|
3
|
-
"description": "Git
|
|
4
|
-
"version": "1.0
|
|
3
|
+
"description": "Git <S>ubmodule <V>ersioning tool",
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"bin": {
|
|
6
|
-
"
|
|
6
|
+
"sv": "index.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"lint": "npx eslint"
|