Skip to content

Commit cdc1f54

Browse files
author
Michael W Powell
committed
rinse and repeat internal package distribution approach
1 parent 5eb886e commit cdc1f54

File tree

3 files changed

+93
-76
lines changed

3 files changed

+93
-76
lines changed

src/ExtensionsJS.String/gulpfile.js

Lines changed: 91 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var crc2json = require("crc2json");
3131
var cfg = {
3232
name: "extensionsjs-string",
3333
src: "str.js",
34+
minSrc: "str.min.js",
3435
pkgJson: "package.json",
3536
rootDir: path.join(".", "Scripts", "ExtensionsJS"),
3637
binDir: path.join(".", "bin"),
@@ -112,7 +113,9 @@ gulp.task("createTarballPackage",
112113

113114
gulp.task("createPackageRegistryDir",
114115
function() {
115-
var repoDir = path.resolve(path.join(cfg.regRootDir, cfg.name)).replace(/\\/g, "/");
116+
// We will assume that the Version has been appropriately bumped.
117+
var version = json.sync(path.join(cfg.binDir, cfg.pkgJson)).version;
118+
var repoDir = path.join(path.join(cfg.regRootDir, cfg.name, version));
116119
if (fs.exists(repoDir)) {
117120
console.log("Package registry directory '" + repoDir + "' exists.");
118121
} else {
@@ -121,86 +124,100 @@ gulp.task("createPackageRegistryDir",
121124
}
122125
});
123126

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

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

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

0 commit comments

Comments
 (0)