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