submodule-version 1.1.4 → 2.0.2
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 +52 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__tests__/parseGitUrl.test.d.ts +1 -0
- package/dist/src/__tests__/parseGitUrl.test.js +30 -0
- package/dist/src/__tests__/parseGitUrl.test.js.map +1 -0
- package/dist/src/__tests__/versionUtil.test.d.ts +1 -0
- package/dist/src/__tests__/versionUtil.test.js +51 -0
- package/dist/src/__tests__/versionUtil.test.js.map +1 -0
- package/dist/src/buildGraph.d.ts +7 -0
- package/dist/src/buildGraph.js +73 -0
- package/dist/src/buildGraph.js.map +1 -0
- package/dist/src/config.d.ts +4 -0
- package/dist/src/config.js +8 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/git.d.ts +5 -0
- package/dist/src/git.js +54 -0
- package/dist/src/git.js.map +1 -0
- package/dist/src/install.d.ts +1 -0
- package/dist/src/install.js +43 -0
- package/dist/src/install.js.map +1 -0
- package/dist/src/log.d.ts +4 -0
- package/dist/src/log.js +20 -0
- package/dist/src/log.js.map +1 -0
- package/dist/src/parseGitUrl.d.ts +7 -0
- package/dist/src/parseGitUrl.js +26 -0
- package/dist/src/parseGitUrl.js.map +1 -0
- package/dist/src/pkgJsonUtil.d.ts +5 -0
- package/dist/src/pkgJsonUtil.js +38 -0
- package/dist/src/pkgJsonUtil.js.map +1 -0
- package/dist/src/submoduleVersion.d.ts +1 -0
- package/dist/src/submoduleVersion.js +43 -0
- package/dist/src/submoduleVersion.js.map +1 -0
- package/dist/src/versionUtil.d.ts +12 -0
- package/dist/src/versionUtil.js +68 -0
- package/dist/src/versionUtil.js.map +1 -0
- package/eslint.config.js +5 -0
- package/index-dev.ts +7 -0
- package/index.ts +3 -0
- package/jest.config.js +9 -0
- package/package.json +14 -4
- package/src/__tests__/parseGitUrl.test.ts +33 -0
- package/src/__tests__/versionUtil.test.ts +60 -0
- package/src/buildGraph.ts +105 -0
- package/src/config.ts +4 -0
- package/src/git.ts +51 -0
- package/src/install.ts +47 -0
- package/src/log.ts +16 -0
- package/src/parseGitUrl.ts +31 -0
- package/src/pkgJsonUtil.ts +36 -0
- package/src/submoduleVersion.ts +54 -0
- package/src/versionUtil.ts +82 -0
- package/tsconfig.json +30 -0
- package/index.js +0 -177
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"target": "es2020",
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noImplicitAny": false,
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"allowUmdGlobalAccess": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"baseUrl": "src",
|
|
20
|
+
"paths": {}
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src/**/*",
|
|
24
|
+
"index.ts"
|
|
25
|
+
],
|
|
26
|
+
"exclude": [
|
|
27
|
+
"node_modules",
|
|
28
|
+
"__tests__"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/index.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const { execSync } = require('child_process');
|
|
6
|
-
const yargs = require('yargs');
|
|
7
|
-
const JSON_NAME = 'package.json';
|
|
8
|
-
const cwd = process.cwd();
|
|
9
|
-
const VERSION_REGEX = /(^.*@.*)@(.*)$/;
|
|
10
|
-
|
|
11
|
-
const config = {
|
|
12
|
-
dir: 'modules',
|
|
13
|
-
tag: 'master',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const logger = (...message) => {
|
|
17
|
-
// eslint-disable-next-line no-console
|
|
18
|
-
console.log(...message);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const abort = (...message) => {
|
|
22
|
-
logger(...message);
|
|
23
|
-
yargs.exit(1, message.join(' '));
|
|
24
|
-
};
|
|
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
|
-
|
|
34
|
-
const readProjectJSON = () => {
|
|
35
|
-
const jsonPath = path.join(cwd, JSON_NAME);
|
|
36
|
-
const isJsonExists = fs.existsSync(jsonPath);
|
|
37
|
-
if (!isJsonExists) throw new Error(`${cwd} is not npm project`);
|
|
38
|
-
const jsonString = fs.readFileSync(jsonPath, 'utf-8');
|
|
39
|
-
|
|
40
|
-
return JSON.parse(jsonString);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const writeProjectJSON = data => {
|
|
44
|
-
fs.writeFileSync(path.join(cwd, JSON_NAME), JSON.stringify(data, null, 2));
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const isGitUrl = url => url.endsWith('.git');
|
|
48
|
-
|
|
49
|
-
const getName = url => {
|
|
50
|
-
if (isGitUrl(url)) return /\/(.*)\.git/.exec(url)[1];
|
|
51
|
-
const parts = url.split('/');
|
|
52
|
-
|
|
53
|
-
return parts[parts.length - 1];
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const checkout = (url, version) => {
|
|
57
|
-
const module = isGitUrl(url) ? `${config.dir}/${getName(url)}` : url;
|
|
58
|
-
logger('Verify or update', module, 'version');
|
|
59
|
-
try {
|
|
60
|
-
execSync(`git -C ${module} checkout ${version} -q`);
|
|
61
|
-
} catch {
|
|
62
|
-
abort('Checkout failded');
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const install = (url, version, location) => {
|
|
67
|
-
const name = getName(url);
|
|
68
|
-
const targetLocation = path.join(location, name);
|
|
69
|
-
const gitCmd = `git submodule add ${url} ${targetLocation}`;
|
|
70
|
-
try {
|
|
71
|
-
execSync(gitCmd);
|
|
72
|
-
checkout(url, version);
|
|
73
|
-
} catch {
|
|
74
|
-
abort(url, 'Is not a git repo');
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const graph = {};
|
|
79
|
-
|
|
80
|
-
const buildGraph = (dependencies = {}, parent, location) => {
|
|
81
|
-
Object.entries(dependencies).forEach(([url, version]) => {
|
|
82
|
-
const name = getName(url);
|
|
83
|
-
const dependencyJSON = path.join(cwd, location, name, JSON_NAME);
|
|
84
|
-
const dependencyIsInstalled = fs.existsSync(dependencyJSON);
|
|
85
|
-
|
|
86
|
-
graph[name] = {
|
|
87
|
-
...(graph[name] || {}),
|
|
88
|
-
[version]: [...(graph[name]?.[version] || []), parent],
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
if (!dependencyIsInstalled) install(url, version, location);
|
|
92
|
-
const jsonString = fs.readFileSync(dependencyJSON, 'utf-8');
|
|
93
|
-
const { sv } = JSON.parse(jsonString);
|
|
94
|
-
|
|
95
|
-
buildGraph(sv, name, location);
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const computeErrors = () => {
|
|
100
|
-
const errorList = Object.entries(graph).reduce((acc, [name, links]) => {
|
|
101
|
-
if (Object.keys(links).length <= 1) return acc;
|
|
102
|
-
|
|
103
|
-
const err = Object.entries(links).reduce((errAcc, [version, usedBy]) => (
|
|
104
|
-
`${errAcc} Version <${version}> used by: ${usedBy.join(', ')}.`
|
|
105
|
-
), `Confilict in module [${name}]!`);
|
|
106
|
-
|
|
107
|
-
return [...acc, err];
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
return errorList.join('\n');
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const validate = (sv, name) => {
|
|
114
|
-
buildGraph(sv, name, config.dir);
|
|
115
|
-
|
|
116
|
-
const errors = computeErrors();
|
|
117
|
-
if (errors) abort(errors);
|
|
118
|
-
|
|
119
|
-
Object.entries(graph).forEach(([moduleName, versions]) => {
|
|
120
|
-
checkout(`${config.dir}/${moduleName}`, Object.keys(versions)[0]);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
logger('Everything is up to date.');
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const validationCommand = () => {
|
|
127
|
-
const { name, sv } = readProjectJSON();
|
|
128
|
-
validate(sv, name);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const installCommand = arg => {
|
|
132
|
-
const { url } = arg;
|
|
133
|
-
const versionMatch = VERSION_REGEX.exec(url) || [];
|
|
134
|
-
const [, gitaddress = url, version = config.tag] = versionMatch;
|
|
135
|
-
|
|
136
|
-
if (!isGitUrl(gitaddress)) {
|
|
137
|
-
abort(gitaddress, 'is not a git URL');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const projectJSON = readProjectJSON();
|
|
141
|
-
const installedDep = projectJSON.sv?.[gitaddress];
|
|
142
|
-
|
|
143
|
-
if (installedDep && installedDep !== version) {
|
|
144
|
-
checkout(gitaddress, version);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const sv = {
|
|
148
|
-
...(projectJSON.sv || {}),
|
|
149
|
-
[gitaddress]: version,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
if (!installedDep || installedDep !== version) {
|
|
153
|
-
writeProjectJSON({ ...projectJSON, sv });
|
|
154
|
-
}
|
|
155
|
-
validate(sv, projectJSON.name);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
159
|
-
yargs.scriptName('sv')
|
|
160
|
-
.usage('$0 <cmd> [args]')
|
|
161
|
-
.command(
|
|
162
|
-
['validate', '$0', 'v'],
|
|
163
|
-
'Validate and install modules',
|
|
164
|
-
() => {},
|
|
165
|
-
validationCommand,
|
|
166
|
-
)
|
|
167
|
-
.command(
|
|
168
|
-
['install <url>', 'i'],
|
|
169
|
-
'Install new submodule',
|
|
170
|
-
y => y.positional('url', {
|
|
171
|
-
type: 'string',
|
|
172
|
-
describe: 'git submodule url',
|
|
173
|
-
}),
|
|
174
|
-
installCommand,
|
|
175
|
-
)
|
|
176
|
-
.help()
|
|
177
|
-
.argv;
|