lincd-cli 0.2.46 → 0.2.48

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