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