Skip to content

Commit ca3ebf5

Browse files
author
Michael W Powell
committed
rinse and repeat internal package distribution update
1 parent 50c207a commit ca3ebf5

File tree

3 files changed

+97
-77
lines changed

3 files changed

+97
-77
lines changed

src/ExtensionsJS.Math/gulpfile.js

Lines changed: 95 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ var crc2json = require("crc2json");
3131
var cfg = {
3232
name: "extensionsjs-math",
3333
src: "math.js",
34+
minSrc: "math.min.js",
3435
pkgJson: "package.json",
3536
rootDir: path.join(".", "Scripts", "ExtensionsJS"),
3637
binDir: path.join(".", "bin"),
3738
specDirs: path.join(".", "spec", "**"),
3839
distDir: path.join(".", "bin", "dist"),
3940
gitDir: ".git",
40-
regRootDir: path.join("..", "..", "..", "..", "Node.js", "Registries")
41+
/* Make sure that projects are Cloned with sufficient directory depth in order to allow
42+
Registries publication, i.e. /source/company/js/ExtensionsJS/repoClone/src/projectName/.../.
43+
4. 3. 2. 1. */
44+
regRootDir: path.resolve(path.join("..", "..", "..", "..", "Node.js", "Registries")).replace(/\\/g, "/")
4145
};
4246

4347
/* TODO: TBD: So much of this is still very much boilerplace, which is the intended goal. */
@@ -112,7 +116,9 @@ gulp.task("createTarballPackage",
112116

113117
gulp.task("createPackageRegistryDir",
114118
function() {
115-
var repoDir = path.resolve(path.join(cfg.regRootDir, cfg.name)).replace(/\\/g, "/");
119+
// We will assume that the Version has been appropriately bumped.
120+
var version = json.sync(path.join(cfg.binDir, cfg.pkgJson)).version;
121+
var repoDir = path.join(path.join(cfg.regRootDir, cfg.name, version));
116122
if (fs.exists(repoDir)) {
117123
console.log("Package registry directory '" + repoDir + "' exists.");
118124
} else {
@@ -121,86 +127,100 @@ gulp.task("createPackageRegistryDir",
121127
}
122128
});
123129

124-
gulp.task("publishPackageToLocalRegistry",
125-
["createTarballPackage", "createPackageRegistryDir"],
130+
// TODO: TBD: rinse and repeat from Array ExtensionsJS...
131+
gulp.task("publishPackageToLocalDir",
132+
["minify", "stage", "createPackageRegistryDir"],
126133
function() {
127-
var repoDir = path.join(cfg.regRootDir, cfg.name);
128-
git.cwd(repoDir);
129-
var tarballName = cfg.name + ".tar.gz";
130-
var commitAndTagPackage = () => {
131-
var pkg = json.sync(path.join(cfg.binDir, cfg.pkgJson));
132-
// We will assume that the Version has been appropriately bumped.
133-
var version = pkg.version;
134-
git.commit("publishing package version " + version,
135-
tarballName,
136-
cerr => {
137-
if (cerr) {
138-
throw cerr;
134+
var version = json.sync(path.join(cfg.binDir, cfg.pkgJson)).version;
135+
var repoDir = path.join(cfg.regRootDir, cfg.name, version).replace(/\\/g, "/");
136+
var items = [
137+
{ name: cfg.src },
138+
{ name: cfg.minSrc },
139+
{ name: cfg.pkgJson }
140+
];
141+
var processedItems = [];
142+
var archive = function() {
143+
if (!processedItems.length) {
144+
return;
145+
}
146+
var commitPackages = function() {
147+
git.commit("publishing " + cfg.name + " " + version);
148+
};
149+
var addPackages = function() {
150+
git.cwd(repoDir);
151+
var addingItems = [];
152+
var updatingItems = [];
153+
for (var j = 0; j < processedItems.length; j++) {
154+
if (processedItems[j].adding) {
155+
addingItems.push(processedItems[j].name);
139156
}
140-
git.tag([version, "--force"],
141-
terr => {
142-
if (terr) {
143-
throw terr;
144-
}
145-
});
146-
});
147-
};
148-
var doPublish = () => {
149-
var srcDir = cfg.distDir;
150-
var copyOpts = { matching: tarballName };
151-
if (fs.exists(path.join(repoDir, tarballName))) {
152-
/* We need to compare a couple of CRC32 results in order to determine whether to
153-
copy in the first place. Note, due to the asynchronous nature of these callbacks,
154-
we need to be careful about what to nest during which callback. */
155-
var processPathCrc = (rootDir, callback) => {
156-
crc2json(rootDir,
157-
map => {
158-
// We need to sift through the entries for the requested value.
159-
var value = undefined;
160-
// ReSharper disable once MissingHasOwnPropertyInForeach
161-
for (var k in map) {
162-
// Checking for having own property does not work here for whatever reason.
163-
if (k.endsWith(tarballName)) {
164-
value = map[k];
165-
break;
166-
}
167-
}
168-
callback(value);
157+
if (processedItems[j].updating) {
158+
updatingItems.push(processedItems[j].name);
159+
}
160+
}
161+
if (addingItems.length) {
162+
git.add(addingItems,
163+
() => {
164+
commitPackages();
169165
});
170-
};
171-
processPathCrc(srcDir,
172-
x => {
173-
processPathCrc(repoDir,
174-
y => {
175-
copyOpts.overwrite = () => x !== y;
176-
fs.copy(srcDir, repoDir, copyOpts);
177-
commitAndTagPackage();
178-
});
179-
});
180-
} else {
181-
/* Otherwise, simply copy the package when it does not exist. We must still
182-
specify overwrite, even though technically there is nothing to overwrite. */
183-
copyOpts.overwrite = () => true;
184-
fs.copy(srcDir, repoDir, copyOpts);
185-
git.add([tarballName]);
186-
commitAndTagPackage();
187-
}
188-
};
189-
// ReSharper disable once PossiblyUnassignedProperty
190-
if (fs.exists(path.join(repoDir, cfg.gitDir)) &&
191-
git.checkIsRepo(err => {
192-
if (err) {
193-
throw err;
166+
} else if (updatingItems.length) {
167+
commitPackages();
194168
}
195-
})) {
196-
doPublish();
197-
} else {
198-
git.init(false,
199-
err => {
169+
};
170+
git.cwd(cfg.regRootDir);
171+
if (fs.exists(path.join(cfg.regRootDir, cfg.gitDir).replace(/\\/g, "/")) &&
172+
// ReSharper disable once PossiblyUnassignedProperty
173+
git.checkIsRepo(err => {
200174
if (err) {
201175
throw err;
202176
}
203-
doPublish();
177+
})) {
178+
addPackages();
179+
} else {
180+
git.init(false,
181+
err => {
182+
if (err) {
183+
throw err;
184+
}
185+
addPackages();
186+
});
187+
}
188+
};
189+
var processPathCrc = (rootDir, info, callback) => {
190+
crc2json(rootDir,
191+
map => {
192+
// We need to sift through the entries for the requested value.
193+
var value = undefined;
194+
// ReSharper disable once MissingHasOwnPropertyInForeach
195+
for (var k in map) {
196+
// Checking for having own property does not work here for whatever reason.
197+
if (k.endsWith(info.name)) {
198+
value = map[k];
199+
break;
200+
}
201+
}
202+
callback(info, value);
203+
});
204+
};
205+
for (var i = 0; i < items.length; i++) {
206+
/* We are likely to get tripped up over the timing of functional callbacks here. But
207+
we will make an effort to string together the series of events that we are interested
208+
in achieving. */
209+
processPathCrc(cfg.binDir,
210+
items[i],
211+
(a, x) => {
212+
processPathCrc(repoDir,
213+
a,
214+
(b, y) => {
215+
var src = path.join(cfg.binDir, b.name).replace(/\\/g, "/");
216+
var dest = path.join(repoDir, b.name).replace(/\\/g, "/");
217+
b.adding = x && y === undefined;
218+
b.updating = x && y && x !== y;
219+
fs.copy(src, dest, { overwrite: b.adding || b.updating });
220+
if (processedItems.push(b) === items.length) {
221+
archive();
222+
}
223+
});
204224
});
205225
}
206226
});

src/ExtensionsJS.Math/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ExtensionsJS.Math/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "extensionsjs-math",
33
"description": "Provides useful methods extending Math functionality.",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"author": "Michael W Powell",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)