lincd-cli 0.2.32 → 0.2.34
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/lib/cli-methods.js +878 -1093
- package/lib/cli.js +28 -28
- package/lib/config-grunt.js +47 -65
- package/lib/config-webpack.js +87 -146
- package/lib/index.js +9 -6
- package/lib/interfaces.js +1 -1
- package/lib/plugins/declaration-plugin.js +40 -51
- package/lib/plugins/externalise-modules.js +15 -40
- package/lib/plugins/watch-run.js +10 -13
- package/lib/utils.js +77 -127
- package/package.json +1 -1
package/lib/cli-methods.js
CHANGED
|
@@ -31,152 +31,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
62
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
63
|
-
if (!m) return o;
|
|
64
|
-
var i = m.call(o), r, ar = [], e;
|
|
65
|
-
try {
|
|
66
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
67
|
-
}
|
|
68
|
-
catch (error) { e = { error: error }; }
|
|
69
|
-
finally {
|
|
70
|
-
try {
|
|
71
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
72
|
-
}
|
|
73
|
-
finally { if (e) throw e.error; }
|
|
74
|
-
}
|
|
75
|
-
return ar;
|
|
76
|
-
};
|
|
77
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
78
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
79
|
-
if (ar || !(i in from)) {
|
|
80
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
81
|
-
ar[i] = from[i];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
|
-
};
|
|
86
|
-
var __values = (this && this.__values) || function(o) {
|
|
87
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
88
|
-
if (m) return m.call(o);
|
|
89
|
-
if (o && typeof o.length === "number") return {
|
|
90
|
-
next: function () {
|
|
91
|
-
if (o && i >= o.length) o = void 0;
|
|
92
|
-
return { value: o && o[i++], done: !o };
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
96
|
-
};
|
|
97
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
98
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
99
36
|
};
|
|
100
|
-
exports
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
101
38
|
exports.executeCommandForPackage = exports.addCapacitor = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.buildMetadata = exports.register = exports.createPackage = exports.createComponent = exports.createSetComponent = exports.createShape = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.createApp = void 0;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
41
|
+
const utils_1 = require("./utils");
|
|
42
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
44
|
+
const models_1 = require("lincd/lib/models");
|
|
45
|
+
const env_cmd_1 = require("env-cmd");
|
|
46
|
+
const JSONLDWriter_1 = require("lincd-jsonld/lib/utils/JSONLDWriter");
|
|
47
|
+
const NameSpace_1 = require("lincd/lib/utils/NameSpace");
|
|
48
|
+
const Prefix_1 = require("lincd/lib/utils/Prefix");
|
|
49
|
+
const get_env_vars_1 = require("env-cmd/dist/get-env-vars");
|
|
113
50
|
var glob = require('glob');
|
|
114
51
|
var variables = {};
|
|
115
52
|
var open = require('open');
|
|
116
53
|
var gruntConfig;
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//replace variables in some copied files
|
|
139
|
-
return [4 /*yield*/, replaceVariablesInFolder(targetFolder)];
|
|
140
|
-
case 1:
|
|
141
|
-
//replace variables in some copied files
|
|
142
|
-
_b.sent();
|
|
143
|
-
return [4 /*yield*/, hasYarnInstalled()];
|
|
144
|
-
case 2:
|
|
145
|
-
hasYarn = _b.sent();
|
|
146
|
-
installCommand = hasYarn ? 'yarn install' : 'npm install';
|
|
147
|
-
return [4 /*yield*/, (0, utils_1.execp)("cd ".concat(hyphenName, " && ").concat(installCommand), true)["catch"](function (err) {
|
|
148
|
-
console.warn('Could not install dependencies or start application');
|
|
149
|
-
})];
|
|
150
|
-
case 3:
|
|
151
|
-
_b.sent();
|
|
152
|
-
log("Your LINCD App is ready at ".concat(chalk_1["default"].blueBright(targetFolder)), "To start, run\n".concat(chalk_1["default"].blueBright("cd ".concat(hyphenName)), " and then ").concat(chalk_1["default"].blueBright((hasYarn ? 'yarn' : 'npm') + ' start')));
|
|
153
|
-
return [2 /*return*/];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
54
|
+
const createApp = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
if (!name) {
|
|
56
|
+
console.warn('Please provide a name as the first argument');
|
|
57
|
+
}
|
|
58
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
59
|
+
let targetFolder = path_1.default.join(basePath, hyphenName);
|
|
60
|
+
if (!fs_extra_1.default.existsSync(targetFolder)) {
|
|
61
|
+
fs_extra_1.default.mkdirSync(targetFolder);
|
|
62
|
+
}
|
|
63
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-with-backend'), targetFolder);
|
|
64
|
+
//make sure the data folder exists (even though its empty).. copying empty folders does not work with fs.copySync
|
|
65
|
+
fs_extra_1.default.mkdirSync(path_1.default.join(targetFolder, 'data'), { recursive: true });
|
|
66
|
+
// fs.renameSync(path.join(targetFolder, '.yarnrc.yml.template'), path.join(targetFolder, '.yarnrc.yml'));
|
|
67
|
+
// fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
68
|
+
log("Creating new LINCD application '" + name + "'");
|
|
69
|
+
//replace variables in some copied files
|
|
70
|
+
yield replaceVariablesInFolder(targetFolder);
|
|
71
|
+
let hasYarn = yield hasYarnInstalled();
|
|
72
|
+
let installCommand = hasYarn ? 'yarn install' : 'npm install';
|
|
73
|
+
yield (0, utils_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
|
|
74
|
+
console.warn('Could not install dependencies or start application');
|
|
156
75
|
});
|
|
157
|
-
};
|
|
76
|
+
log(`Your LINCD App is ready at ${chalk_1.default.blueBright(targetFolder)}`, `To start, run\n${chalk_1.default.blueBright(`cd ${hyphenName}`)} and then ${chalk_1.default.blueBright((hasYarn ? 'yarn' : 'npm') + ' start')}`);
|
|
77
|
+
});
|
|
158
78
|
exports.createApp = createApp;
|
|
159
79
|
function logHelp() {
|
|
160
80
|
(0, utils_1.execp)('yarn exec lincd help');
|
|
161
81
|
}
|
|
162
|
-
function log() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
messages[_i] = arguments[_i];
|
|
166
|
-
}
|
|
167
|
-
messages.forEach(function (message) {
|
|
168
|
-
console.log(chalk_1["default"].cyan('Info: ') + message);
|
|
82
|
+
function log(...messages) {
|
|
83
|
+
messages.forEach((message) => {
|
|
84
|
+
console.log(chalk_1.default.cyan('Info: ') + message);
|
|
169
85
|
});
|
|
170
86
|
}
|
|
171
87
|
function progressUpdate(message) {
|
|
172
88
|
process.stdout.write(' \r');
|
|
173
89
|
process.stdout.write(message + '\r');
|
|
174
90
|
}
|
|
175
|
-
function debugInfo() {
|
|
176
|
-
var messages = [];
|
|
177
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
178
|
-
messages[_i] = arguments[_i];
|
|
179
|
-
}
|
|
91
|
+
function debugInfo(...messages) {
|
|
180
92
|
// messages.forEach((message) => {
|
|
181
93
|
// console.log(chalk.cyan('Info: ') + message);
|
|
182
94
|
// });
|
|
@@ -189,18 +101,14 @@ function debugInfo() {
|
|
|
189
101
|
// process.exit();
|
|
190
102
|
// }
|
|
191
103
|
// if (gruntConfig && gruntConfig.analyse === true) {
|
|
192
|
-
messages.forEach(
|
|
193
|
-
console.log(chalk_1
|
|
104
|
+
messages.forEach((message) => {
|
|
105
|
+
console.log(chalk_1.default.cyan('Info: ') + message);
|
|
194
106
|
});
|
|
195
107
|
// }
|
|
196
108
|
}
|
|
197
|
-
function warn() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
messages[_i] = arguments[_i];
|
|
201
|
-
}
|
|
202
|
-
messages.forEach(function (message) {
|
|
203
|
-
console.log(chalk_1["default"].magenta('Warning: ') + message);
|
|
109
|
+
function warn(...messages) {
|
|
110
|
+
messages.forEach((message) => {
|
|
111
|
+
console.log(chalk_1.default.magenta('Warning: ') + message);
|
|
204
112
|
// console.log(chalk.red(message));
|
|
205
113
|
});
|
|
206
114
|
}
|
|
@@ -229,15 +137,15 @@ function checkWorkspaces(rootPath, workspaces, res) {
|
|
|
229
137
|
if (workspaces.packages) {
|
|
230
138
|
workspaces = workspaces.packages;
|
|
231
139
|
}
|
|
232
|
-
workspaces.forEach(
|
|
233
|
-
|
|
140
|
+
workspaces.forEach((workspace) => {
|
|
141
|
+
let workspacePath = path_1.default.join(rootPath, workspace.replace('/*', ''));
|
|
234
142
|
if (workspace.indexOf('/*') !== -1) {
|
|
235
143
|
// console.log(workspacePath);
|
|
236
|
-
if (fs_extra_1
|
|
237
|
-
|
|
238
|
-
folders.forEach(
|
|
144
|
+
if (fs_extra_1.default.existsSync(workspacePath)) {
|
|
145
|
+
let folders = fs_extra_1.default.readdirSync(workspacePath);
|
|
146
|
+
folders.forEach((folder) => {
|
|
239
147
|
if (folder !== './' && folder !== '../') {
|
|
240
|
-
checkPackagePath(rootPath, path_1
|
|
148
|
+
checkPackagePath(rootPath, path_1.default.join(workspacePath, folder), res);
|
|
241
149
|
}
|
|
242
150
|
});
|
|
243
151
|
}
|
|
@@ -248,10 +156,10 @@ function checkWorkspaces(rootPath, workspaces, res) {
|
|
|
248
156
|
});
|
|
249
157
|
}
|
|
250
158
|
function checkPackagePath(rootPath, packagePath, res) {
|
|
251
|
-
|
|
159
|
+
let packageJsonPath = path_1.default.join(packagePath, 'package.json');
|
|
252
160
|
// console.log('checking '+packagePath);
|
|
253
|
-
if (fs_extra_1
|
|
254
|
-
var pack = JSON.parse(fs_extra_1
|
|
161
|
+
if (fs_extra_1.default.existsSync(packageJsonPath)) {
|
|
162
|
+
var pack = JSON.parse(fs_extra_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
255
163
|
//some packages are not true lincd packages, but we still want them to be re-built automatically. This is what lincd_util is for
|
|
256
164
|
if (pack && pack.workspaces) {
|
|
257
165
|
checkWorkspaces(packagePath, pack.workspaces, res);
|
|
@@ -259,132 +167,123 @@ function checkPackagePath(rootPath, packagePath, res) {
|
|
|
259
167
|
else if (pack && pack.lincd === true) {
|
|
260
168
|
res.push({
|
|
261
169
|
path: packagePath,
|
|
262
|
-
packageName: pack.name
|
|
170
|
+
packageName: pack.name,
|
|
263
171
|
});
|
|
264
172
|
}
|
|
265
173
|
}
|
|
266
174
|
}
|
|
267
175
|
function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStackEnd) {
|
|
268
|
-
|
|
269
|
-
var dependencies = new Map();
|
|
176
|
+
let dependencies = new Map();
|
|
270
177
|
//get dependencies of each package
|
|
271
|
-
|
|
272
|
-
lincdPackages.forEach(
|
|
178
|
+
let leastDependentPackage;
|
|
179
|
+
lincdPackages.forEach((pkg) => {
|
|
273
180
|
var pack = (0, utils_1.getPackageJSON)(pkg.path);
|
|
274
181
|
if (pack) {
|
|
275
182
|
//get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
|
|
276
|
-
|
|
277
|
-
.filter(
|
|
278
|
-
.map(
|
|
183
|
+
let packageDependencies = Object.keys(pack.dependencies)
|
|
184
|
+
.filter((dependency) => lincdPackages.has(dependency))
|
|
185
|
+
.map((dependency) => {
|
|
279
186
|
return lincdPackages.has(dependency) ? lincdPackages.get(dependency) : dependency;
|
|
280
187
|
});
|
|
281
188
|
// console.log(package.packageName,packageDependencies.map())
|
|
282
189
|
dependencies.set(pkg, packageDependencies);
|
|
283
190
|
}
|
|
284
191
|
});
|
|
285
|
-
dependencies.forEach(
|
|
286
|
-
if (!PackageDependencies.some(
|
|
192
|
+
dependencies.forEach((PackageDependencies, pkg) => {
|
|
193
|
+
if (!PackageDependencies.some((dependency) => {
|
|
287
194
|
return typeof dependency !== 'string' && lincdPackages.has(dependency.packageName);
|
|
288
195
|
})) {
|
|
289
196
|
leastDependentPackage = pkg;
|
|
290
197
|
}
|
|
291
198
|
});
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
deps.every(function (dependency) {
|
|
327
|
-
return typeof dependency !== 'string' && (done.has(dependency) || !lincdPackages.has(dependency.packageName));
|
|
328
|
-
})) {
|
|
329
|
-
stack.push(pkg);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
if (stack.length <= 0 && done.size < lincdPackages.size) {
|
|
333
|
-
console.log(chalk_1["default"].red('Only ' + done.size + ' out of ' + lincdPackages.size + ' packages have been built'));
|
|
334
|
-
console.log('ALL remaining packages have dependencies that have not been met. This may point to ' + chalk_1["default"].red('circular dependencies.'));
|
|
335
|
-
console.log('Already built: ' + Array.from(done).map(function (p) { return chalk_1["default"].green(p.packageName); }).join(', '));
|
|
336
|
-
console.log(chalk_1["default"].blue('\nTo solve this issue') + ': find the circular dependencies below and fix the dependencies:\n\n');
|
|
337
|
-
//TODO: actually find and name the packages that have circular dependencies
|
|
338
|
-
// let circular = [];
|
|
339
|
-
// lincdPackages.forEach((pkg) => {
|
|
340
|
-
// if (!done.has(pkg))
|
|
341
|
-
// {
|
|
342
|
-
// let deps = dependencies.get(pkg);
|
|
343
|
-
// if (deps.some(dependency => {
|
|
344
|
-
// //return true if this dependency (indirectly) depends on the package whos' dependency it is
|
|
345
|
-
// return hasDependency(dependency,pkg,dependencies)
|
|
346
|
-
// }))
|
|
347
|
-
// {
|
|
348
|
-
// circular.push(pkg);
|
|
349
|
-
// }
|
|
350
|
-
// process.exit();
|
|
351
|
-
// }
|
|
352
|
-
// });
|
|
353
|
-
lincdPackages.forEach(function (pkg) {
|
|
354
|
-
var deps = dependencies.get(pkg);
|
|
355
|
-
if (!done.has(pkg)) {
|
|
356
|
-
console.log(chalk_1["default"].red(pkg.packageName) + ' has not been built yet. Unbuilt dependencies:\n' + deps.filter(function (dependency) {
|
|
357
|
-
return !Array.from(done).some(function (p) {
|
|
358
|
-
// console.log(p.packageName,dependency.packageName,p===dependency)
|
|
359
|
-
return p === dependency;
|
|
360
|
-
});
|
|
361
|
-
}).map(function (p) { return chalk_1["default"].red('\t- ' + ((p === null || p === void 0 ? void 0 : p.packageName) ? p.packageName : p.toString()) + '\n'); }).join(" "));
|
|
362
|
-
// console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => {
|
|
363
|
-
// return Array.from(done).some(p => p.packageName === pkg.packageName)
|
|
364
|
-
// }).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
|
|
365
|
-
// console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => done.has(pkg)).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
//if more to be built, iterate
|
|
370
|
-
if (stack.length > 0) {
|
|
371
|
-
return [2 /*return*/, runStack(stack)];
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
onStackEnd(dependencies, results.filter(Boolean));
|
|
375
|
-
}
|
|
376
|
-
return [2 /*return*/];
|
|
199
|
+
let startStack = [leastDependentPackage];
|
|
200
|
+
let done = new Set();
|
|
201
|
+
let results = [];
|
|
202
|
+
let runStack = (stack) => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
let runFunction = onBuildStack(stack, dependencies);
|
|
204
|
+
//build the stack in parallel
|
|
205
|
+
let stackPromise = Promise.all(stack.map((pck) => {
|
|
206
|
+
// p = p.then(() => {
|
|
207
|
+
return runFunction(pck)
|
|
208
|
+
.catch(({ error, stdout, stderr }) => {
|
|
209
|
+
warn('Uncaught exception whilst running parallel function on ' + pck.packageName, error.message);
|
|
210
|
+
// warn(chalk.red(pck.packageName+' failed:'));
|
|
211
|
+
// console.log(stdout);
|
|
212
|
+
})
|
|
213
|
+
.then((res) => {
|
|
214
|
+
done.add(pck);
|
|
215
|
+
return res;
|
|
216
|
+
});
|
|
217
|
+
}));
|
|
218
|
+
//wait till stack is completed
|
|
219
|
+
let stackResults = yield stackPromise;
|
|
220
|
+
results = results.concat(stackResults);
|
|
221
|
+
//clear stack for next round
|
|
222
|
+
stack = [];
|
|
223
|
+
//find those packages who have all their dependencies already built and add them to the stack
|
|
224
|
+
lincdPackages.forEach((pkg) => {
|
|
225
|
+
let deps = dependencies.get(pkg);
|
|
226
|
+
//if the package is not done yet
|
|
227
|
+
//but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
|
|
228
|
+
if (!done.has(pkg) &&
|
|
229
|
+
deps.every((dependency) => {
|
|
230
|
+
return typeof dependency !== 'string' && (done.has(dependency) || !lincdPackages.has(dependency.packageName));
|
|
231
|
+
})) {
|
|
232
|
+
stack.push(pkg);
|
|
377
233
|
}
|
|
378
234
|
});
|
|
379
|
-
|
|
235
|
+
if (stack.length <= 0 && done.size < lincdPackages.size) {
|
|
236
|
+
console.log(chalk_1.default.red('Only ' + done.size + ' out of ' + lincdPackages.size + ' packages have been built'));
|
|
237
|
+
console.log('ALL remaining packages have dependencies that have not been met. This may point to ' + chalk_1.default.red('circular dependencies.'));
|
|
238
|
+
console.log('Already built: ' + Array.from(done).map(p => chalk_1.default.green(p.packageName)).join(', '));
|
|
239
|
+
console.log(chalk_1.default.blue('\nTo solve this issue') + ': find the circular dependencies below and fix the dependencies:\n\n');
|
|
240
|
+
//TODO: actually find and name the packages that have circular dependencies
|
|
241
|
+
// let circular = [];
|
|
242
|
+
// lincdPackages.forEach((pkg) => {
|
|
243
|
+
// if (!done.has(pkg))
|
|
244
|
+
// {
|
|
245
|
+
// let deps = dependencies.get(pkg);
|
|
246
|
+
// if (deps.some(dependency => {
|
|
247
|
+
// //return true if this dependency (indirectly) depends on the package whos' dependency it is
|
|
248
|
+
// return hasDependency(dependency,pkg,dependencies)
|
|
249
|
+
// }))
|
|
250
|
+
// {
|
|
251
|
+
// circular.push(pkg);
|
|
252
|
+
// }
|
|
253
|
+
// process.exit();
|
|
254
|
+
// }
|
|
255
|
+
// });
|
|
256
|
+
lincdPackages.forEach(pkg => {
|
|
257
|
+
let deps = dependencies.get(pkg);
|
|
258
|
+
if (!done.has(pkg)) {
|
|
259
|
+
console.log(chalk_1.default.red(pkg.packageName) + ' has not been built yet. Unbuilt dependencies:\n' + deps.filter(dependency => {
|
|
260
|
+
return !Array.from(done).some(p => {
|
|
261
|
+
// console.log(p.packageName,dependency.packageName,p===dependency)
|
|
262
|
+
return p === dependency;
|
|
263
|
+
});
|
|
264
|
+
}).map(p => chalk_1.default.red('\t- ' + ((p === null || p === void 0 ? void 0 : p.packageName) ? p.packageName : p.toString()) + '\n')).join(" "));
|
|
265
|
+
// console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => {
|
|
266
|
+
// return Array.from(done).some(p => p.packageName === pkg.packageName)
|
|
267
|
+
// }).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
|
|
268
|
+
// console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => done.has(pkg)).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
//if more to be built, iterate
|
|
273
|
+
if (stack.length > 0) {
|
|
274
|
+
return runStack(stack);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
onStackEnd(dependencies, results.filter(Boolean));
|
|
278
|
+
}
|
|
279
|
+
});
|
|
380
280
|
//starts the process
|
|
381
281
|
runStack(startStack);
|
|
382
282
|
}
|
|
383
|
-
function hasDependency(pkg, childPkg, dependencies, depth) {
|
|
384
|
-
if (depth === void 0) { depth = 1; }
|
|
283
|
+
function hasDependency(pkg, childPkg, dependencies, depth = 1) {
|
|
385
284
|
console.log("Does " + pkg.packageName + " have dep " + childPkg.packageName + " ?");
|
|
386
|
-
|
|
387
|
-
if (deps.some(
|
|
285
|
+
let deps = dependencies.get(pkg);
|
|
286
|
+
if (deps.some(dependency => {
|
|
388
287
|
console.log(dependency.packageName, childPkg.packageName, dependency === childPkg);
|
|
389
288
|
if (depth === 2)
|
|
390
289
|
return false;
|
|
@@ -398,12 +297,11 @@ function hasDependency(pkg, childPkg, dependencies, depth) {
|
|
|
398
297
|
return false;
|
|
399
298
|
}
|
|
400
299
|
function buildAll(target, target2, target3) {
|
|
401
|
-
var _this = this;
|
|
402
300
|
console.log('Building all LINCD packages of this repository in order of dependencies');
|
|
403
|
-
|
|
404
|
-
|
|
301
|
+
let lincdPackages = getLocalLincdPackageMap();
|
|
302
|
+
let startFrom;
|
|
405
303
|
//by default start building
|
|
406
|
-
|
|
304
|
+
let building = true;
|
|
407
305
|
//option to start from a specific package in the stack
|
|
408
306
|
if (target == 'from') {
|
|
409
307
|
startFrom = target2;
|
|
@@ -412,7 +310,7 @@ function buildAll(target, target2, target3) {
|
|
|
412
310
|
//clear targets
|
|
413
311
|
target = '';
|
|
414
312
|
target2 = '';
|
|
415
|
-
console.log(chalk_1
|
|
313
|
+
console.log(chalk_1.default.blue('Will skip builds until ' + startFrom));
|
|
416
314
|
// return async (pkg) => {};
|
|
417
315
|
}
|
|
418
316
|
if (target2 == 'from') {
|
|
@@ -422,110 +320,108 @@ function buildAll(target, target2, target3) {
|
|
|
422
320
|
//clear targets
|
|
423
321
|
target2 = '';
|
|
424
322
|
target3 = '';
|
|
425
|
-
console.log(chalk_1
|
|
323
|
+
console.log(chalk_1.default.blue('Will skip builds until ' + startFrom));
|
|
426
324
|
// return async (pkg) => {};
|
|
427
325
|
}
|
|
428
|
-
|
|
429
|
-
|
|
326
|
+
let done = new Set();
|
|
327
|
+
let failedModules = [];
|
|
430
328
|
progressUpdate(lincdPackages.size + ' packages left');
|
|
431
|
-
|
|
329
|
+
let packagesLeft = lincdPackages.size;
|
|
432
330
|
// let packagesLeft = lincdPackages.size - done.size;
|
|
433
|
-
runOnPackagesGroupedByDependencies(lincdPackages,
|
|
331
|
+
runOnPackagesGroupedByDependencies(lincdPackages, (packageGroup, dependencies) => {
|
|
434
332
|
if (done.size > 0) {
|
|
435
|
-
debugInfo(chalk_1
|
|
333
|
+
debugInfo(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
|
|
436
334
|
// log(stack);
|
|
437
335
|
}
|
|
438
|
-
debugInfo('Now building: ' + chalk_1
|
|
439
|
-
return
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
building = true;
|
|
448
|
-
}
|
|
449
|
-
//else still waiting for the package
|
|
450
|
-
else {
|
|
451
|
-
log(chalk_1["default"].blue('skipping ' + pkg.packageName));
|
|
452
|
-
command = Promise.resolve(true);
|
|
453
|
-
skipping = true;
|
|
454
|
-
}
|
|
336
|
+
debugInfo('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
337
|
+
return (pkg) => __awaiter(this, void 0, void 0, function* () {
|
|
338
|
+
let command;
|
|
339
|
+
let skipping = false;
|
|
340
|
+
//if we're skipping builds until a certain package
|
|
341
|
+
if (!building) {
|
|
342
|
+
//if the package name matches the package we're supposed to start from then start building packages
|
|
343
|
+
if (pkg.packageName == startFrom || pkg.packageName == startFrom) {
|
|
344
|
+
building = true;
|
|
455
345
|
}
|
|
456
|
-
//
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
346
|
+
//else still waiting for the package
|
|
347
|
+
else {
|
|
348
|
+
log(chalk_1.default.blue('skipping ' + pkg.packageName));
|
|
349
|
+
command = Promise.resolve(true);
|
|
350
|
+
skipping = true;
|
|
460
351
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
352
|
+
}
|
|
353
|
+
//unless told otherwise, build the package
|
|
354
|
+
if (!command) {
|
|
355
|
+
command = (0, utils_1.execPromise)('cd ' + pkg.path + ' && yarn exec lincd build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : ''), false, false, {}, false);
|
|
356
|
+
debugInfo(chalk_1.default.cyan('Building ' + pkg.packageName));
|
|
357
|
+
}
|
|
358
|
+
return command
|
|
359
|
+
.catch(({ error, stdout, stderr }) => {
|
|
360
|
+
//this prints out the webpack output, including the build errors
|
|
361
|
+
warn('Failed to build ' + pkg.packageName);
|
|
362
|
+
console.log(stdout);
|
|
363
|
+
failedModules.push(pkg.packageName);
|
|
364
|
+
let dependentModules = getDependentPackages(dependencies, pkg);
|
|
365
|
+
if (dependentModules.length > 0) {
|
|
366
|
+
printBuildResults(failedModules, done);
|
|
367
|
+
console.log(chalk_1.default.magenta('Stopping build process because an error occurred whilst building ' +
|
|
368
|
+
pkg.packageName +
|
|
369
|
+
', which ' +
|
|
370
|
+
dependentModules.length +
|
|
371
|
+
' other packages depend on.')); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
372
|
+
console.log(chalk_1.default.cyanBright('tip ') +
|
|
373
|
+
'Run ' +
|
|
374
|
+
chalk_1.default.green(`lincd build-all from ${pkg.packageName}`) +
|
|
375
|
+
' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
376
|
+
process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
.then((res) => {
|
|
380
|
+
if (!skipping) {
|
|
381
|
+
log(chalk_1.default.green('Built ' + pkg.packageName));
|
|
382
|
+
}
|
|
383
|
+
done.add(pkg);
|
|
384
|
+
packagesLeft--;
|
|
385
|
+
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
386
|
+
process.stdout.write(packagesLeft + ' packages left\r');
|
|
387
|
+
if (packagesLeft == 0) {
|
|
388
|
+
printBuildResults(failedModules, done);
|
|
389
|
+
}
|
|
390
|
+
return res;
|
|
495
391
|
});
|
|
496
|
-
});
|
|
497
|
-
},
|
|
392
|
+
});
|
|
393
|
+
}, (dependencies) => {
|
|
498
394
|
//if no more packages to build but we never started building...
|
|
499
395
|
if (!building) {
|
|
500
|
-
console.log(chalk_1
|
|
396
|
+
console.log(chalk_1.default.red('Could not find the package to start from. Please provide a correct package name or package name to build from'));
|
|
501
397
|
}
|
|
502
398
|
else {
|
|
503
399
|
//Detecting cyclical dependencies that caused some packages not to be build
|
|
504
|
-
|
|
505
|
-
lincdPackages.forEach(
|
|
400
|
+
let first = true;
|
|
401
|
+
lincdPackages.forEach((pkg) => {
|
|
506
402
|
if (!done.has(pkg)) {
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
console.log(chalk_1
|
|
510
|
-
|
|
403
|
+
let deps = dependencies.get(pkg);
|
|
404
|
+
if (first) {
|
|
405
|
+
console.log(chalk_1.default.red('CYCLICAL DEPENDENCIES? - could not build some packages because they depend on each other.'));
|
|
406
|
+
first = false;
|
|
511
407
|
}
|
|
512
408
|
//print the cyclical dependencies
|
|
513
|
-
console.log(chalk_1
|
|
409
|
+
console.log(chalk_1.default.red(pkg.packageName) +
|
|
514
410
|
' depends on ' +
|
|
515
411
|
deps
|
|
516
|
-
.filter(
|
|
412
|
+
.filter((dependency) => {
|
|
517
413
|
return typeof dependency !== 'string';
|
|
518
414
|
})
|
|
519
|
-
.map(
|
|
520
|
-
return done.has(d) ? d.packageName : chalk_1
|
|
415
|
+
.map((d) => {
|
|
416
|
+
return done.has(d) ? d.packageName : chalk_1.default.red(d.packageName);
|
|
521
417
|
})
|
|
522
418
|
.join(', '));
|
|
523
419
|
//also print some information why these packages have not been moved into the stack
|
|
524
|
-
|
|
420
|
+
let stringDependencies = deps.filter((d) => typeof d === 'string');
|
|
525
421
|
if (stringDependencies.length > 0) {
|
|
526
|
-
console.log(chalk_1
|
|
422
|
+
console.log(chalk_1.default.red('And it depends on these package(s) - which seem not to be proper packages :' +
|
|
527
423
|
stringDependencies.join(', ')));
|
|
528
|
-
console.log(chalk_1
|
|
424
|
+
console.log(chalk_1.default.red('Could you remove this from dependencies? Should it be a devDependency?'));
|
|
529
425
|
}
|
|
530
426
|
}
|
|
531
427
|
});
|
|
@@ -534,8 +430,8 @@ function buildAll(target, target2, target3) {
|
|
|
534
430
|
}
|
|
535
431
|
exports.buildAll = buildAll;
|
|
536
432
|
function getDependentPackages(dependencies, pkg) {
|
|
537
|
-
|
|
538
|
-
dependencies.forEach(
|
|
433
|
+
let dependentModules = [];
|
|
434
|
+
dependencies.forEach((dModuleDependencies, dModule) => {
|
|
539
435
|
if (dModuleDependencies.indexOf(pkg) !== -1) {
|
|
540
436
|
dependentModules.push(dModule);
|
|
541
437
|
}
|
|
@@ -546,10 +442,9 @@ function getDependentPackages(dependencies, pkg) {
|
|
|
546
442
|
* Returns a map of the packages that this repository manages (so no packages found through the workspaces who's path contains ../ )
|
|
547
443
|
* @param rootPath
|
|
548
444
|
*/
|
|
549
|
-
function getLocalLincdPackageMap(rootPath) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
getLincdPackages(rootPath).forEach(function (pkg) {
|
|
445
|
+
function getLocalLincdPackageMap(rootPath = './') {
|
|
446
|
+
let map = new Map();
|
|
447
|
+
getLincdPackages(rootPath).forEach((pkg) => {
|
|
553
448
|
if (pkg.path.indexOf('../') === -1 && pkg.path.indexOf('..\\') === -1) {
|
|
554
449
|
// console.log(package.path);
|
|
555
450
|
map.set(pkg.packageName, pkg);
|
|
@@ -557,18 +452,16 @@ function getLocalLincdPackageMap(rootPath) {
|
|
|
557
452
|
});
|
|
558
453
|
return map;
|
|
559
454
|
}
|
|
560
|
-
function getLocalLincdModules(rootPath) {
|
|
561
|
-
|
|
562
|
-
return getLincdPackages(rootPath).filter(function (pkg) {
|
|
455
|
+
function getLocalLincdModules(rootPath = './') {
|
|
456
|
+
return getLincdPackages(rootPath).filter((pkg) => {
|
|
563
457
|
return pkg.path.indexOf('..\\') === -1;
|
|
564
458
|
});
|
|
565
459
|
}
|
|
566
|
-
function getLincdPackages(rootPath) {
|
|
567
|
-
|
|
568
|
-
var pack = (0, utils_1.getPackageJSON)();
|
|
460
|
+
function getLincdPackages(rootPath = process.cwd()) {
|
|
461
|
+
let pack = (0, utils_1.getPackageJSON)();
|
|
569
462
|
if (!pack || !pack.workspaces) {
|
|
570
|
-
for (
|
|
571
|
-
rootPath = path_1
|
|
463
|
+
for (let i = 0; i <= 3; i++) {
|
|
464
|
+
rootPath = path_1.default.join(process.cwd(), ...Array(i).fill('..'));
|
|
572
465
|
pack = (0, utils_1.getPackageJSON)(rootPath);
|
|
573
466
|
if (pack && pack.workspaces) {
|
|
574
467
|
// log('Found workspace at '+packagePath);
|
|
@@ -577,12 +470,12 @@ function getLincdPackages(rootPath) {
|
|
|
577
470
|
}
|
|
578
471
|
}
|
|
579
472
|
if (!pack || !pack.workspaces) {
|
|
580
|
-
warn(chalk_1
|
|
473
|
+
warn(chalk_1.default.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
|
|
581
474
|
logHelp();
|
|
582
475
|
process.exit();
|
|
583
476
|
}
|
|
584
477
|
// console.log(pack.workspaces);
|
|
585
|
-
|
|
478
|
+
let res = [];
|
|
586
479
|
checkWorkspaces(rootPath, pack.workspaces, res);
|
|
587
480
|
return res;
|
|
588
481
|
}
|
|
@@ -592,20 +485,18 @@ function setVariable(name, replacement) {
|
|
|
592
485
|
name = name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
593
486
|
variables[name] = replacement;
|
|
594
487
|
}
|
|
595
|
-
var replaceVariablesInFile =
|
|
596
|
-
var fileContent,
|
|
597
|
-
|
|
598
|
-
switch (_a.label) {
|
|
599
|
-
case 0: return [4 /*yield*/, fs_extra_1["default"].readFile(filePath, 'utf8')["catch"](function (err) {
|
|
600
|
-
console.warn(chalk_1["default"].red("Could not read file " + filePath));
|
|
601
|
-
})];
|
|
602
|
-
case 1:
|
|
603
|
-
fileContent = _a.sent();
|
|
604
|
-
newContent = replaceCurlyVariables(fileContent);
|
|
605
|
-
return [2 /*return*/, fs_extra_1["default"].writeFile(filePath, newContent)];
|
|
606
|
-
}
|
|
488
|
+
var replaceVariablesInFile = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
489
|
+
var fileContent = yield fs_extra_1.default.readFile(filePath, 'utf8').catch(err => {
|
|
490
|
+
console.warn(chalk_1.default.red("Could not read file " + filePath));
|
|
607
491
|
});
|
|
608
|
-
|
|
492
|
+
if (fileContent) {
|
|
493
|
+
var newContent = replaceCurlyVariables(fileContent);
|
|
494
|
+
return fs_extra_1.default.writeFile(filePath, newContent);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
return Promise.resolve();
|
|
498
|
+
}
|
|
499
|
+
});
|
|
609
500
|
var replaceCurlyVariables = function (string) {
|
|
610
501
|
// var reg = new RegExp('\\$\\{'+key+'\\}','g');
|
|
611
502
|
for (var key in variables) {
|
|
@@ -613,93 +504,79 @@ var replaceCurlyVariables = function (string) {
|
|
|
613
504
|
}
|
|
614
505
|
return string;
|
|
615
506
|
};
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
507
|
+
const capitalize = (str) => str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
|
|
508
|
+
const camelCase = (str) => {
|
|
509
|
+
let string = str.replace(/[^A-Za-z0-9]/g, ' ').split(' ');
|
|
619
510
|
if (string.length > 1) {
|
|
620
|
-
return string.reduce(
|
|
511
|
+
return string.reduce((result, word) => result + capitalize(word));
|
|
621
512
|
}
|
|
622
513
|
return str;
|
|
623
514
|
};
|
|
624
|
-
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
//if this is not a lincd app (but a lincd package instead)
|
|
655
|
-
if (!sourceFolder.includes('frontend')) {
|
|
656
|
-
indexPath = addLineToIndex("import './ontologies/".concat(hyphenName, "';"), 'ontologies');
|
|
657
|
-
log("Added an import of this file from ".concat(chalk_1["default"].magenta(indexPath)));
|
|
658
|
-
}
|
|
659
|
-
return [2 /*return*/];
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
};
|
|
515
|
+
const createOntology = (prefix, uriBase, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
516
|
+
if (!prefix) {
|
|
517
|
+
console.warn('Please provide a suggested prefix as the first argument');
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
let sourceFolder = getSourceFolder(basePath);
|
|
521
|
+
let targetFolder = ensureFolderExists(sourceFolder, 'ontologies');
|
|
522
|
+
if (!uriBase) {
|
|
523
|
+
uriBase = 'http://lincd.org/ont/' + prefix + '/';
|
|
524
|
+
}
|
|
525
|
+
setVariable('uri_base', uriBase);
|
|
526
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(prefix);
|
|
527
|
+
//copy ontology accessor file
|
|
528
|
+
log("Creating files for ontology '" + prefix + "'");
|
|
529
|
+
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
530
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
531
|
+
//copy data files
|
|
532
|
+
let targetDataFile = path_1.default.join(targetFolder, '..', 'data', hyphenName + '.json');
|
|
533
|
+
let targetDataFile2 = path_1.default.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
|
|
534
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json'), targetDataFile);
|
|
535
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
|
|
536
|
+
yield replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2);
|
|
537
|
+
log(`Prepared a new ontology data files in ${chalk_1.default.magenta(targetDataFile.replace(basePath, ''))}`, `And an ontology accessor file in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
|
|
538
|
+
//if this is not a lincd app (but a lincd package instead)
|
|
539
|
+
if (!sourceFolder.includes('frontend')) {
|
|
540
|
+
//then also add an import to index
|
|
541
|
+
let indexPath = addLineToIndex(`import './ontologies/${hyphenName}';`, 'ontologies');
|
|
542
|
+
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
543
|
+
}
|
|
544
|
+
});
|
|
664
545
|
exports.createOntology = createOntology;
|
|
665
|
-
|
|
546
|
+
const addLineToIndex = function (line, insertMatchString) {
|
|
666
547
|
//import ontology in index
|
|
667
|
-
|
|
668
|
-
.map(
|
|
669
|
-
.find(
|
|
670
|
-
return fs_extra_1
|
|
548
|
+
let indexPath = ['index.ts', 'index.tsx']
|
|
549
|
+
.map((f) => path_1.default.join('src', f))
|
|
550
|
+
.find((indexFileName) => {
|
|
551
|
+
return fs_extra_1.default.existsSync(indexFileName);
|
|
671
552
|
});
|
|
672
553
|
if (indexPath) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
554
|
+
let indexContents = fs_extra_1.default.readFileSync(indexPath, 'utf-8');
|
|
555
|
+
let lines = indexContents.split(/\n/g);
|
|
556
|
+
let newContents;
|
|
676
557
|
for (var key in lines) {
|
|
677
558
|
if (lines[key].indexOf(insertMatchString) !== -1) {
|
|
678
559
|
//remove lines after this line and insert new line in its place
|
|
679
|
-
lines[key] +=
|
|
560
|
+
lines[key] += `\n${line}`;
|
|
680
561
|
newContents = lines.join('\n');
|
|
681
562
|
// log("Found at "+key,lines,newContents);
|
|
682
563
|
break;
|
|
683
564
|
}
|
|
684
565
|
}
|
|
685
566
|
if (!newContents) {
|
|
686
|
-
newContents = indexContents +
|
|
567
|
+
newContents = indexContents + `\n${line}`;
|
|
687
568
|
// log("Added at end",newContents);
|
|
688
569
|
}
|
|
689
|
-
fs_extra_1
|
|
570
|
+
fs_extra_1.default.writeFileSync(indexPath, newContents);
|
|
690
571
|
}
|
|
691
572
|
return indexPath;
|
|
692
573
|
};
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
696
|
-
files[_i] = arguments[_i];
|
|
697
|
-
}
|
|
698
|
-
return Promise.all(files.map(function (file) {
|
|
574
|
+
const replaceVariablesInFiles = function (...files) {
|
|
575
|
+
return Promise.all(files.map((file) => {
|
|
699
576
|
return replaceVariablesInFile(file);
|
|
700
577
|
}));
|
|
701
578
|
};
|
|
702
|
-
|
|
579
|
+
const replaceVariablesInFolder = function (folder) {
|
|
703
580
|
//get all files in folder, including files that start with a dot
|
|
704
581
|
glob(folder + '/**/*', { dot: true, nodir: true }, function (err, files) {
|
|
705
582
|
if (err) {
|
|
@@ -707,45 +584,30 @@ var replaceVariablesInFolder = function (folder) {
|
|
|
707
584
|
}
|
|
708
585
|
else {
|
|
709
586
|
// console.log(files);
|
|
710
|
-
return Promise.all(files.map(
|
|
587
|
+
return Promise.all(files.map((file) => {
|
|
711
588
|
return replaceVariablesInFile(file);
|
|
712
589
|
}));
|
|
713
590
|
}
|
|
714
591
|
});
|
|
715
592
|
};
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
719
|
-
files[_i - 1] = arguments[_i];
|
|
720
|
-
}
|
|
721
|
-
return replaceVariablesInFiles.apply(void 0, __spreadArray([], __read(files.map(function (f) { return path_1["default"].join(root, f); })), false));
|
|
593
|
+
const replaceVariablesInFilesWithRoot = function (root, ...files) {
|
|
594
|
+
return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
|
|
722
595
|
};
|
|
723
|
-
|
|
724
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
return '';
|
|
731
|
-
})];
|
|
732
|
-
case 1:
|
|
733
|
-
version = (_a.sent());
|
|
734
|
-
return [2 /*return*/, version.toString().match(/[0-9]+/)];
|
|
735
|
-
}
|
|
736
|
-
});
|
|
596
|
+
const hasYarnInstalled = function () {
|
|
597
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
598
|
+
let version = (yield (0, utils_1.execPromise)('yarn --version').catch((err) => {
|
|
599
|
+
console.log('yarn probably not working');
|
|
600
|
+
return '';
|
|
601
|
+
}));
|
|
602
|
+
return version.toString().match(/[0-9]+/);
|
|
737
603
|
});
|
|
738
604
|
};
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
folders.forEach(function (folder) {
|
|
746
|
-
target = target ? path_1["default"].join(target, folder) : path_1["default"].join(folder);
|
|
747
|
-
if (!fs_extra_1["default"].existsSync(target)) {
|
|
748
|
-
fs_extra_1["default"].mkdirSync(target);
|
|
605
|
+
const ensureFolderExists = function (...folders) {
|
|
606
|
+
let target;
|
|
607
|
+
folders.forEach((folder) => {
|
|
608
|
+
target = target ? path_1.default.join(target, folder) : path_1.default.join(folder);
|
|
609
|
+
if (!fs_extra_1.default.existsSync(target)) {
|
|
610
|
+
fs_extra_1.default.mkdirSync(target);
|
|
749
611
|
}
|
|
750
612
|
});
|
|
751
613
|
return target;
|
|
@@ -762,216 +624,165 @@ var ensureFolderExists = function () {
|
|
|
762
624
|
}
|
|
763
625
|
return targetFolder;*/
|
|
764
626
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
627
|
+
const setNameVariables = function (name) {
|
|
628
|
+
let hyphenName = name.replace(/[-_\s]+/g, '-');
|
|
629
|
+
let camelCaseName = camelCase(name); //some-package --> someModule
|
|
630
|
+
let underscoreName = name.replace(/[-\s]+/g, '_');
|
|
631
|
+
let plainName = name.replace(/[-\s]+/g, '');
|
|
770
632
|
//longer similar variables names should come before the shorter ones
|
|
771
633
|
setVariable('underscore_name', underscoreName);
|
|
772
634
|
setVariable('hyphen_name', hyphenName);
|
|
773
635
|
setVariable('camel_name', camelCaseName);
|
|
774
636
|
setVariable('name', name);
|
|
775
637
|
setVariable('plain_name', plainName);
|
|
776
|
-
return { hyphenName
|
|
638
|
+
return { hyphenName, camelCaseName, underscoreName, plainName };
|
|
777
639
|
};
|
|
778
|
-
function getSourceFolder(basePath) {
|
|
779
|
-
if (basePath === void 0) { basePath = process.cwd(); }
|
|
640
|
+
function getSourceFolder(basePath = process.cwd()) {
|
|
780
641
|
//LINCD App
|
|
781
|
-
if (fs_extra_1
|
|
782
|
-
return path_1
|
|
642
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(basePath, 'frontend', 'src'))) {
|
|
643
|
+
return path_1.default.join(basePath, 'frontend', 'src');
|
|
783
644
|
}
|
|
784
645
|
//LINCD package
|
|
785
|
-
if (fs_extra_1
|
|
786
|
-
return path_1
|
|
646
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(basePath, 'src'))) {
|
|
647
|
+
return path_1.default.join(basePath, 'src');
|
|
787
648
|
}
|
|
788
649
|
else {
|
|
789
650
|
console.warn('Cannot find source folder');
|
|
790
|
-
return path_1
|
|
651
|
+
return path_1.default.join(basePath, 'src');
|
|
791
652
|
}
|
|
792
653
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
if (!sourceFolder.includes('frontend')) {
|
|
812
|
-
indexPath = addLineToIndex("import './shapes/".concat(hyphenName, "';"), 'shapes');
|
|
813
|
-
log("Added an import of this file from ".concat(chalk_1["default"].magenta(indexPath)));
|
|
814
|
-
}
|
|
815
|
-
return [2 /*return*/];
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
});
|
|
819
|
-
};
|
|
654
|
+
const createShape = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
655
|
+
let sourceFolder = getSourceFolder(basePath);
|
|
656
|
+
let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
|
|
657
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
658
|
+
//copy default shape file
|
|
659
|
+
// log("Creating files for shape '" + name + "'");
|
|
660
|
+
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
661
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
|
|
662
|
+
//replace variables in some of the copied files
|
|
663
|
+
yield replaceVariablesInFiles(targetFile);
|
|
664
|
+
log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
|
|
665
|
+
//if this is NOT a lincd app (but a lincd package)
|
|
666
|
+
let indexPath;
|
|
667
|
+
if (!sourceFolder.includes('frontend')) {
|
|
668
|
+
indexPath = addLineToIndex(`import './shapes/${hyphenName}';`, 'shapes');
|
|
669
|
+
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
670
|
+
}
|
|
671
|
+
});
|
|
820
672
|
exports.createShape = createShape;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
fs_extra_1["default"].copySync(path_1["default"].join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
|
|
836
|
-
//replace variables in some of the copied files
|
|
837
|
-
return [4 /*yield*/, replaceVariablesInFiles(targetFile, targetFile2)];
|
|
838
|
-
case 1:
|
|
839
|
-
//replace variables in some of the copied files
|
|
840
|
-
_b.sent();
|
|
841
|
-
indexPath = addLineToIndex("import './components/".concat(hyphenName, "';"), 'components');
|
|
842
|
-
log("Created a new set component in ".concat(chalk_1["default"].magenta(targetFile.replace(basePath, ''))), "Created a new stylesheet in ".concat(chalk_1["default"].magenta(targetFile2.replace(basePath, ''))), "Added an import of this file from ".concat(chalk_1["default"].magenta(indexPath)));
|
|
843
|
-
return [2 /*return*/];
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
};
|
|
673
|
+
const createSetComponent = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
674
|
+
let targetFolder = ensureFolderExists(basePath, 'src', 'components');
|
|
675
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
676
|
+
//copy default shape file
|
|
677
|
+
log("Creating files for set component '" + name + "'");
|
|
678
|
+
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
679
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'set-component.tsx'), targetFile);
|
|
680
|
+
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
681
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
|
|
682
|
+
//replace variables in some of the copied files
|
|
683
|
+
yield replaceVariablesInFiles(targetFile, targetFile2);
|
|
684
|
+
let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
|
|
685
|
+
log(`Created a new set component in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
686
|
+
});
|
|
848
687
|
exports.createSetComponent = createSetComponent;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
_b.sent();
|
|
870
|
-
log("Created a new component template in ".concat(chalk_1["default"].magenta(targetFile.replace(basePath, ''))), "Created component stylesheet template in ".concat(chalk_1["default"].magenta(targetFile2.replace(basePath, ''))));
|
|
871
|
-
//if this is not a lincd app (but a lincd package instead)
|
|
872
|
-
if (!sourceFolder.includes('frontend')) {
|
|
873
|
-
indexPath = addLineToIndex("import './components/".concat(hyphenName, "';"), 'components');
|
|
874
|
-
log("Added an import of this file from ".concat(chalk_1["default"].magenta(indexPath)));
|
|
875
|
-
}
|
|
876
|
-
return [2 /*return*/];
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
});
|
|
880
|
-
};
|
|
688
|
+
const createComponent = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
689
|
+
let sourceFolder = getSourceFolder(basePath);
|
|
690
|
+
let targetFolder = ensureFolderExists(sourceFolder, 'components');
|
|
691
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
692
|
+
//copy default shape file
|
|
693
|
+
log("Creating files for component '" + name + "'");
|
|
694
|
+
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
695
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.tsx'), targetFile);
|
|
696
|
+
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
697
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
|
|
698
|
+
//replace variables in some of the copied files
|
|
699
|
+
yield replaceVariablesInFiles(targetFile, targetFile2);
|
|
700
|
+
log(`Created a new component template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created component stylesheet template in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`);
|
|
701
|
+
//if this is not a lincd app (but a lincd package instead)
|
|
702
|
+
if (!sourceFolder.includes('frontend')) {
|
|
703
|
+
//then also add an import to index
|
|
704
|
+
let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
|
|
705
|
+
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
881
708
|
exports.createComponent = createComponent;
|
|
882
|
-
|
|
883
|
-
if
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
'src/data/example-ontology.json.d.ts',
|
|
938
|
-
].forEach(function (f) {
|
|
939
|
-
var parts = f.split('/');
|
|
940
|
-
var newParts = __spreadArray([], __read(parts), false);
|
|
941
|
-
var _a = __read(newParts.pop().split('.')), name = _a[0], extensions = _a.slice(1);
|
|
942
|
-
var newName = hyphenName + '.' + extensions.join('.');
|
|
943
|
-
console.log('rename ', path_1["default"].join(targetFolder, f), path_1["default"].join.apply(path_1["default"], __spreadArray(__spreadArray([targetFolder], __read(newParts), false), [newName], false)));
|
|
944
|
-
fs_extra_1["default"].renameSync(path_1["default"].join(targetFolder, f), path_1["default"].join.apply(path_1["default"], __spreadArray(__spreadArray([targetFolder], __read(newParts), false), [newName], false)));
|
|
945
|
-
});
|
|
946
|
-
return [4 /*yield*/, (0, utils_1.execPromise)('yarn --version')["catch"](function (err) {
|
|
947
|
-
console.log('yarn probably not working');
|
|
948
|
-
return '';
|
|
949
|
-
})];
|
|
950
|
-
case 2:
|
|
951
|
-
version = (_c.sent());
|
|
952
|
-
installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
|
|
953
|
-
return [4 /*yield*/, (0, utils_1.execp)("cd ".concat(targetFolder, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
|
|
954
|
-
console.warn('Could not install dependencies');
|
|
955
|
-
})];
|
|
956
|
-
case 3:
|
|
957
|
-
_c.sent();
|
|
958
|
-
log("Prepared a new LINCD package in ".concat(chalk_1["default"].magenta(targetFolder)), "Run ".concat(chalk_1["default"].blueBright('yarn build'), " from this directory to build once"), "Or ".concat(chalk_1["default"].blueBright('yarn dev'), " to continuously rebuild on file changes"));
|
|
959
|
-
return [2 /*return*/];
|
|
960
|
-
}
|
|
961
|
-
});
|
|
709
|
+
const createPackage = (name, uriBase, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
710
|
+
//if ran with npx, basePath will be the root directory of the repository, even if we're executing from a sub folder (the root directory is where node_modules lives and package.json with workspaces)
|
|
711
|
+
//so we manually find a packages folder, if it exists we go into that.
|
|
712
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(basePath, 'packages'))) {
|
|
713
|
+
basePath = path_1.default.join(basePath, 'packages');
|
|
714
|
+
}
|
|
715
|
+
if (!name) {
|
|
716
|
+
console.warn('Please provide a name as the first argument');
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
//let's remove scope for variable names
|
|
720
|
+
let [packageName, scope, cleanPackageName] = name.match(/(@[\w\-]+\/)?([\w\-]+)/);
|
|
721
|
+
let targetFolder = ensureFolderExists(basePath, cleanPackageName);
|
|
722
|
+
if (!uriBase) {
|
|
723
|
+
uriBase = 'http://lincd.org/ont/' + name;
|
|
724
|
+
}
|
|
725
|
+
setVariable('uri_base', uriBase + '/');
|
|
726
|
+
//find @scope and the next part between 2 slashes after
|
|
727
|
+
//so @dacore/some-mod/lib/file.js
|
|
728
|
+
// --> match[0] = @dacore/some-mod
|
|
729
|
+
// --> match[1] = @dacore
|
|
730
|
+
// --> match[2] = some-mod
|
|
731
|
+
//but save full scoped package name under ${package_name}
|
|
732
|
+
setVariable('package_name', name);
|
|
733
|
+
//extra variable for clarity (will be same as 'name')
|
|
734
|
+
setVariable('output_file_name', name);
|
|
735
|
+
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(cleanPackageName);
|
|
736
|
+
log("Creating new LINCD package '" + name + "'");
|
|
737
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package'), targetFolder);
|
|
738
|
+
//replace variables in some of the copied files
|
|
739
|
+
yield Promise.all([
|
|
740
|
+
'src/index.ts',
|
|
741
|
+
'package.json',
|
|
742
|
+
'Gruntfile.js',
|
|
743
|
+
'src/package.ts',
|
|
744
|
+
'src/shapes/ExampleShapeClass.ts',
|
|
745
|
+
'src/ontologies/example-ontology.ts',
|
|
746
|
+
'src/data/example-ontology.json',
|
|
747
|
+
]
|
|
748
|
+
.map((f) => path_1.default.join(targetFolder, f))
|
|
749
|
+
.map((file) => {
|
|
750
|
+
return replaceVariablesInFile(file);
|
|
751
|
+
}));
|
|
752
|
+
//rename these to a file name similar to the pkg name
|
|
753
|
+
[
|
|
754
|
+
'src/ontologies/example-ontology.ts',
|
|
755
|
+
'src/data/example-ontology.json',
|
|
756
|
+
'src/data/example-ontology.json.d.ts',
|
|
757
|
+
].forEach((f) => {
|
|
758
|
+
let parts = f.split('/');
|
|
759
|
+
let newParts = [...parts];
|
|
760
|
+
let [name, ...extensions] = newParts.pop().split('.');
|
|
761
|
+
let newName = hyphenName + '.' + extensions.join('.');
|
|
762
|
+
console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
763
|
+
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
962
764
|
});
|
|
963
|
-
|
|
765
|
+
let version = (yield (0, utils_1.execPromise)('yarn --version').catch((err) => {
|
|
766
|
+
console.log('yarn probably not working');
|
|
767
|
+
return '';
|
|
768
|
+
}));
|
|
769
|
+
let installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
|
|
770
|
+
yield (0, utils_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
|
|
771
|
+
console.warn('Could not install dependencies');
|
|
772
|
+
});
|
|
773
|
+
log(`Prepared a new LINCD package in ${chalk_1.default.magenta(targetFolder)}`, `Run ${chalk_1.default.blueBright('yarn build')} from this directory to build once`, `Or ${chalk_1.default.blueBright('yarn dev')} to continuously rebuild on file changes`);
|
|
774
|
+
});
|
|
964
775
|
exports.createPackage = createPackage;
|
|
965
776
|
var getNextVersion = function (version) {
|
|
966
|
-
|
|
777
|
+
let parts = version.split('.');
|
|
967
778
|
return parts[0] + '.' + parts[1] + '.' + (parseInt(parts[2]) + 1).toString();
|
|
968
779
|
};
|
|
969
780
|
var getNextMajorVersion = function (version) {
|
|
970
|
-
|
|
781
|
+
let parts = version.split('.');
|
|
971
782
|
return (parseInt(parts[0]) + 1).toString() + '.0.0';
|
|
972
783
|
};
|
|
973
784
|
var getNextMinorVersion = function (version) {
|
|
974
|
-
|
|
785
|
+
let parts = version.split('.');
|
|
975
786
|
return parts[0] + '.' + (parseInt(parts[1]) + 1).toString() + '.0';
|
|
976
787
|
};
|
|
977
788
|
var buildFailed = function (output) {
|
|
@@ -1014,11 +825,11 @@ var buildFailed = function (output) {
|
|
|
1014
825
|
console.warn('Not a project');
|
|
1015
826
|
}
|
|
1016
827
|
});*/
|
|
1017
|
-
|
|
1018
|
-
if (fs_extra_1
|
|
1019
|
-
var pack = JSON.parse(fs_extra_1
|
|
1020
|
-
|
|
1021
|
-
|
|
828
|
+
const register = function (registryURL) {
|
|
829
|
+
if (fs_extra_1.default.existsSync(process.cwd() + '/package.json')) {
|
|
830
|
+
var pack = JSON.parse(fs_extra_1.default.readFileSync(process.cwd() + '/package.json', 'utf8'));
|
|
831
|
+
let version = pack.version;
|
|
832
|
+
let packageName = pack.name;
|
|
1022
833
|
// let author = pack.author;
|
|
1023
834
|
// let description = pack.description;
|
|
1024
835
|
//
|
|
@@ -1026,173 +837,140 @@ var register = function (registryURL) {
|
|
|
1026
837
|
// if (pack.author.name) {
|
|
1027
838
|
// authorName = pack.author.name;
|
|
1028
839
|
// }
|
|
1029
|
-
console.log(chalk_1
|
|
840
|
+
console.log(chalk_1.default.cyan('registering package ' + packageName + ' ' + version + ' in the LINCD registry'));
|
|
1030
841
|
return fetch(registryURL + '/register', {
|
|
1031
842
|
method: 'POST',
|
|
1032
843
|
headers: {
|
|
1033
844
|
Accept: 'application/json, text/plain, */*',
|
|
1034
|
-
'Content-Type': 'application/json'
|
|
845
|
+
'Content-Type': 'application/json',
|
|
1035
846
|
},
|
|
1036
|
-
body: JSON.stringify({ package: packageName, version
|
|
847
|
+
body: JSON.stringify({ package: packageName, version }),
|
|
848
|
+
// body: JSON.stringify({package: packageName, version, author}),
|
|
1037
849
|
})
|
|
1038
|
-
.then(
|
|
1039
|
-
.then(
|
|
850
|
+
.then((res) => res.json())
|
|
851
|
+
.then((json) => {
|
|
1040
852
|
if (json.error) {
|
|
1041
|
-
console.log(chalk_1
|
|
853
|
+
console.log(chalk_1.default.red('Response: ' + json.error));
|
|
1042
854
|
}
|
|
1043
855
|
else if (json.result) {
|
|
1044
|
-
console.log(chalk_1
|
|
856
|
+
console.log(chalk_1.default.blueBright('Response: ') + json.result);
|
|
1045
857
|
if (json.warning) {
|
|
1046
|
-
console.log(chalk_1
|
|
858
|
+
console.log(chalk_1.default.red('Warning: ') + json.warning);
|
|
1047
859
|
}
|
|
1048
860
|
}
|
|
1049
|
-
})
|
|
1050
|
-
|
|
861
|
+
})
|
|
862
|
+
.catch((err) => {
|
|
863
|
+
console.warn(chalk_1.default.red('Warning: ') + 'Could not connect to LINCD registry');
|
|
1051
864
|
});
|
|
1052
865
|
}
|
|
1053
866
|
else {
|
|
1054
|
-
console.warn(chalk_1
|
|
867
|
+
console.warn(chalk_1.default.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
|
|
1055
868
|
}
|
|
1056
869
|
};
|
|
1057
870
|
exports.register = register;
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
871
|
+
const buildMetadata = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
872
|
+
// require('@babel/register')({extensions: ['js', '.ts', '.tsx']});
|
|
873
|
+
//NOTE: we can not rely on the LincdWebApp shape from lincd-server here, because that would make the initial build of all modules a lot trickier
|
|
874
|
+
//see, CLI needs to be built as one of the first things in order to build other things. So it cannot rely on lincd-server, which relies on 10 other packages
|
|
875
|
+
let app;
|
|
876
|
+
//set the URL of the app as the URI of its node
|
|
877
|
+
let envVars = yield (0, env_cmd_1.GetEnvVars)({
|
|
878
|
+
envFile: {
|
|
879
|
+
filePath: '.env-cmdrc.json',
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
if (envVars[process.env.NODE_ENV] && envVars[process.env.NODE_ENV].SITE_ROOT) {
|
|
883
|
+
//get the site root of the current environment
|
|
884
|
+
app = models_1.NamedNode.getOrCreate(envVars[process.env.NODE_ENV].SITE_ROOT);
|
|
885
|
+
}
|
|
886
|
+
else {
|
|
887
|
+
warn('Cannot find environment variable SITE_ROOT. Make sure SITE_ROOT is set (likely in .env-cmdrc.json) for the current environment: ' +
|
|
888
|
+
process.env.NODE_ENV);
|
|
889
|
+
app = models_1.NamedNode.create();
|
|
890
|
+
}
|
|
891
|
+
let updatedPaths = [];
|
|
892
|
+
var localPackagePaths = getLocalPackagePaths();
|
|
893
|
+
//prepare output path
|
|
894
|
+
let metadataFolder = path_1.default.join(process.cwd(), 'data', 'metadata');
|
|
895
|
+
yield fs_extra_1.default.ensureDir(metadataFolder); //{recursive:true} but not needed with fs-extra
|
|
896
|
+
for (const [packageCodeName, packagePath, lincdPackagePath, isAppPackage] of localPackagePaths) {
|
|
897
|
+
let errors = false;
|
|
898
|
+
//TODO: check if this resolves, if not, skip it (for initial setup)
|
|
899
|
+
Promise.resolve().then(() => __importStar(require('lincd-modules/lib/scripts/package-metadata.js'))).then((script) => __awaiter(void 0, void 0, void 0, function* () {
|
|
900
|
+
yield script.getPackageMetadata(packagePath, lincdPackagePath).then((response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
901
|
+
if (response.errors.length > 0) {
|
|
902
|
+
// console.log(JSON.stringify(response));
|
|
903
|
+
warn('Error processing ' + packagePath + ':\n' + response.errors.join('\n'));
|
|
904
|
+
// throw response
|
|
905
|
+
errors = true;
|
|
1073
906
|
}
|
|
1074
907
|
else {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
updatedPaths = [];
|
|
1080
|
-
localPackagePaths = getLocalPackagePaths();
|
|
1081
|
-
metadataFolder = path_1["default"].join(process.cwd(), 'data', 'metadata');
|
|
1082
|
-
return [4 /*yield*/, fs_extra_1["default"].ensureDir(metadataFolder)];
|
|
1083
|
-
case 2:
|
|
1084
|
-
_c.sent(); //{recursive:true} but not needed with fs-extra
|
|
1085
|
-
_loop_1 = function (packageCodeName, packagePath, lincdPackagePath, isAppPackage) {
|
|
1086
|
-
var errors = false;
|
|
1087
|
-
//TODO: check if this resolves, if not, skip it (for initial setup)
|
|
1088
|
-
Promise.resolve().then(function () { return __importStar(require('lincd-modules/lib/scripts/package-metadata.js')); }).then(function (script) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1089
|
-
return __generator(this, function (_a) {
|
|
1090
|
-
switch (_a.label) {
|
|
1091
|
-
case 0: return [4 /*yield*/, script.getPackageMetadata(packagePath, lincdPackagePath).then(function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1092
|
-
var pkgNode, lincdApp, packageMetaData_1, metadataFile_1;
|
|
1093
|
-
return __generator(this, function (_a) {
|
|
1094
|
-
switch (_a.label) {
|
|
1095
|
-
case 0:
|
|
1096
|
-
if (!(response.errors.length > 0)) return [3 /*break*/, 1];
|
|
1097
|
-
// console.log(JSON.stringify(response));
|
|
1098
|
-
warn('Error processing ' + packagePath + ':\n' + response.errors.join('\n'));
|
|
1099
|
-
// throw response
|
|
1100
|
-
errors = true;
|
|
1101
|
-
return [3 /*break*/, 3];
|
|
1102
|
-
case 1:
|
|
1103
|
-
if (!response.packageUri) {
|
|
1104
|
-
console.warn("No package URI from meta data. Not building meta data for this package");
|
|
1105
|
-
return [2 /*return*/];
|
|
1106
|
-
}
|
|
1107
|
-
pkgNode = models_1.NamedNode.getOrCreate(response.packageUri);
|
|
1108
|
-
lincdApp = (0, NameSpace_1.createNameSpace)('http://lincd.org/ont/lincd-app/');
|
|
1109
|
-
Prefix_1.Prefix.add('lincdApp', 'http://lincd.org/ont/lincd-app/');
|
|
1110
|
-
if (isAppPackage) {
|
|
1111
|
-
//Note: this needs to match with LincdWebApp.ownPackage accessor;
|
|
1112
|
-
app.overwrite(lincdApp('ownPackage'), pkgNode);
|
|
1113
|
-
}
|
|
1114
|
-
else {
|
|
1115
|
-
//Note: this needs to match with LincdWebApp.packages accessor;
|
|
1116
|
-
app.set(lincdApp('maintainsPackage'), pkgNode);
|
|
1117
|
-
}
|
|
1118
|
-
packageMetaData_1 = JSON.stringify(response.result, null, 2);
|
|
1119
|
-
metadataFile_1 = path_1["default"].join(metadataFolder, packageCodeName + '.json');
|
|
1120
|
-
return [4 /*yield*/, fs_extra_1["default"].writeFile(metadataFile_1, packageMetaData_1).then(function () {
|
|
1121
|
-
updatedPaths.push(metadataFile_1);
|
|
1122
|
-
})];
|
|
1123
|
-
case 2:
|
|
1124
|
-
_a.sent();
|
|
1125
|
-
_a.label = 3;
|
|
1126
|
-
case 3: return [2 /*return*/];
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
}); })];
|
|
1130
|
-
case 1:
|
|
1131
|
-
_a.sent();
|
|
1132
|
-
return [2 /*return*/];
|
|
1133
|
-
}
|
|
1134
|
-
});
|
|
1135
|
-
}); });
|
|
1136
|
-
};
|
|
1137
|
-
try {
|
|
1138
|
-
for (localPackagePaths_1 = __values(localPackagePaths), localPackagePaths_1_1 = localPackagePaths_1.next(); !localPackagePaths_1_1.done; localPackagePaths_1_1 = localPackagePaths_1.next()) {
|
|
1139
|
-
_a = __read(localPackagePaths_1_1.value, 4), packageCodeName = _a[0], packagePath = _a[1], lincdPackagePath = _a[2], isAppPackage = _a[3];
|
|
1140
|
-
_loop_1(packageCodeName, packagePath, lincdPackagePath, isAppPackage);
|
|
908
|
+
if (!response.packageUri) {
|
|
909
|
+
console.warn("No package URI from meta data. Not building meta data for this package");
|
|
910
|
+
return;
|
|
1141
911
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
912
|
+
let pkgNode = models_1.NamedNode.getOrCreate(response.packageUri);
|
|
913
|
+
//connect the packages to the app
|
|
914
|
+
let lincdApp = (0, NameSpace_1.createNameSpace)('http://lincd.org/ont/lincd-app/');
|
|
915
|
+
Prefix_1.Prefix.add('lincdApp', 'http://lincd.org/ont/lincd-app/');
|
|
916
|
+
if (isAppPackage) {
|
|
917
|
+
//Note: this needs to match with LincdWebApp.ownPackage accessor;
|
|
918
|
+
app.overwrite(lincdApp('ownPackage'), pkgNode);
|
|
1147
919
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
920
|
+
else {
|
|
921
|
+
//Note: this needs to match with LincdWebApp.packages accessor;
|
|
922
|
+
app.set(lincdApp('maintainsPackage'), pkgNode);
|
|
923
|
+
}
|
|
924
|
+
//write this graph to a jsonld file
|
|
925
|
+
let packageMetaData = JSON.stringify(response.result, null, 2);
|
|
926
|
+
let metadataFile = path_1.default.join(metadataFolder, packageCodeName + '.json');
|
|
927
|
+
yield fs_extra_1.default.writeFile(metadataFile, packageMetaData).then(() => {
|
|
1155
928
|
updatedPaths.push(metadataFile);
|
|
1156
|
-
})
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
}));
|
|
932
|
+
}));
|
|
933
|
+
//enable this when testing if you don't want to continue with building other metadata when an errors occur
|
|
934
|
+
// if (errors) break;
|
|
935
|
+
}
|
|
936
|
+
let packageMetaData = yield JSONLDWriter_1.JSONLDWriter.stringify(app, process.env.NODE_ENV === 'development');
|
|
937
|
+
let metadataFile = path_1.default.join(metadataFolder, '_app.json');
|
|
938
|
+
yield fs_extra_1.default.writeFile(metadataFile, packageMetaData).then(() => {
|
|
939
|
+
updatedPaths.push(metadataFile);
|
|
1161
940
|
});
|
|
1162
|
-
|
|
941
|
+
return updatedPaths;
|
|
942
|
+
});
|
|
1163
943
|
exports.buildMetadata = buildMetadata;
|
|
1164
944
|
function getLocalPackagePaths() {
|
|
1165
|
-
|
|
945
|
+
let packagePaths = [];
|
|
1166
946
|
//add the APP package itself
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
if (fs_extra_1
|
|
1170
|
-
|
|
947
|
+
let appPackagePath = process.cwd();
|
|
948
|
+
let appLincdPackagePath = path_1.default.join(appPackagePath, 'frontend', 'src', 'package.ts');
|
|
949
|
+
if (fs_extra_1.default.existsSync(appPackagePath)) {
|
|
950
|
+
let packageJSON = (0, utils_1.getPackageJSON)(appPackagePath);
|
|
1171
951
|
packagePaths.push([packageJSON.name, appPackagePath, appLincdPackagePath, true]);
|
|
1172
952
|
}
|
|
1173
953
|
else {
|
|
1174
954
|
console.log('Not a LINCD app');
|
|
1175
955
|
}
|
|
1176
956
|
//NOTE: we could also switch to checking 'workspaces'?
|
|
1177
|
-
|
|
1178
|
-
if (fs_extra_1
|
|
1179
|
-
|
|
1180
|
-
localPackages.forEach(
|
|
957
|
+
let packagesFolder = path_1.default.join(process.cwd(), 'packages');
|
|
958
|
+
if (fs_extra_1.default.existsSync(packagesFolder)) {
|
|
959
|
+
let localPackages = fs_extra_1.default.readdirSync(packagesFolder);
|
|
960
|
+
localPackages.forEach((packageFolderName) => {
|
|
1181
961
|
packagePaths.push([
|
|
1182
962
|
packageFolderName,
|
|
1183
|
-
path_1
|
|
1184
|
-
path_1
|
|
963
|
+
path_1.default.join(packagesFolder, packageFolderName),
|
|
964
|
+
path_1.default.join(packagesFolder, packageFolderName, 'lib', 'package.js'),
|
|
1185
965
|
]);
|
|
1186
966
|
});
|
|
1187
967
|
}
|
|
1188
968
|
return packagePaths;
|
|
1189
969
|
}
|
|
1190
|
-
|
|
1191
|
-
if (packagePath === void 0) { packagePath = process.cwd(); }
|
|
1192
|
-
if (logResults === void 0) { logResults = true; }
|
|
970
|
+
const buildPackage = (target, target2, packagePath = process.cwd(), logResults = true) => {
|
|
1193
971
|
if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
|
|
1194
|
-
if (!fs_extra_1
|
|
1195
|
-
console.warn(
|
|
972
|
+
if (!fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'Gruntfile.js'))) {
|
|
973
|
+
console.warn(`No Gruntfile found at ${packagePath}\\Gruntfile.js. Cannot build.`);
|
|
1196
974
|
return;
|
|
1197
975
|
}
|
|
1198
976
|
var nodeEnv = '';
|
|
@@ -1218,9 +996,9 @@ var buildPackage = function (target, target2, packagePath, logResults) {
|
|
|
1218
996
|
(target ? '-' + target : '') +
|
|
1219
997
|
(target2 ? '-' + target2 : '') +
|
|
1220
998
|
' --color');
|
|
1221
|
-
|
|
999
|
+
let method = logResults ? utils_1.execp : utils_1.execPromise;
|
|
1222
1000
|
//execute the command to build the method, and provide the current work directory as option
|
|
1223
|
-
return method(nodeEnv + 'grunt build' + (target ? '-' + target : '') + (target2 ? '-' + target2 : '') + ' --color', false, false, { cwd: packagePath })
|
|
1001
|
+
return method(nodeEnv + 'grunt build' + (target ? '-' + target : '') + (target2 ? '-' + target2 : '') + ' --color', false, false, { cwd: packagePath }).catch((err) => {
|
|
1224
1002
|
process.exit(1);
|
|
1225
1003
|
});
|
|
1226
1004
|
}
|
|
@@ -1229,54 +1007,45 @@ var buildPackage = function (target, target2, packagePath, logResults) {
|
|
|
1229
1007
|
}
|
|
1230
1008
|
};
|
|
1231
1009
|
exports.buildPackage = buildPackage;
|
|
1232
|
-
|
|
1010
|
+
const getLastBuildTime = (packagePath) => {
|
|
1233
1011
|
return getLastModifiedFile(packagePath + '/@(builds|lib|dist)/**/*.js');
|
|
1234
1012
|
};
|
|
1235
|
-
|
|
1013
|
+
const getLastModifiedSourceTime = (packagePath) => {
|
|
1236
1014
|
return getLastModifiedFile(packagePath + '/@(src|data|scss)/**/*', {
|
|
1237
|
-
ignore: [packagePath + '/**/*.scss.json', packagePath + '/**/*.d.ts']
|
|
1015
|
+
ignore: [packagePath + '/**/*.scss.json', packagePath + '/**/*.d.ts'],
|
|
1238
1016
|
});
|
|
1239
1017
|
};
|
|
1240
|
-
|
|
1018
|
+
const getLastCommitTime = (packagePath) => {
|
|
1241
1019
|
// console.log(`git log -1 --format=%ci -- ${packagePath}`);
|
|
1242
1020
|
// process.exit();
|
|
1243
|
-
return (0, utils_1.execPromise)(
|
|
1244
|
-
.then(
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
// log(packagePath,result,lastCommit);
|
|
1256
|
-
// log(changes);
|
|
1257
|
-
return [2 /*return*/, { date: lastCommitDate, changes: changes, commitId: commitId }];
|
|
1258
|
-
}
|
|
1259
|
-
});
|
|
1260
|
-
}); })["catch"](function (_a) {
|
|
1261
|
-
var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
|
|
1262
|
-
debugInfo(chalk_1["default"].red('Git error: ') + error.message.toString());
|
|
1021
|
+
return (0, utils_1.execPromise)(`git log -1 --format="%h %ci" -- ${packagePath}`)
|
|
1022
|
+
.then((result) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1023
|
+
let commitId = result.substring(0, result.indexOf(" "));
|
|
1024
|
+
let date = result.substring(commitId.length + 1);
|
|
1025
|
+
let lastCommitDate = new Date(date);
|
|
1026
|
+
let changes = yield (0, utils_1.execPromise)(`git show --stat --oneline ${commitId} -- ${packagePath}`);
|
|
1027
|
+
// log(packagePath,result,lastCommit);
|
|
1028
|
+
// log(changes);
|
|
1029
|
+
return { date: lastCommitDate, changes, commitId };
|
|
1030
|
+
}))
|
|
1031
|
+
.catch(({ error, stdout, stderr }) => {
|
|
1032
|
+
debugInfo(chalk_1.default.red('Git error: ') + error.message.toString());
|
|
1263
1033
|
return null;
|
|
1264
1034
|
});
|
|
1265
1035
|
};
|
|
1266
|
-
|
|
1267
|
-
if (config === void 0) { config = {}; }
|
|
1036
|
+
const getLastModifiedFile = (filePath, config = {}) => {
|
|
1268
1037
|
var files = glob.sync(filePath, config);
|
|
1269
1038
|
// console.log(files.join(" - "));
|
|
1270
1039
|
var lastModifiedName;
|
|
1271
1040
|
var lastModified;
|
|
1272
1041
|
var lastModifiedTime = 0;
|
|
1273
|
-
files.forEach(
|
|
1274
|
-
if (fs_extra_1
|
|
1042
|
+
files.forEach((fileName) => {
|
|
1043
|
+
if (fs_extra_1.default.lstatSync(fileName).isDirectory()) {
|
|
1275
1044
|
// console.log("skipping directory "+fileName);
|
|
1276
1045
|
return;
|
|
1277
1046
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1047
|
+
let mtime = fs_extra_1.default.statSync(path_1.default.join(fileName)).mtime;
|
|
1048
|
+
let modifiedTime = mtime.getTime();
|
|
1280
1049
|
if (modifiedTime > lastModifiedTime) {
|
|
1281
1050
|
// console.log(fileName,mtime);
|
|
1282
1051
|
lastModifiedName = fileName;
|
|
@@ -1284,112 +1053,109 @@ var getLastModifiedFile = function (filePath, config) {
|
|
|
1284
1053
|
lastModifiedTime = modifiedTime;
|
|
1285
1054
|
}
|
|
1286
1055
|
});
|
|
1287
|
-
return { lastModified
|
|
1056
|
+
return { lastModified, lastModifiedName, lastModifiedTime };
|
|
1288
1057
|
};
|
|
1289
|
-
var publishUpdated = function (test) {
|
|
1290
|
-
|
|
1291
|
-
if (test === void 0) { test = false; }
|
|
1292
|
-
var packages = getLocalLincdModules();
|
|
1058
|
+
var publishUpdated = function (test = false) {
|
|
1059
|
+
let packages = getLocalLincdModules();
|
|
1293
1060
|
var p = Promise.resolve('');
|
|
1294
|
-
|
|
1295
|
-
|
|
1061
|
+
let packagesLeft = packages.length;
|
|
1062
|
+
let results = [];
|
|
1296
1063
|
log('Checking which packages need to be published by comparing last published date with last git commit');
|
|
1297
1064
|
// p = Promise.all(packages.map((pckg) => {
|
|
1298
|
-
packages.forEach(
|
|
1065
|
+
packages.forEach((pckg) => {
|
|
1299
1066
|
p = p
|
|
1300
|
-
.then(
|
|
1067
|
+
.then((previousResult) => {
|
|
1301
1068
|
// progressUpdate(packagesLeft-- + ' packages left. Now checking ' + pckg.packageName);
|
|
1302
1069
|
log('# Checking package ' + pckg.packageName);
|
|
1303
1070
|
// log('# Requesting ' + 'yarn info '+pkg.packageName+' --json');
|
|
1304
1071
|
// return execPromise('yarn info '+pkg.packageName+' --json').then((output:string) => {
|
|
1305
1072
|
// console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
|
|
1306
1073
|
// return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
|
|
1307
|
-
|
|
1074
|
+
let shouldPublish;
|
|
1308
1075
|
var pack = (0, utils_1.getPackageJSON)(pckg.path);
|
|
1309
|
-
|
|
1076
|
+
let version = getNextVersion(pack.version);
|
|
1310
1077
|
if (pack.private) {
|
|
1311
1078
|
shouldPublish = false;
|
|
1312
|
-
debugInfo(chalk_1
|
|
1313
|
-
return chalk_1
|
|
1079
|
+
debugInfo(chalk_1.default.blue('--> is private, skipping'));
|
|
1080
|
+
return chalk_1.default.gray(pckg.packageName + ' is private');
|
|
1314
1081
|
// return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
|
|
1315
1082
|
}
|
|
1316
1083
|
console.log("testing npm");
|
|
1317
1084
|
return (0, utils_1.execPromise)('npm info ' + pckg.packageName + ' --json')
|
|
1318
|
-
.then(
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1085
|
+
.then((output) => __awaiter(this, void 0, void 0, function* () {
|
|
1086
|
+
console.log("testing npm done");
|
|
1087
|
+
var info;
|
|
1088
|
+
try {
|
|
1089
|
+
if (output == '' || output.includes('E404')) {
|
|
1090
|
+
debugInfo('Empty or 404 response from `npm info`. This package was probably not published before');
|
|
1091
|
+
// throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
|
|
1092
|
+
// return;
|
|
1093
|
+
shouldPublish = true;
|
|
1094
|
+
//don't patch the version number (default, see above), use the current version
|
|
1095
|
+
version = pack.version;
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
info = JSON.parse(output);
|
|
1099
|
+
}
|
|
1100
|
+
if (info) {
|
|
1101
|
+
let lastPublish;
|
|
1102
|
+
//yarn:
|
|
1103
|
+
// let lastPublish = info.data.time[info.data.version];
|
|
1104
|
+
lastPublish = info.time[info.version];
|
|
1105
|
+
// }
|
|
1106
|
+
// catch (e) {
|
|
1107
|
+
// console.log(info);
|
|
1108
|
+
// console.error(chalk.red("Could not parse response from npm info. Format may have changed?"));
|
|
1109
|
+
// process.exit();
|
|
1110
|
+
// }
|
|
1111
|
+
let lastPublishDate = new Date(lastPublish);
|
|
1112
|
+
// let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
|
|
1113
|
+
let lastCommitInfo = yield getLastCommitTime(pckg.path);
|
|
1114
|
+
if (!lastCommitInfo) {
|
|
1115
|
+
shouldPublish = false;
|
|
1116
|
+
debugInfo('Could not determine last git commit');
|
|
1117
|
+
// return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
|
|
1118
|
+
return chalk_1.default.red(pckg.packageName + ' - could not determine last commit');
|
|
1119
|
+
}
|
|
1120
|
+
else {
|
|
1121
|
+
//NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
|
|
1122
|
+
//SO: now you NEED TO commit before it picks up that you should publish
|
|
1123
|
+
shouldPublish = lastPublishDate.getTime() < lastCommitInfo.date.getTime();
|
|
1124
|
+
//ignore changes to package.json if that's the only change, because when we publish the version number changes, which is then committed
|
|
1125
|
+
//(note there is always 2 lines for commit info + number of files changed)
|
|
1126
|
+
let changedFiles = lastCommitInfo.changes.split("\n").filter(line => line.includes("|"));
|
|
1127
|
+
let numberOfFilesChanges = changedFiles.length;
|
|
1128
|
+
// console.log("CHECK "+lastCommitInfo.changes.includes("package.json")+" - "+numberOfFilesChanges)
|
|
1129
|
+
if (shouldPublish && lastCommitInfo.changes.includes("package.json") && numberOfFilesChanges === 1) {
|
|
1348
1130
|
shouldPublish = false;
|
|
1349
|
-
debugInfo('Could not determine last git commit');
|
|
1350
|
-
// return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
|
|
1351
|
-
return [2 /*return*/, chalk_1["default"].red(pckg.packageName + ' - could not determine last commit')];
|
|
1352
|
-
}
|
|
1353
|
-
else {
|
|
1354
|
-
//NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
|
|
1355
|
-
//SO: now you NEED TO commit before it picks up that you should publish
|
|
1356
|
-
shouldPublish = lastPublishDate.getTime() < lastCommitInfo.date.getTime();
|
|
1357
|
-
changedFiles = lastCommitInfo.changes.split("\n").filter(function (line) { return line.includes("|"); });
|
|
1358
|
-
numberOfFilesChanges = changedFiles.length;
|
|
1359
|
-
// console.log("CHECK "+lastCommitInfo.changes.includes("package.json")+" - "+numberOfFilesChanges)
|
|
1360
|
-
if (shouldPublish && lastCommitInfo.changes.includes("package.json") && numberOfFilesChanges === 1) {
|
|
1361
|
-
shouldPublish = false;
|
|
1362
|
-
}
|
|
1363
|
-
if (shouldPublish) {
|
|
1364
|
-
log(chalk_1["default"].magenta(pckg.packageName) + ' should be published because:');
|
|
1365
|
-
log(lastPublishDate.toDateString() +
|
|
1366
|
-
' ' +
|
|
1367
|
-
lastPublishDate.toTimeString() +
|
|
1368
|
-
' published ' +
|
|
1369
|
-
info.version);
|
|
1370
|
-
log(lastCommitInfo.date.toDateString() + ' ' + new Date(lastCommitInfo.date).toTimeString() + ' source last committed:');
|
|
1371
|
-
log(lastCommitInfo.changes);
|
|
1372
|
-
}
|
|
1373
1131
|
}
|
|
1374
|
-
_a.label = 3;
|
|
1375
|
-
case 3: return [3 /*break*/, 5];
|
|
1376
|
-
case 4:
|
|
1377
|
-
err_1 = _a.sent();
|
|
1378
|
-
// var stats = fs.statSync(path.join(packageDirectory));
|
|
1379
|
-
// var files = fs.readdirSync(path.join(packageDirectory,'src'));
|
|
1380
|
-
console.log(chalk_1["default"].red(pckg.packageName + ' failed: ' + err_1.message + '\n'));
|
|
1381
|
-
console.warn('Returned JSON from npm: ' + output);
|
|
1382
|
-
// return previousResult + ' ' + chalk.red(pckg.packageName + ' failed: ' + err.message + '\n');
|
|
1383
|
-
return [2 /*return*/, chalk_1["default"].red(pckg.packageName + ' failed: ' + err_1.message)];
|
|
1384
|
-
case 5:
|
|
1385
1132
|
if (shouldPublish) {
|
|
1386
|
-
|
|
1133
|
+
log(chalk_1.default.magenta(pckg.packageName) + ' should be published because:');
|
|
1134
|
+
log(lastPublishDate.toDateString() +
|
|
1135
|
+
' ' +
|
|
1136
|
+
lastPublishDate.toTimeString() +
|
|
1137
|
+
' published ' +
|
|
1138
|
+
info.version);
|
|
1139
|
+
log(lastCommitInfo.date.toDateString() + ' ' + new Date(lastCommitInfo.date).toTimeString() + ' source last committed:');
|
|
1140
|
+
log(lastCommitInfo.changes);
|
|
1387
1141
|
}
|
|
1388
|
-
|
|
1142
|
+
}
|
|
1389
1143
|
}
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1144
|
+
}
|
|
1145
|
+
catch (err) {
|
|
1146
|
+
// var stats = fs.statSync(path.join(packageDirectory));
|
|
1147
|
+
// var files = fs.readdirSync(path.join(packageDirectory,'src'));
|
|
1148
|
+
console.log(chalk_1.default.red(pckg.packageName + ' failed: ' + err.message + '\n'));
|
|
1149
|
+
console.warn('Returned JSON from npm: ' + output);
|
|
1150
|
+
// return previousResult + ' ' + chalk.red(pckg.packageName + ' failed: ' + err.message + '\n');
|
|
1151
|
+
return chalk_1.default.red(pckg.packageName + ' failed: ' + err.message);
|
|
1152
|
+
}
|
|
1153
|
+
if (shouldPublish) {
|
|
1154
|
+
return (0, exports.publishPackage)(pckg, test, info, version);
|
|
1155
|
+
}
|
|
1156
|
+
return chalk_1.default.blue(pckg.packageName) + ' latest version is up to date';
|
|
1157
|
+
}))
|
|
1158
|
+
.catch(({ error, stdout, stderr }) => {
|
|
1393
1159
|
if (error) {
|
|
1394
1160
|
console.log(error.message);
|
|
1395
1161
|
}
|
|
@@ -1400,19 +1166,20 @@ var publishUpdated = function (test) {
|
|
|
1400
1166
|
console.log(stderr);
|
|
1401
1167
|
}
|
|
1402
1168
|
// return previousResult + ' ' + chalk.red(pckg.packageName + ' failed\n');
|
|
1403
|
-
console.warn(chalk_1
|
|
1404
|
-
return chalk_1
|
|
1169
|
+
console.warn(chalk_1.default.red(pckg.packageName + ' failed'));
|
|
1170
|
+
return chalk_1.default.red(pckg.packageName + ' failed');
|
|
1405
1171
|
});
|
|
1406
1172
|
})
|
|
1407
|
-
.then(
|
|
1173
|
+
.then((res) => {
|
|
1408
1174
|
log(res);
|
|
1409
1175
|
results.push(res);
|
|
1410
|
-
})
|
|
1411
|
-
|
|
1412
|
-
|
|
1176
|
+
})
|
|
1177
|
+
.catch((err) => {
|
|
1178
|
+
console.warn(chalk_1.default.red(pckg.packageName + ' failed: ' + err.toString()));
|
|
1179
|
+
results.push(chalk_1.default.red(pckg.packageName + ' failed: ' + err.toString()));
|
|
1413
1180
|
});
|
|
1414
1181
|
});
|
|
1415
|
-
return p.then(
|
|
1182
|
+
return p.then(() => {
|
|
1416
1183
|
// if (messages == '')
|
|
1417
1184
|
// {
|
|
1418
1185
|
// console.log('All published packages are already up-to-date.');
|
|
@@ -1424,184 +1191,214 @@ var publishUpdated = function (test) {
|
|
|
1424
1191
|
});
|
|
1425
1192
|
};
|
|
1426
1193
|
exports.publishUpdated = publishUpdated;
|
|
1427
|
-
function getEnvJsonPath(relativeToPath) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
if (!(i <= 10)) return [3 /*break*/, 4];
|
|
1442
|
-
return [4 /*yield*/, (0, get_env_vars_1.getEnvFile)({ filePath: relativeToPath + path + '.env.json' })["catch"](function (err) {
|
|
1443
|
-
return null;
|
|
1444
|
-
})];
|
|
1445
|
-
case 2:
|
|
1446
|
-
envFile = _a.sent();
|
|
1447
|
-
if (envFile) {
|
|
1448
|
-
//note: we're getting the actual contents here, so we could also use that more directly?
|
|
1449
|
-
return [2 /*return*/, path + '.env.json'];
|
|
1450
|
-
}
|
|
1451
|
-
path += '../';
|
|
1452
|
-
_a.label = 3;
|
|
1453
|
-
case 3:
|
|
1454
|
-
i++;
|
|
1455
|
-
return [3 /*break*/, 1];
|
|
1456
|
-
case 4: return [2 /*return*/];
|
|
1194
|
+
function getEnvJsonPath(relativeToPath = process.cwd()) {
|
|
1195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1196
|
+
let path = '';
|
|
1197
|
+
if (!relativeToPath.endsWith('/')) {
|
|
1198
|
+
relativeToPath += '/';
|
|
1199
|
+
}
|
|
1200
|
+
// let path = './';
|
|
1201
|
+
for (let i = 0; i <= 10; i++) {
|
|
1202
|
+
let envFile = yield (0, get_env_vars_1.getEnvFile)({ filePath: relativeToPath + path + '.env.json' }).catch(err => {
|
|
1203
|
+
return null;
|
|
1204
|
+
});
|
|
1205
|
+
if (envFile) {
|
|
1206
|
+
//note: we're getting the actual contents here, so we could also use that more directly?
|
|
1207
|
+
return path + '.env.json';
|
|
1457
1208
|
}
|
|
1458
|
-
|
|
1209
|
+
path += '../';
|
|
1210
|
+
}
|
|
1459
1211
|
});
|
|
1460
1212
|
}
|
|
1461
1213
|
var publishPackage = function (pkg, test, info, publishVersion) {
|
|
1462
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1489
|
-
res.indexOf('Could not publish') !== -1 ||
|
|
1490
|
-
res.indexOf("Couldn't publish") !== -1) {
|
|
1491
|
-
console.log(res);
|
|
1492
|
-
return chalk_1["default"].red(pkg.packageName + ' failed\n');
|
|
1493
|
-
}
|
|
1494
|
-
console.log('Successfully published ' + chalk_1["default"].green(pkg.path) + ' ' + chalk_1["default"].magenta(publishVersion));
|
|
1495
|
-
return chalk_1["default"].green(pkg.packageName) + ' published ' + chalk_1["default"].magenta(publishVersion);
|
|
1496
|
-
})["catch"](function (_a) {
|
|
1497
|
-
var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
|
|
1498
|
-
console.log(chalk_1["default"].red('Failed to publish: ' + error.message));
|
|
1499
|
-
return chalk_1["default"].red(pkg.packageName + ' failed to publish');
|
|
1500
|
-
})];
|
|
1214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1215
|
+
if (!pkg) {
|
|
1216
|
+
let localPackageJson = (0, utils_1.getPackageJSON)();
|
|
1217
|
+
pkg = {
|
|
1218
|
+
path: process.cwd(),
|
|
1219
|
+
packageName: localPackageJson.name,
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
if (!publishVersion) {
|
|
1223
|
+
publishVersion = info ? getNextVersion(info.version) : 'patch';
|
|
1224
|
+
}
|
|
1225
|
+
if (test) {
|
|
1226
|
+
debugInfo('should publish ' + pkg.packageName + ' ' + publishVersion);
|
|
1227
|
+
//when testing what needs to be published
|
|
1228
|
+
return chalk_1.default.blue(pkg.packageName + ' should publish');
|
|
1229
|
+
}
|
|
1230
|
+
console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
|
|
1231
|
+
//looking for an .env.json file in our workspace, which may store our NPM AUTH key
|
|
1232
|
+
let envJsonPath = yield getEnvJsonPath(pkg.path);
|
|
1233
|
+
return (0, utils_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
|
|
1234
|
+
.then((res) => {
|
|
1235
|
+
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1236
|
+
res.indexOf('Could not publish') !== -1 ||
|
|
1237
|
+
res.indexOf("Couldn't publish") !== -1) {
|
|
1238
|
+
console.log(res);
|
|
1239
|
+
return chalk_1.default.red(pkg.packageName + ' failed\n');
|
|
1501
1240
|
}
|
|
1241
|
+
console.log('Successfully published ' + chalk_1.default.green(pkg.path) + ' ' + chalk_1.default.magenta(publishVersion));
|
|
1242
|
+
return chalk_1.default.green(pkg.packageName) + ' published ' + chalk_1.default.magenta(publishVersion);
|
|
1243
|
+
})
|
|
1244
|
+
.catch(({ error, stdout, stderr }) => {
|
|
1245
|
+
console.log(chalk_1.default.red('Failed to publish: ' + error.message));
|
|
1246
|
+
return chalk_1.default.red(pkg.packageName + ' failed to publish');
|
|
1502
1247
|
});
|
|
1503
1248
|
});
|
|
1504
1249
|
};
|
|
1505
1250
|
exports.publishPackage = publishPackage;
|
|
1506
|
-
var buildUpdated = function (back, target, target2, test) {
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
}
|
|
1566
|
-
return [2 /*return*/];
|
|
1567
|
-
});
|
|
1568
|
-
}); };
|
|
1569
|
-
}, function (results) {
|
|
1570
|
-
if (results.length) {
|
|
1571
|
-
log('Summary:');
|
|
1572
|
-
log(results.join('\n'));
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1575
|
-
log(chalk_1["default"].green('Nothing to rebuild'));
|
|
1251
|
+
var buildUpdated = function (back, target, target2, test = false) {
|
|
1252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1253
|
+
// back = back || 1;
|
|
1254
|
+
// return execPromise(`git log -${back} --format=%ci`).then((result) => {
|
|
1255
|
+
// let now = new Date();
|
|
1256
|
+
let previousResult = '';
|
|
1257
|
+
log(test ? 'Checking which packages need to be rebuild' : 'Building updated packages');
|
|
1258
|
+
// let packages = getLocalLincdModules();
|
|
1259
|
+
let packages = getLocalLincdPackageMap();
|
|
1260
|
+
// console.log(packages);
|
|
1261
|
+
let jsonldPkgUpdated = needsRebuilding(packages.get('lincd-jsonld'));
|
|
1262
|
+
// let cliPkgUpdated = needsRebuilding(packages.get('lincd-cli'));
|
|
1263
|
+
//if either cli or jsonldPkg needs to be rebuilt
|
|
1264
|
+
// if (jsonldPkgUpdated || cliPkgUpdated) {
|
|
1265
|
+
if (jsonldPkgUpdated) {
|
|
1266
|
+
yield (0, utils_1.execPromise)('yarn build-core', false, false, {}, true);
|
|
1267
|
+
}
|
|
1268
|
+
let rebuildAllModules = false;
|
|
1269
|
+
// if (cliPkgUpdated) {
|
|
1270
|
+
// rebuildAllModules = true;
|
|
1271
|
+
// log(chalk.magenta('Rebuilding all packages because the build tools (lincd-cli) got updated'));
|
|
1272
|
+
// }
|
|
1273
|
+
let packagesLeft = packages.size;
|
|
1274
|
+
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
1275
|
+
debugInfo('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
1276
|
+
debugInfo((packagesLeft) + " packages left.");
|
|
1277
|
+
packagesLeft = packagesLeft - packageGroup.length;
|
|
1278
|
+
return (pkg) => __awaiter(this, void 0, void 0, function* () {
|
|
1279
|
+
// debugInfo('# Checking package ' + pkg.packageName);
|
|
1280
|
+
let needRebuild = needsRebuilding(pkg, true);
|
|
1281
|
+
if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
|
|
1282
|
+
needRebuild = true;
|
|
1283
|
+
}
|
|
1284
|
+
// console.log(pkg.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
|
|
1285
|
+
// console.log(pkg.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
|
|
1286
|
+
if (needRebuild || rebuildAllModules) {
|
|
1287
|
+
//TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
|
|
1288
|
+
// log(packageName+' modified since last commit on '+now.toString());
|
|
1289
|
+
if (test) {
|
|
1290
|
+
debugInfo('Need to build ' + pkg.packageName);
|
|
1291
|
+
return chalk_1.default.blue(pkg.packageName + ' should be build');
|
|
1292
|
+
}
|
|
1293
|
+
log('Building ' + pkg.packageName);
|
|
1294
|
+
return (0, utils_1.execPromise)('cd ' + pkg.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : ''))
|
|
1295
|
+
.then((res) => {
|
|
1296
|
+
debugInfo(chalk_1.default.green(pkg.packageName + ' successfully built'));
|
|
1297
|
+
return chalk_1.default.green(pkg.packageName + ' built');
|
|
1298
|
+
})
|
|
1299
|
+
.catch(({ error, stdout, stderr }) => {
|
|
1300
|
+
warn('Failed to build ' + pkg.packageName);
|
|
1301
|
+
console.log(stdout);
|
|
1302
|
+
let dependentModules = getDependentPackages(dependencies, pkg);
|
|
1303
|
+
if (dependentModules.length > 0) {
|
|
1304
|
+
// printBuildResults(failedModules, done);
|
|
1305
|
+
warn(chalk_1.default.red(pkg.packageName + ' build failed'));
|
|
1306
|
+
warn('Stopping build-updated process because ' +
|
|
1307
|
+
dependentModules.length +
|
|
1308
|
+
' other packages depend on this package.\n'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
1309
|
+
process.exit(1);
|
|
1576
1310
|
}
|
|
1577
1311
|
});
|
|
1578
|
-
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}, (results) => {
|
|
1315
|
+
if (results.length) {
|
|
1316
|
+
log('Summary:');
|
|
1317
|
+
log(results.join('\n'));
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
log(chalk_1.default.green('Nothing to rebuild'));
|
|
1579
1321
|
}
|
|
1580
1322
|
});
|
|
1323
|
+
return;
|
|
1324
|
+
var p = Promise.resolve('');
|
|
1325
|
+
packages.forEach((pkg) => {
|
|
1326
|
+
let packageName = pkg.packageName;
|
|
1327
|
+
p = p
|
|
1328
|
+
.then((previousResult) => {
|
|
1329
|
+
let lastModifiedSource = getLastModifiedSourceTime(pkg.path);
|
|
1330
|
+
let lastModifiedBundle = getLastBuildTime(pkg.path);
|
|
1331
|
+
// console.log(pkg.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
|
|
1332
|
+
// console.log(pkg.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
|
|
1333
|
+
debugInfo('# Checking package ' + packageName);
|
|
1334
|
+
if (lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime) {
|
|
1335
|
+
//TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
|
|
1336
|
+
// log(packageName+' modified since last commit on '+now.toString());
|
|
1337
|
+
debugInfo(chalk_1.default.cyan('Last modified source: ' +
|
|
1338
|
+
lastModifiedSource.lastModifiedName +
|
|
1339
|
+
' on ' +
|
|
1340
|
+
lastModifiedSource.lastModified.toString()));
|
|
1341
|
+
debugInfo(chalk_1.default.cyan('Last build: ' +
|
|
1342
|
+
(lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
|
|
1343
|
+
? lastModifiedBundle.lastModified.toString()
|
|
1344
|
+
: 'never')));
|
|
1345
|
+
if (test) {
|
|
1346
|
+
debugInfo('need to build ' + packageName);
|
|
1347
|
+
}
|
|
1348
|
+
else {
|
|
1349
|
+
log('building ' + packageName);
|
|
1350
|
+
}
|
|
1351
|
+
if (!test) {
|
|
1352
|
+
return (0, utils_1.execPromise)('cd ' + pkg.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : '')).then((res) => {
|
|
1353
|
+
if (res.indexOf('Aborted due to warnings') !== -1 || res.indexOf('Fatal error') !== -1) {
|
|
1354
|
+
console.log(res);
|
|
1355
|
+
return previousResult + ' ' + chalk_1.default.red(packageName + ' failed\n');
|
|
1356
|
+
}
|
|
1357
|
+
console.log(chalk_1.default.green(packageName + ' successfully built'));
|
|
1358
|
+
return previousResult + ' ' + chalk_1.default.green(packageName + ' built\n');
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
return previousResult + ' ' + chalk_1.default.blue(packageName + ' should be build\n');
|
|
1362
|
+
}
|
|
1363
|
+
return previousResult;
|
|
1364
|
+
})
|
|
1365
|
+
.catch(({ error, stdout, stderr }) => {
|
|
1366
|
+
console.log(stdout);
|
|
1367
|
+
return previousResult + ' ' + chalk_1.default.red(packageName + ' failed\n');
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
return p.then((messages) => {
|
|
1371
|
+
if (messages == '') {
|
|
1372
|
+
console.log(chalk_1.default.green('Nothing to rebuild.'));
|
|
1373
|
+
}
|
|
1374
|
+
else {
|
|
1375
|
+
console.log('Summary: \n' + messages);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
// });
|
|
1581
1379
|
});
|
|
1582
1380
|
};
|
|
1583
1381
|
exports.buildUpdated = buildUpdated;
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
var result = lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime;
|
|
1382
|
+
const needsRebuilding = function (pkg, log = false) {
|
|
1383
|
+
let lastModifiedSource = getLastModifiedSourceTime(pkg.path);
|
|
1384
|
+
let lastModifiedBundle = getLastBuildTime(pkg.path);
|
|
1385
|
+
let result = lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime;
|
|
1589
1386
|
if (log) {
|
|
1590
|
-
debugInfo(chalk_1
|
|
1387
|
+
debugInfo(chalk_1.default.cyan('Last modified source: ' +
|
|
1591
1388
|
lastModifiedSource.lastModifiedName +
|
|
1592
1389
|
' on ' +
|
|
1593
1390
|
lastModifiedSource.lastModified.toString()));
|
|
1594
|
-
debugInfo(chalk_1
|
|
1391
|
+
debugInfo(chalk_1.default.cyan('Last build: ' +
|
|
1595
1392
|
(lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
|
|
1596
1393
|
? lastModifiedBundle.lastModified.toString()
|
|
1597
1394
|
: 'never')));
|
|
1598
1395
|
}
|
|
1599
1396
|
return result;
|
|
1600
1397
|
};
|
|
1601
|
-
|
|
1602
|
-
log('Successfully built: ' + chalk_1
|
|
1398
|
+
const printBuildResults = function (failed, done) {
|
|
1399
|
+
log('Successfully built: ' + chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) + '\n');
|
|
1603
1400
|
if (failed.length > 0) {
|
|
1604
|
-
warn('Failed to build: ' + chalk_1
|
|
1401
|
+
warn('Failed to build: ' + chalk_1.default.red(failed.join(', ')) + '\n');
|
|
1605
1402
|
}
|
|
1606
1403
|
};
|
|
1607
1404
|
var executeCommandForEachPackage = function (packages, command, filterMethod, filterValue) {
|
|
@@ -1610,91 +1407,79 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
|
|
|
1610
1407
|
//filter packages, so that we only execute on the packages as provided in the command
|
|
1611
1408
|
log('Excluding ' + filterValue);
|
|
1612
1409
|
filterValue = filterValue.split(',');
|
|
1613
|
-
packages = packages.filter(
|
|
1410
|
+
packages = packages.filter((pkg) => filterValue.indexOf(pkg.packageName) === -1);
|
|
1614
1411
|
}
|
|
1615
|
-
|
|
1412
|
+
let startFrom;
|
|
1616
1413
|
//by default start executing, unless 'from' is given
|
|
1617
|
-
|
|
1414
|
+
let executing = true;
|
|
1618
1415
|
//option to start from a specific pkg in the stack
|
|
1619
1416
|
if (filterMethod == 'from') {
|
|
1620
1417
|
startFrom = filterValue;
|
|
1621
1418
|
if (startFrom) {
|
|
1622
|
-
console.log(chalk_1
|
|
1419
|
+
console.log(chalk_1.default.blue('Will skip ahead to ' + startFrom));
|
|
1623
1420
|
}
|
|
1624
|
-
|
|
1625
|
-
packages = packages.filter(
|
|
1626
|
-
if (!
|
|
1627
|
-
|
|
1421
|
+
let seen = false;
|
|
1422
|
+
packages = packages.filter((pkg) => {
|
|
1423
|
+
if (!seen && (pkg.packageName == startFrom || pkg.packageName == startFrom)) {
|
|
1424
|
+
seen = true;
|
|
1628
1425
|
}
|
|
1629
|
-
return
|
|
1426
|
+
return seen;
|
|
1630
1427
|
});
|
|
1631
1428
|
}
|
|
1632
1429
|
log("Executing '" +
|
|
1633
|
-
chalk_1
|
|
1430
|
+
chalk_1.default.blueBright(command) +
|
|
1634
1431
|
"' on packages " +
|
|
1635
|
-
chalk_1
|
|
1432
|
+
chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
|
|
1636
1433
|
var p = Promise.resolve(true);
|
|
1637
|
-
packages.forEach(
|
|
1638
|
-
p = p.then(
|
|
1639
|
-
log('# Package ' + chalk_1
|
|
1434
|
+
packages.forEach((pkg) => {
|
|
1435
|
+
p = p.then(() => {
|
|
1436
|
+
log('# Package ' + chalk_1.default.magenta(pkg.packageName));
|
|
1640
1437
|
return (0, utils_1.execp)('cd ' + pkg.path + ' && ' + command);
|
|
1641
1438
|
});
|
|
1642
1439
|
});
|
|
1643
1440
|
return p;
|
|
1644
1441
|
};
|
|
1645
1442
|
exports.executeCommandForEachPackage = executeCommandForEachPackage;
|
|
1646
|
-
var addCapacitor = function (basePath) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
case 1:
|
|
1676
|
-
_a.sent();
|
|
1677
|
-
return [4 /*yield*/, (0, utils_1.execPromise)("yarn add @capacitor/android @capacitor/core @capacitor/geolocation @capacitor/ios @capacitor/push-notifications", false, false, null, true)];
|
|
1678
|
-
case 2:
|
|
1679
|
-
_a.sent();
|
|
1680
|
-
log("Done! Run ".concat(chalk_1["default"].magenta('yarn build-static'), " to generate static bundles. Then run ").concat(chalk_1["default"].magenta('yarn cap add android'), " and/or ").concat(chalk_1["default"].magenta('yarn cap add ios'), "')"));
|
|
1681
|
-
log("Also see the app icons in /frontend/web");
|
|
1682
|
-
return [2 /*return*/];
|
|
1683
|
-
}
|
|
1684
|
-
});
|
|
1443
|
+
var addCapacitor = function (basePath = process.cwd()) {
|
|
1444
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1445
|
+
let targetFolder = ensureFolderExists(basePath);
|
|
1446
|
+
log('Adding capacitor');
|
|
1447
|
+
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
|
|
1448
|
+
//update .env-cmdrc.json file
|
|
1449
|
+
let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
|
|
1450
|
+
let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
|
|
1451
|
+
envCmd['static-dev'] = {
|
|
1452
|
+
"NODE_ENV": "production",
|
|
1453
|
+
"SITE_ROOT": "http://localhost:4000",
|
|
1454
|
+
"DATA_ROOT": "http://localhost:4000/data",
|
|
1455
|
+
"OUTPUT_PATH": "./frontend/web/assets",
|
|
1456
|
+
"ASSET_PATH": "./assets/",
|
|
1457
|
+
"ENTRY_PATH": "./frontend/src/index-static.tsx"
|
|
1458
|
+
};
|
|
1459
|
+
fs_extra_1.default.writeFile(envCmdPath, JSON.stringify(envCmd, null, 2));
|
|
1460
|
+
log('Edited .env-cmdrc.json');
|
|
1461
|
+
//update package.json scripts
|
|
1462
|
+
let pack = (0, utils_1.getPackageJSON)(basePath);
|
|
1463
|
+
pack.scripts['build-static'] = 'env-cmd -e static-dev node frontend/scripts/build.js';
|
|
1464
|
+
pack.scripts['cap:android'] = 'yarn cap open android';
|
|
1465
|
+
pack.scripts['cap:sync'] = 'yarn cap sync';
|
|
1466
|
+
fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
|
|
1467
|
+
log('Added new run script to package.json');
|
|
1468
|
+
yield (0, utils_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
|
|
1469
|
+
yield (0, utils_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/geolocation @capacitor/ios @capacitor/push-notifications`, false, false, null, true);
|
|
1470
|
+
log(`Done! Run ${chalk_1.default.magenta('yarn build-static')} to generate static bundles. Then run ${chalk_1.default.magenta('yarn cap add android')} and/or ${chalk_1.default.magenta('yarn cap add ios')}')`);
|
|
1471
|
+
log(`Also see the app icons in /frontend/web`);
|
|
1685
1472
|
});
|
|
1686
1473
|
};
|
|
1687
1474
|
exports.addCapacitor = addCapacitor;
|
|
1688
1475
|
var executeCommandForPackage = function (packageName, command) {
|
|
1689
|
-
|
|
1690
|
-
return modDetails.packageName.indexOf(packageName) !== -1 || modDetails.packageName.indexOf(packageName) !== -1;
|
|
1691
|
-
});
|
|
1476
|
+
let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 || modDetails.packageName.indexOf(packageName) !== -1);
|
|
1692
1477
|
if (packageDetails) {
|
|
1693
1478
|
log("Executing 'cd " + packageDetails.path + ' && yarn exec lincd' + (command ? ' ' + command : '') + "'");
|
|
1694
1479
|
return (0, utils_1.execp)('cd ' + packageDetails.path + ' && yarn exec lincd' + (command ? ' ' + command : ''));
|
|
1695
1480
|
}
|
|
1696
1481
|
else {
|
|
1697
|
-
warn("Could not find a pkg who's name (partially) matched " + chalk_1
|
|
1482
|
+
warn("Could not find a pkg who's name (partially) matched " + chalk_1.default.cyan(packageName));
|
|
1698
1483
|
}
|
|
1699
1484
|
};
|
|
1700
1485
|
exports.executeCommandForPackage = executeCommandForPackage;
|