submodule-version 1.0.1 → 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.
Files changed (3) hide show
  1. package/README.md +12 -7
  2. package/index.js +31 -22
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Install or update
2
2
 
3
- `npx sw i repo.git`
4
- `npx sw i repo.git@1.0.0`
5
- `npx sw install repo.git@1.0.0`
6
- `npx sw i repo.git@master`
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 sw`
11
- `npx sw v`
12
- `npx sw validate`
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
- const DEFAULT_DIR = 'modules';
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 { wv: depWV = {} } = JSON.parse(jsonString);
82
+ const { sv } = JSON.parse(jsonString);
71
83
 
72
- buildGraph(depWV.dependencies, name, location);
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 = (wv, name) => {
91
- buildGraph(wv.dependencies, name, wv?.dir || DEFAULT_DIR);
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,52 +108,49 @@ const validate = (wv, name) => {
96
108
  };
97
109
 
98
110
  const checkoutModule = (url, version) => {
99
- const module = isGitUrl(url) ? `${DEFAULT_DIR}/${getName(url)}` : url;
111
+ const module = isGitUrl(url) ? `${config.dir}/${getName(url)}` : url;
100
112
  logger('checkout', module);
101
113
  try {
102
- execSync(`git -C ${module} checkout ${version}`);
114
+ execSync(`git -C ${module} checkout ${version} -q`);
103
115
  } catch {
104
116
  abort('Checkout failded');
105
117
  };
106
118
  };
107
119
 
108
120
  const validationCommand = () => {
109
- const { name, wv } = readProjectJSON();
110
- validate(wv, name);
121
+ const { name, sv } = readProjectJSON();
122
+ validate(sv, name);
111
123
  };
112
124
 
113
- const makeInstallCommand = arg => {
125
+ const installCommand = arg => {
114
126
  const { url } = arg;
115
127
  const versionMatch = VERSION_REGEX.exec(url) || [];
116
- const [, gitaddress = url, version = 'master'] = versionMatch;
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?.wv.dependencies?.[gitaddress];
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 wv = {
130
- ...(projectJSON.wv || {}),
131
- dependencies: {
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, wv });
147
+ writeProjectJSON({ ...projectJSON, sv });
139
148
  }
140
- validate(wv, projectJSON.name);
149
+ validate(sv, projectJSON.name);
141
150
  };
142
151
 
143
152
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
144
- yargs.scriptName('wv')
153
+ yargs.scriptName('sv')
145
154
  .usage('$0 <cmd> [args]')
146
155
  .command(
147
156
  ['validate', '$0', 'v'],
@@ -156,7 +165,7 @@ yargs.scriptName('wv')
156
165
  type: 'string',
157
166
  describe: 'git submodule url',
158
167
  }),
159
- makeInstallCommand,
168
+ installCommand,
160
169
  )
161
170
  .help()
162
171
  .argv;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "submodule-version",
3
- "description": "Git submodule versioning tool",
4
- "version": "1.0.1",
3
+ "description": "Git <S>ubmodule <V>ersioning tool",
4
+ "version": "1.1.0",
5
5
  "bin": {
6
- "sw": "index.js"
6
+ "sv": "index.js"
7
7
  },
8
8
  "scripts": {
9
9
  "lint": "npx eslint"