Skip to content

Commit 50c207a

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

File tree

3 files changed

+98
-77
lines changed

3 files changed

+98
-77
lines changed

src/ExtensionsJS.Events/gulpfile.js

Lines changed: 96 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ var crc2json = require("crc2json");
3131
var cfg = {
3232
name: "extensionsjs-events",
3333
src: "events.js",
34+
minSrc: "events.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+
*/
45+
regRootDir: path.resolve(path.join("..", "..", "..", "..", "Node.js", "Registries")).replace(/\\/g, "/")
4146
};
4247

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

113118
gulp.task("createPackageRegistryDir",
114119
function() {
115-
var repoDir = path.resolve(path.join(cfg.regRootDir, cfg.name)).replace(/\\/g, "/");
120+
// We will assume that the Version has been appropriately bumped.
121+
var version = json.sync(path.join(cfg.binDir, cfg.pkgJson)).version;
122+
var repoDir = path.join(path.join(cfg.regRootDir, cfg.name, version));
116123
if (fs.exists(repoDir)) {
117124
console.log("Package registry directory '" + repoDir + "' exists.");
118125
} else {
@@ -121,86 +128,100 @@ gulp.task("createPackageRegistryDir",
121128
}
122129
});
123130

124-
gulp.task("publishPackageToLocalRegistry",
125-
["createTarballPackage", "createPackageRegistryDir"],
131+
// TODO: TBD: rinse and repeat from Array ExtensionsJS...
132+
gulp.task("publishPackageToLocalDir",
133+
["minify", "stage", "createPackageRegistryDir"],
126134
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;
135+
var version = json.sync(path.join(cfg.binDir, cfg.pkgJson)).version;
136+
var repoDir = path.join(cfg.regRootDir, cfg.name, version).replace(/\\/g, "/");
137+
var items = [
138+
{ name: cfg.src },
139+
{ name: cfg.minSrc },
140+
{ name: cfg.pkgJson }
141+
];
142+
var processedItems = [];
143+
var archive = function() {
144+
if (!processedItems.length) {
145+
return;
146+
}
147+
var commitPackages = function() {
148+
git.commit("publishing " + cfg.name + " " + version);
149+
};
150+
var addPackages = function() {
151+
git.cwd(repoDir);
152+
var addingItems = [];
153+
var updatingItems = [];
154+
for (var j = 0; j < processedItems.length; j++) {
155+
if (processedItems[j].adding) {
156+
addingItems.push(processedItems[j].name);
139157
}
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);
158+
if (processedItems[j].updating) {
159+
updatingItems.push(processedItems[j].name);
160+
}
161+
}
162+
if (addingItems.length) {
163+
git.add(addingItems,
164+
() => {
165+
commitPackages();
169166
});
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;
167+
} else if (updatingItems.length) {
168+
commitPackages();
194169
}
195-
})) {
196-
doPublish();
197-
} else {
198-
git.init(false,
199-
err => {
170+
};
171+
git.cwd(cfg.regRootDir);
172+
if (fs.exists(path.join(cfg.regRootDir, cfg.gitDir).replace(/\\/g, "/")) &&
173+
// ReSharper disable once PossiblyUnassignedProperty
174+
git.checkIsRepo(err => {
200175
if (err) {
201176
throw err;
202177
}
203-
doPublish();
178+
})) {
179+
addPackages();
180+
} else {
181+
git.init(false,
182+
err => {
183+
if (err) {
184+
throw err;
185+
}
186+
addPackages();
187+
});
188+
}
189+
};
190+
var processPathCrc = (rootDir, info, callback) => {
191+
crc2json(rootDir,
192+
map => {
193+
// We need to sift through the entries for the requested value.
194+
var value = undefined;
195+
// ReSharper disable once MissingHasOwnPropertyInForeach
196+
for (var k in map) {
197+
// Checking for having own property does not work here for whatever reason.
198+
if (k.endsWith(info.name)) {
199+
value = map[k];
200+
break;
201+
}
202+
}
203+
callback(info, value);
204+
});
205+
};
206+
for (var i = 0; i < items.length; i++) {
207+
/* We are likely to get tripped up over the timing of functional callbacks here. But
208+
we will make an effort to string together the series of events that we are interested
209+
in achieving. */
210+
processPathCrc(cfg.binDir,
211+
items[i],
212+
(o, x) => {
213+
processPathCrc(repoDir,
214+
o,
215+
(p, y) => {
216+
var src = path.join(cfg.binDir, p.name).replace(/\\/g, "/");
217+
var dest = path.join(repoDir, p.name).replace(/\\/g, "/");
218+
p.adding = x && y === undefined;
219+
p.updating = x && y && x !== y;
220+
fs.copy(src, dest, { overwrite: p.adding || p.updating });
221+
if (processedItems.push(p) === items.length) {
222+
archive();
223+
}
224+
});
204225
});
205226
}
206227
});

src/ExtensionsJS.Events/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.Events/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "extensionsjs-events",
33
"description": "Provides a useful set of Event Dispatching extensions facilitating Event Driven operation that is completely agnostic of any client side frameworks, jQuery, and so on.",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"author": "Michael W Powell",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)