lincd-cli 0.1.9 → 0.1.10
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/src/App.tsx +5 -0
- package/defaults/app/src/index.tsx +10 -0
- package/defaults/app/tsconfig.json +18 -0
- package/defaults/module/Gruntfile.js +16 -0
- package/defaults/module/src/components/ExampleComponent.tsx +20 -0
- package/defaults/module/src/data/example-ontology.json +20 -0
- package/defaults/module/src/data/example-ontology.json.d.ts +1 -0
- package/defaults/module/src/index.ts +7 -0
- package/defaults/module/src/module.ts +4 -0
- package/defaults/module/src/ontologies/example-ontology.ts +36 -0
- package/defaults/module/src/shapes/ExampleShapeClass.ts +29 -0
- package/defaults/module/tsconfig-es5.json +18 -0
- package/defaults/module/tsconfig.json +18 -0
- package/lib/cli.js +349 -461
- package/lib/utils.js +6 -3
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {createRoot} from 'react-dom/client';
|
|
3
|
+
import {App} from './App';
|
|
4
|
+
|
|
5
|
+
declare var document;
|
|
6
|
+
if (typeof document !== 'undefined') {
|
|
7
|
+
const container = document.getElementById('root');
|
|
8
|
+
const root = createRoot(container!);
|
|
9
|
+
root.render(<App></App>);
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"outDir": "lib",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"downlevelIteration": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"jsx": "react",
|
|
14
|
+
"baseUrl": "./",
|
|
15
|
+
"rootDir": "src"
|
|
16
|
+
},
|
|
17
|
+
"files": ["./src/index.tsx"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var buildTools = require('lincd-cli');
|
|
2
|
+
module.exports = buildTools.generateGruntConfig('${module_name}', {
|
|
3
|
+
externals: {
|
|
4
|
+
react: 'React',
|
|
5
|
+
'react-dom': 'ReactDOM',
|
|
6
|
+
}, //list of non lincd modules that are already loaded and made globally available by one of the dependencies of this module
|
|
7
|
+
//internals: [],//list of lincd modules that you want to INCLUDE in the bundle (as opposed to the module its own bundle being a dependency)
|
|
8
|
+
//alias:{},//webpack alias -> maps on type of npm path to another
|
|
9
|
+
//target:"es5"|"es6",
|
|
10
|
+
//environment:"server"|"frontend",
|
|
11
|
+
//outputPath:string,
|
|
12
|
+
//es5Server:boolean
|
|
13
|
+
//es5:{},//es5 specific config, use same properties as above
|
|
14
|
+
//es6:{},//es6 specific config, use same properties as above
|
|
15
|
+
//debug:false,//debug the build process
|
|
16
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {ExampleShapeClass} from "../shapes/ExampleShapeClass";
|
|
3
|
+
import {linkedComponentClass,linkedComponent} from '../module';
|
|
4
|
+
import {LinkedComponentClass} from 'lincd/lib/utils/LinkedComponentClass';
|
|
5
|
+
|
|
6
|
+
export const ExampleComponent = linkedComponent<ExampleShapeClass>(ExampleShapeClass, ({source, sourceShape}) => {
|
|
7
|
+
//note that typescript knows that person has the type of the Shape you provided
|
|
8
|
+
return <div></div>;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
//alternatively, use a Class component if you prefer:
|
|
12
|
+
/*@linkedComponentClass(ExampleShapeClass)
|
|
13
|
+
export class ExampleComponent extends LinkedComponentClass<ExampleShapeClass> {
|
|
14
|
+
render() {
|
|
15
|
+
let exampleInstance = this.sourceShape;
|
|
16
|
+
|
|
17
|
+
//get the name of this item from the graph
|
|
18
|
+
return <h1>Hello {exampleInstance.name}!</h1>;
|
|
19
|
+
}
|
|
20
|
+
}*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": {
|
|
3
|
+
"dc": "http://purl.org/dc/elements/1.1/",
|
|
4
|
+
"owl": "http://www.w3.org/2002/07/owl#",
|
|
5
|
+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
6
|
+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
7
|
+
"${hyphen_name}": "${uri_base}"
|
|
8
|
+
},
|
|
9
|
+
"@graph": [
|
|
10
|
+
{
|
|
11
|
+
"@id": "${hyphen_name}:ExampleClass",
|
|
12
|
+
"@type": "rdfs:Class",
|
|
13
|
+
"rdfs:comment": "This is an example class. You can remove or rename it",
|
|
14
|
+
"rdfs:isDefinedBy": {
|
|
15
|
+
"@id": "${hyphen_name}:"
|
|
16
|
+
},
|
|
17
|
+
"rdfs:label": "Example Class"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var json: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {NamedNode} from 'lincd/lib/models';
|
|
2
|
+
import {JSONLD} from 'lincd-jsonld/lib/JSONLD';
|
|
3
|
+
import {createNameSpace} from 'lincd/lib/utils/NameSpace';
|
|
4
|
+
import {linkedOntology} from '../module';
|
|
5
|
+
//import all the exports of this file as one variable called _this (we need this at the end)
|
|
6
|
+
import * as _this from './${hyphen_name}';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Load the data of this ontology into memory, thus adding the properties of the entities of this ontology to the local graph.
|
|
10
|
+
*/
|
|
11
|
+
export var loadData = () => {
|
|
12
|
+
return import('../data/${hyphen_name}.json').then((data) => JSONLD.parse(data));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The namespace of this ontology, which can be used to create NamedNodes with URI's not listed in this file
|
|
17
|
+
*/
|
|
18
|
+
export var ns = createNameSpace('${uri_base}');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The NamedNode of the ontology itself
|
|
22
|
+
*/
|
|
23
|
+
export var _self: NamedNode = ns('');
|
|
24
|
+
|
|
25
|
+
//A list of all the entities (Classes & Properties) of this ontology, each exported as a NamedNode
|
|
26
|
+
export var ExampleClass: NamedNode = ns('ExampleClass');
|
|
27
|
+
export var exampleProperty: NamedNode = ns('exampleProperty');
|
|
28
|
+
|
|
29
|
+
//An extra grouping object so all the entities can be accessed from the prefix/name
|
|
30
|
+
export const ${camel_name} = {
|
|
31
|
+
ExampleClass,
|
|
32
|
+
exampleProperty,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//Registers this ontology to LINCD.JS, so that data loading can be automated amongst other things
|
|
36
|
+
linkedOntology(_this, ns, '${hyphen_name}', loadData, '../data/${hyphen_name}.json');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {Shape} from 'lincd/lib/shapes/Shape';
|
|
2
|
+
import {Literal, NamedNode} from 'lincd/lib/models';
|
|
3
|
+
import {linkedShape} from '../module';
|
|
4
|
+
import {literalProperty} from 'lincd/lib/utils/ShapeDecorators';
|
|
5
|
+
import {${camel_name}} from '../ontologies/${hyphen_name}';
|
|
6
|
+
|
|
7
|
+
@linkedShape
|
|
8
|
+
export class ExampleShapeClass extends Shape {
|
|
9
|
+
/**
|
|
10
|
+
* indicates that instances of this shape need to have this rdf.type
|
|
11
|
+
*/
|
|
12
|
+
static targetClass: NamedNode = ${camel_name}.ExampleClass;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* instances of this shape need to have exactly one value defined for the given property
|
|
16
|
+
*/
|
|
17
|
+
@literalProperty({
|
|
18
|
+
path: ${camel_name}.exampleProperty,
|
|
19
|
+
required: true,
|
|
20
|
+
maxCount: 1,
|
|
21
|
+
})
|
|
22
|
+
get name() {
|
|
23
|
+
return this.getValue(${camel_name}.exampleProperty);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set name(val: string) {
|
|
27
|
+
this.overwrite(${camel_name}.exampleProperty, new Literal(val));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"outDir": "lib",
|
|
7
|
+
"declaration": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"downlevelIteration": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"jsx": "react",
|
|
14
|
+
"baseUrl": "./",
|
|
15
|
+
"rootDir": "src"
|
|
16
|
+
},
|
|
17
|
+
"files": ["./src/index.ts"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"outDir": "lib",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"downlevelIteration": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"jsx": "react",
|
|
14
|
+
"baseUrl": "./",
|
|
15
|
+
"rootDir": "src"
|
|
16
|
+
},
|
|
17
|
+
"files": ["./src/index.ts"]
|
|
18
|
+
}
|
package/lib/cli.js
CHANGED
|
@@ -56,6 +56,104 @@ var path = require('path');
|
|
|
56
56
|
var glob = require('glob');
|
|
57
57
|
var variables = {};
|
|
58
58
|
var open = require('open');
|
|
59
|
+
program
|
|
60
|
+
.command('create-app')
|
|
61
|
+
.action(function (name) {
|
|
62
|
+
return createApp(name);
|
|
63
|
+
})
|
|
64
|
+
.description('Creates a new folder with all the required files for a LINCD app')
|
|
65
|
+
.argument('<name>', 'the name of your LINCD app');
|
|
66
|
+
program
|
|
67
|
+
.command('create-module')
|
|
68
|
+
.action(function (name, uriBase) {
|
|
69
|
+
return createModule(name, uriBase);
|
|
70
|
+
})
|
|
71
|
+
.description('Create a new folder with all the required files for a new LINCD module')
|
|
72
|
+
.argument('<name>', 'The name of the module. Will be used as package name in package.json')
|
|
73
|
+
.argument('[uri_base]', 'The base URL used for data of this module. Leave blank to use the URL of your module on lincd.org after you register it');
|
|
74
|
+
program
|
|
75
|
+
.command('create-shape')
|
|
76
|
+
.action(function (name, uriBase) {
|
|
77
|
+
return createShape(name);
|
|
78
|
+
})
|
|
79
|
+
.description('Creates a new ShapeClass file for your module. Execute this from your module folder.')
|
|
80
|
+
.argument('<name>', 'The name of the shape. Will be used for the file name and the class name');
|
|
81
|
+
program
|
|
82
|
+
.command('create-ontology')
|
|
83
|
+
.action(function (prefix, uriBase) {
|
|
84
|
+
return createOntology(prefix, uriBase);
|
|
85
|
+
})
|
|
86
|
+
.description('Creates a new ontology file for your module. Execute this from your module folder.')
|
|
87
|
+
.argument('<suggested-prefix>', 'The suggested prefix for your ontology. Also the shorthand code used for the file name and the exported ontology object')
|
|
88
|
+
.argument('[uribase]', "Optional argument to set the URI base for the URI's of all entities in your ontology. Leave blank to use the URI's provided by lincd.org once you register this module");
|
|
89
|
+
program.command('register-local', { hidden: true }).action(function () {
|
|
90
|
+
register('http://localhost:4001');
|
|
91
|
+
});
|
|
92
|
+
program.command('register-dev', { hidden: true }).action(function () {
|
|
93
|
+
register('https://dev-registry.lincd.org');
|
|
94
|
+
});
|
|
95
|
+
program
|
|
96
|
+
.command('register')
|
|
97
|
+
.action(function () {
|
|
98
|
+
register('https://registry.lincd.org');
|
|
99
|
+
})
|
|
100
|
+
.description('Register (a new version of) this module to the LINCD registry. If successful your module will appear on www.lincd.org');
|
|
101
|
+
program
|
|
102
|
+
.command('info')
|
|
103
|
+
.action(function () {
|
|
104
|
+
var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
|
105
|
+
console.log(ownPackage.version);
|
|
106
|
+
console.log('Running from: ' + __dirname);
|
|
107
|
+
})
|
|
108
|
+
.description("Log the version of this tool and the path that it's running from");
|
|
109
|
+
program.command('build [target] [target2]', { isDefault: true }).action(function (target, target2) {
|
|
110
|
+
buildModule(target, target2);
|
|
111
|
+
});
|
|
112
|
+
program.command('publish-updated').action(function () {
|
|
113
|
+
return publishUpdated();
|
|
114
|
+
});
|
|
115
|
+
program.command('status').action(function () {
|
|
116
|
+
return publishUpdated(true).then(function () {
|
|
117
|
+
return buildUpdated(undefined, '', '', true);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
program.command('build-updated [target] [target2]').action(function (target, target2) {
|
|
121
|
+
return buildUpdated(1, target, target2);
|
|
122
|
+
});
|
|
123
|
+
program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
|
|
124
|
+
return buildUpdated(back, target, target2);
|
|
125
|
+
});
|
|
126
|
+
program.command('build-all [target] [target2]').action(function (target, target2) {
|
|
127
|
+
buildAll(target, target2);
|
|
128
|
+
});
|
|
129
|
+
program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
|
|
130
|
+
executeCommandForEachModule(getLincdModules(), command, includedSpaces);
|
|
131
|
+
});
|
|
132
|
+
program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
|
|
133
|
+
executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
|
|
134
|
+
});
|
|
135
|
+
program.command('dev [target] [mode]').action(function (target, mode) {
|
|
136
|
+
developModule(target, mode);
|
|
137
|
+
});
|
|
138
|
+
program
|
|
139
|
+
.command('module|m')
|
|
140
|
+
.action(function (name, command, args) {
|
|
141
|
+
var fullCommand = (command ? command + ' ' +
|
|
142
|
+
' ' +
|
|
143
|
+
args
|
|
144
|
+
.slice(0, 3)
|
|
145
|
+
.filter(function (a) { return a && true; })
|
|
146
|
+
.join(' ') : null);
|
|
147
|
+
executeCommandForModule(name, fullCommand);
|
|
148
|
+
})
|
|
149
|
+
.alias('m')
|
|
150
|
+
.description("Searches for a module in this workspace with a partially matching name and executes a command for that module (without needing to execute it from that modules' folder)")
|
|
151
|
+
.argument('<name>', 'the name of the module. Can be a part of the name.')
|
|
152
|
+
.argument('[command]', 'the lincd command you want to execute. Like dev or build')
|
|
153
|
+
.argument('[args...]', 'the additional arguments of that command');
|
|
154
|
+
function logHelp() {
|
|
155
|
+
execp('yarn lincd help');
|
|
156
|
+
}
|
|
59
157
|
function log() {
|
|
60
158
|
var messages = [];
|
|
61
159
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -75,6 +173,25 @@ function warn() {
|
|
|
75
173
|
// console.log(chalk.red(message));
|
|
76
174
|
});
|
|
77
175
|
}
|
|
176
|
+
function developModule(target, mode) {
|
|
177
|
+
if (!target)
|
|
178
|
+
target = 'es6';
|
|
179
|
+
if (mode !== 'production')
|
|
180
|
+
mode = '';
|
|
181
|
+
else if (target !== 'es6')
|
|
182
|
+
log('target must be es6 when developing for production');
|
|
183
|
+
if (target == 'es5' || target == 'es6') {
|
|
184
|
+
// log('> Starting continuous development build for '+target+' target')
|
|
185
|
+
log('starting continuous development build');
|
|
186
|
+
log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
|
|
187
|
+
var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
|
|
188
|
+
command.stdout.pipe(process.stdout);
|
|
189
|
+
command.stderr.pipe(process.stderr);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
console.warn('unknown build target. Use es5 or es6');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
78
195
|
function checkWorkspaces(rootPath, workspaces, res) {
|
|
79
196
|
// console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
|
|
80
197
|
workspaces.forEach(function (workspace) {
|
|
@@ -113,6 +230,194 @@ function checkModulePath(rootPath, modulePath, res) {
|
|
|
113
230
|
}
|
|
114
231
|
}
|
|
115
232
|
}
|
|
233
|
+
function buildAll(target, target2) {
|
|
234
|
+
var _this = this;
|
|
235
|
+
var dependencies = new Map();
|
|
236
|
+
console.log('Building all modules of this repository in order of dependencies');
|
|
237
|
+
var modules = getLocalLincdModuleMap();
|
|
238
|
+
//get dependencies of each module
|
|
239
|
+
var leastDependentModule;
|
|
240
|
+
modules.forEach(function (module) {
|
|
241
|
+
var pack = (0, utils_1.getPackageJSON)(module.path);
|
|
242
|
+
if (pack) {
|
|
243
|
+
//get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
|
|
244
|
+
var moduleDependencies = Object.keys(pack.dependencies)
|
|
245
|
+
.filter(function (dependency) { return modules.has(dependency); })
|
|
246
|
+
.map(function (dependency) {
|
|
247
|
+
return modules.has(dependency) ? modules.get(dependency) : dependency;
|
|
248
|
+
});
|
|
249
|
+
// console.log(module.moduleName,moduleDependencies.map())
|
|
250
|
+
dependencies.set(module, moduleDependencies);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
dependencies.forEach(function (moduleDependencies, module) {
|
|
254
|
+
if (!moduleDependencies.some(function (dependency) {
|
|
255
|
+
return typeof dependency !== 'string' && modules.has(dependency.moduleName);
|
|
256
|
+
})) {
|
|
257
|
+
leastDependentModule = module;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
var startFrom;
|
|
261
|
+
//by default start building
|
|
262
|
+
var building = true;
|
|
263
|
+
//option to start from a specific module in the stack
|
|
264
|
+
if (target == 'from') {
|
|
265
|
+
startFrom = target2;
|
|
266
|
+
//if we have a startFrom, then we havnt started the build process yet
|
|
267
|
+
building = startFrom ? false : true;
|
|
268
|
+
//clear targets
|
|
269
|
+
target = '';
|
|
270
|
+
target2 = '';
|
|
271
|
+
console.log(chalk.blue('Will skip builds until ' + startFrom));
|
|
272
|
+
}
|
|
273
|
+
var stack = [leastDependentModule];
|
|
274
|
+
var done = new Set();
|
|
275
|
+
var p = Promise.resolve();
|
|
276
|
+
var runStack = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
277
|
+
var modulesLeft, failedModules, stackPromise, first_1;
|
|
278
|
+
return __generator(this, function (_a) {
|
|
279
|
+
switch (_a.label) {
|
|
280
|
+
case 0:
|
|
281
|
+
modulesLeft = modules.size - done.size;
|
|
282
|
+
if (done.size > 0) {
|
|
283
|
+
console.log(chalk.magenta('\n-------\nThese modules are next, since all their dependencies have now been build:'));
|
|
284
|
+
console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
|
|
285
|
+
// log(stack);
|
|
286
|
+
}
|
|
287
|
+
failedModules = [];
|
|
288
|
+
stackPromise = Promise.all(stack.map(function (module) {
|
|
289
|
+
// p = p.then(() => {
|
|
290
|
+
var command;
|
|
291
|
+
//if we're skipping builds until a certain module
|
|
292
|
+
if (!building) {
|
|
293
|
+
//if the module name matches the module we're supposed to start from then start building modules
|
|
294
|
+
if (module.moduleName == startFrom || module.packageName == startFrom) {
|
|
295
|
+
building = true;
|
|
296
|
+
}
|
|
297
|
+
//else still waiting for the module
|
|
298
|
+
else {
|
|
299
|
+
log(chalk.blue('skipping ' + module.moduleName));
|
|
300
|
+
command = Promise.resolve(true);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//unless told otherwise, build the module
|
|
304
|
+
if (!command) {
|
|
305
|
+
command = execp('cd ' +
|
|
306
|
+
module.path +
|
|
307
|
+
' && yarn lincd build' +
|
|
308
|
+
(target ? ' ' + target : '') +
|
|
309
|
+
(target2 ? ' ' + target2 : ''));
|
|
310
|
+
log(chalk.cyan('Building ' + module.moduleName));
|
|
311
|
+
}
|
|
312
|
+
return command["catch"](function (err) {
|
|
313
|
+
var dependentModules = [];
|
|
314
|
+
dependencies.forEach(function (dModuleDependencies, dModule) {
|
|
315
|
+
if (dModuleDependencies.indexOf(module) !== -1) {
|
|
316
|
+
dependentModules.push(dModule);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
if (dependentModules.length > 0) {
|
|
320
|
+
failedModules.push(module.moduleName);
|
|
321
|
+
printFailedModules(failedModules);
|
|
322
|
+
console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
|
|
323
|
+
module.moduleName +
|
|
324
|
+
', which ' +
|
|
325
|
+
dependentModules.length +
|
|
326
|
+
' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
327
|
+
console.log(chalk.cyanBright('tip ') +
|
|
328
|
+
'Run ' +
|
|
329
|
+
chalk.green("lincd build-all from ".concat(module.moduleName)) +
|
|
330
|
+
' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
failedModules.push(module.moduleName);
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
.then(function (res) {
|
|
338
|
+
done.add(module);
|
|
339
|
+
modulesLeft--;
|
|
340
|
+
log(chalk.magenta(modulesLeft + ' modules left'));
|
|
341
|
+
if (modulesLeft == 0 && failedModules.length > 0) {
|
|
342
|
+
printFailedModules(failedModules);
|
|
343
|
+
}
|
|
344
|
+
return res;
|
|
345
|
+
});
|
|
346
|
+
// });
|
|
347
|
+
// done.add(module);
|
|
348
|
+
}));
|
|
349
|
+
//wait till stack is completed
|
|
350
|
+
return [4 /*yield*/, stackPromise];
|
|
351
|
+
case 1:
|
|
352
|
+
//wait till stack is completed
|
|
353
|
+
_a.sent();
|
|
354
|
+
// await p;
|
|
355
|
+
//clear stack for next round
|
|
356
|
+
stack = [];
|
|
357
|
+
//find those modules who have all their dependencies already built and add them to the stack
|
|
358
|
+
modules.forEach(function (module) {
|
|
359
|
+
var deps = dependencies.get(module);
|
|
360
|
+
//if the module is not done yet
|
|
361
|
+
//but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
|
|
362
|
+
if (!done.has(module) &&
|
|
363
|
+
deps.every(function (dependency) {
|
|
364
|
+
return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
|
|
365
|
+
})) {
|
|
366
|
+
stack.push(module);
|
|
367
|
+
}
|
|
368
|
+
// else if(!done.has(module))
|
|
369
|
+
// {
|
|
370
|
+
// console.log(chalk.red(module+' not yet'))
|
|
371
|
+
// console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
|
|
372
|
+
// }
|
|
373
|
+
});
|
|
374
|
+
//if more to be built, iterate
|
|
375
|
+
if (stack.length > 0) {
|
|
376
|
+
return [2 /*return*/, runStack()];
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
//if no more modules to build but we never started building...
|
|
380
|
+
if (!building) {
|
|
381
|
+
console.log(chalk.red('Could not find the module to start from. Please provide a correct package name or module name to build from'));
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
first_1 = true;
|
|
385
|
+
modules.forEach(function (module) {
|
|
386
|
+
if (!done.has(module)) {
|
|
387
|
+
var deps = dependencies.get(module);
|
|
388
|
+
if (first_1) {
|
|
389
|
+
console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some modules because they depend on each other.'));
|
|
390
|
+
first_1 = false;
|
|
391
|
+
}
|
|
392
|
+
//print the cyclical dependencies
|
|
393
|
+
console.log(chalk.red(module.moduleName) +
|
|
394
|
+
' depends on ' +
|
|
395
|
+
deps
|
|
396
|
+
.filter(function (dependency) {
|
|
397
|
+
return typeof dependency !== 'string';
|
|
398
|
+
})
|
|
399
|
+
.map(function (d) {
|
|
400
|
+
return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
|
|
401
|
+
})
|
|
402
|
+
.join(', '));
|
|
403
|
+
//also print some information why these modules have not been moved into the stack
|
|
404
|
+
var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
|
|
405
|
+
if (stringDependencies.length > 0) {
|
|
406
|
+
console.log(chalk.red('And it depends on these module(s) - which seem not to be proper modules :' +
|
|
407
|
+
stringDependencies.join(', ')));
|
|
408
|
+
console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return [2 /*return*/];
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}); };
|
|
418
|
+
//starts the process
|
|
419
|
+
runStack();
|
|
420
|
+
}
|
|
116
421
|
/**
|
|
117
422
|
* Returns a map of the modules that this repository manages (so no modules found through the workspaces who's path contains ../ )
|
|
118
423
|
* @param rootPath
|
|
@@ -135,20 +440,26 @@ function getLocalLincdModules(rootPath) {
|
|
|
135
440
|
});
|
|
136
441
|
}
|
|
137
442
|
function getLincdModules(rootPath) {
|
|
138
|
-
if (rootPath === void 0) { rootPath =
|
|
139
|
-
//TODO: read from package.json what the workspaces are. for each, follow up all the folders inside that path
|
|
140
|
-
//TODO: then return an array with objects that have both the module name + the path. And then use that path across this whenever this function is called
|
|
141
|
-
//TODO: this way it will work with websites as well, instead of just from the main LINCD repository
|
|
443
|
+
if (rootPath === void 0) { rootPath = process.cwd(); }
|
|
142
444
|
var pack = (0, utils_1.getPackageJSON)();
|
|
143
|
-
|
|
144
|
-
|
|
445
|
+
if (!pack || !pack.workspaces) {
|
|
446
|
+
for (var i = 0; i <= 3; i++) {
|
|
447
|
+
rootPath = path.join.apply(path, __spreadArray([process.cwd()], Array(i).fill('..'), false));
|
|
448
|
+
pack = (0, utils_1.getPackageJSON)(rootPath);
|
|
449
|
+
if (pack && pack.workspaces) {
|
|
450
|
+
// log('Found workspace at '+packagePath);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (!pack || !pack.workspaces) {
|
|
145
456
|
warn(chalk.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
|
|
146
457
|
logHelp();
|
|
147
458
|
process.exit();
|
|
148
459
|
}
|
|
149
|
-
//
|
|
460
|
+
// console.log(pack.workspaces);
|
|
461
|
+
var res = [];
|
|
150
462
|
checkWorkspaces(rootPath, pack.workspaces, res);
|
|
151
|
-
// console.log(res);
|
|
152
463
|
return res;
|
|
153
464
|
}
|
|
154
465
|
function setVariable(name, replacement) {
|
|
@@ -210,12 +521,6 @@ function execp(cmd, log, allowError, options) {
|
|
|
210
521
|
});
|
|
211
522
|
});
|
|
212
523
|
}
|
|
213
|
-
function replaceVariables(string) {
|
|
214
|
-
for (var key in variables) {
|
|
215
|
-
string = string.replace(new RegExp(key, 'g'), variables[key]);
|
|
216
|
-
}
|
|
217
|
-
return string;
|
|
218
|
-
}
|
|
219
524
|
function execPromise(command, log, allowError, options) {
|
|
220
525
|
if (log === void 0) { log = false; }
|
|
221
526
|
if (allowError === void 0) { allowError = false; }
|
|
@@ -271,25 +576,7 @@ var camelCase = function (str) {
|
|
|
271
576
|
.reduce(function (result, word) { return result + capitalize(word); });
|
|
272
577
|
//it also leave the first capital intact
|
|
273
578
|
return string;
|
|
274
|
-
// let string = str
|
|
275
|
-
// .toLowerCase()
|
|
276
|
-
// .replace(/[^A-Za-z0-9]/g, ' ')
|
|
277
|
-
// .split(' ')
|
|
278
|
-
// .reduce((result, word) => result + capitalize(word.toLowerCase()));
|
|
279
|
-
// return string.charAt(0).toLowerCase() + string.slice(1);
|
|
280
579
|
};
|
|
281
|
-
program.command('create-app [name] [uribase]').action(function (name, uriBase) {
|
|
282
|
-
return createApp(name, uriBase);
|
|
283
|
-
});
|
|
284
|
-
program.command('create-module [name] [uribase]').action(function (name, uriBase) {
|
|
285
|
-
return createModule(name, uriBase);
|
|
286
|
-
});
|
|
287
|
-
program.command('create-shape [name]').action(function (name, uriBase) {
|
|
288
|
-
return createShape(name);
|
|
289
|
-
});
|
|
290
|
-
program.command('create-ontology [suggested-prefix] [uribase]').action(function (prefix, uriBase) {
|
|
291
|
-
return createOntology(prefix, uriBase);
|
|
292
|
-
});
|
|
293
580
|
var createOntology = function (prefix, uriBase, basePath) {
|
|
294
581
|
if (basePath === void 0) { basePath = process.cwd(); }
|
|
295
582
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -367,17 +654,26 @@ var ensureFolderExists = function () {
|
|
|
367
654
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
368
655
|
folders[_i] = arguments[_i];
|
|
369
656
|
}
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (fs.existsSync(
|
|
374
|
-
fs.mkdirSync(
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
warn("Please run this command from the root of your module. This command expects ".concat(parentDirectory.toString(), " to exists from that folder"));
|
|
657
|
+
var target;
|
|
658
|
+
folders.forEach(function (folder) {
|
|
659
|
+
target = target ? path.join(target, folder) : path.join(folder);
|
|
660
|
+
if (!fs.existsSync(target)) {
|
|
661
|
+
fs.mkdirSync(target);
|
|
378
662
|
}
|
|
663
|
+
});
|
|
664
|
+
return target;
|
|
665
|
+
/*let targetFolder = path.join(...folders);
|
|
666
|
+
let parentDirectory = folders.slice(0, folders.length - 1);
|
|
667
|
+
if (!fs.existsSync(targetFolder)) {
|
|
668
|
+
if (fs.existsSync(path.join(...parentDirectory))) {
|
|
669
|
+
fs.mkdirSync(targetFolder);
|
|
670
|
+
} else {
|
|
671
|
+
warn(
|
|
672
|
+
`Please run this command from the root of your module. This command expects ${parentDirectory.toString()} to exists from that folder`,
|
|
673
|
+
);
|
|
674
|
+
}
|
|
379
675
|
}
|
|
380
|
-
return targetFolder
|
|
676
|
+
return targetFolder;*/
|
|
381
677
|
};
|
|
382
678
|
var setNameVariables = function (name) {
|
|
383
679
|
var hyphenName = name.replace(/[-_\s]+/g, '-');
|
|
@@ -497,7 +793,7 @@ var createModule = function (name, uriBase, basePath) {
|
|
|
497
793
|
});
|
|
498
794
|
});
|
|
499
795
|
};
|
|
500
|
-
var createApp = function (name,
|
|
796
|
+
var createApp = function (name, basePath) {
|
|
501
797
|
if (basePath === void 0) { basePath = process.cwd(); }
|
|
502
798
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
503
799
|
var _a, packageName, scope, cleanPackageName, targetFolder, codeName, cameCaseName, underscoreName, version, installCommand;
|
|
@@ -508,9 +804,6 @@ var createApp = function (name, uriBase, basePath) {
|
|
|
508
804
|
console.warn('Please provide a name as the first argument');
|
|
509
805
|
}
|
|
510
806
|
_a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
|
|
511
|
-
if (!uriBase) {
|
|
512
|
-
uriBase = 'http://lincd.org/ont/' + name;
|
|
513
|
-
}
|
|
514
807
|
targetFolder = path.join(basePath, name);
|
|
515
808
|
if (!fs.existsSync(targetFolder)) {
|
|
516
809
|
fs.mkdirSync(targetFolder);
|
|
@@ -519,7 +812,7 @@ var createApp = function (name, uriBase, basePath) {
|
|
|
519
812
|
codeName = cleanPackageName.replace(/\-/g, '_');
|
|
520
813
|
cameCaseName = camelCase(name);
|
|
521
814
|
underscoreName = name.replace(/[-\s]+/g, '_');
|
|
522
|
-
setVariable('uri_base', uriBase);
|
|
815
|
+
// setVariable('uri_base', uriBase);
|
|
523
816
|
//longer similar variables names should come before the shorter ones
|
|
524
817
|
setVariable('camelcase_name', cameCaseName);
|
|
525
818
|
setVariable('underscore_name', underscoreName);
|
|
@@ -602,16 +895,14 @@ var buildFailed = function (output) {
|
|
|
602
895
|
console.warn('Not a project');
|
|
603
896
|
}
|
|
604
897
|
});*/
|
|
605
|
-
|
|
898
|
+
var register = function (registryURL) {
|
|
606
899
|
if (fs.existsSync(process.cwd() + '/package.json')) {
|
|
607
900
|
var pack = JSON.parse(fs.readFileSync(process.cwd() + '/package.json', 'utf8'));
|
|
608
901
|
var version = pack.version;
|
|
609
902
|
var moduleName = pack.name;
|
|
610
903
|
var author = pack.author;
|
|
611
|
-
// let displayName = pack.displayName;
|
|
612
904
|
console.log(chalk.cyan('registering ' + author + "'s module, " + moduleName + ' ' + version + ' in the LINCD registry'));
|
|
613
|
-
|
|
614
|
-
return fetch('http://localhost:4001/register', {
|
|
905
|
+
return fetch(registryURL + '/register', {
|
|
615
906
|
method: 'POST',
|
|
616
907
|
headers: {
|
|
617
908
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -628,113 +919,13 @@ program.command('register [version]').action(function (newVersion) {
|
|
|
628
919
|
console.log(chalk.cyan('Response: ') + json.result);
|
|
629
920
|
}
|
|
630
921
|
})["catch"](function (err) {
|
|
631
|
-
console.warn('Could not connect to LINCD registry');
|
|
922
|
+
console.warn(chalk.red('Warning: ') + 'Could not connect to LINCD registry');
|
|
632
923
|
});
|
|
633
|
-
/*console.log(chalk.cyan('building production bundles'));
|
|
634
|
-
return execPromise('yarn lincd build production', false, true)
|
|
635
|
-
.then((output: string) => {
|
|
636
|
-
if (buildFailed(output)) {
|
|
637
|
-
// console.warn("Build failed:");
|
|
638
|
-
console.log(output);
|
|
639
|
-
throw new Error('build failed');
|
|
640
|
-
}
|
|
641
|
-
pack.version = newVersion;
|
|
642
|
-
//save package.json
|
|
643
|
-
return fs.writeFileSync(
|
|
644
|
-
path.join(process.cwd(), 'package.json'),
|
|
645
|
-
JSON.stringify(pack, null, 2),
|
|
646
|
-
);
|
|
647
|
-
})
|
|
648
|
-
.then((version) => {
|
|
649
|
-
console.log(chalk.cyan('Committing to git'));
|
|
650
|
-
//we have just changed package.json, so there will be things "uncommitted"
|
|
651
|
-
//to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
|
|
652
|
-
//so: add all files not added yet in the folder of this module
|
|
653
|
-
//then commit all changes (including new version number in package.json)
|
|
654
|
-
//then add a version commit git flag
|
|
655
|
-
return execPromise(
|
|
656
|
-
`git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
|
|
657
|
-
);
|
|
658
|
-
})
|
|
659
|
-
.then((version) => {
|
|
660
|
-
console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
|
|
661
|
-
|
|
662
|
-
// let tag = moduleName+'@'+version;
|
|
663
|
-
return execPromise('yarn publish --new-version ' + newVersion, true);
|
|
664
|
-
})
|
|
665
|
-
.then((res) => {
|
|
666
|
-
if (
|
|
667
|
-
res.indexOf('Aborted due to warnings') !== -1 ||
|
|
668
|
-
res.indexOf('Could not publish') !== -1 ||
|
|
669
|
-
res.indexOf("Couldn't publish") !== -1
|
|
670
|
-
) {
|
|
671
|
-
console.log(chalk.red('Failed to publish'));
|
|
672
|
-
return false;
|
|
673
|
-
} else {
|
|
674
|
-
var pack = JSON.parse(
|
|
675
|
-
fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
|
|
676
|
-
);
|
|
677
|
-
version = pack.version;
|
|
678
|
-
console.log(chalk.green('Published ' + version));
|
|
679
|
-
return true;
|
|
680
|
-
}
|
|
681
|
-
})
|
|
682
|
-
.catch((err) => {
|
|
683
|
-
console.warn(chalk.red('Could not publish: ' + err));
|
|
684
|
-
});*/
|
|
685
924
|
}
|
|
686
925
|
else {
|
|
687
|
-
console.warn('not found: ' + process.cwd() + '/package.json');
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
// program.command('create [action] [value]').action((action, prefixedUri) => {
|
|
691
|
-
//
|
|
692
|
-
// let [ontology,label] = typeof prefixedUri !== 'undefined' ? prefixedUri.split(":") : [];
|
|
693
|
-
// if(!ontology || !label)
|
|
694
|
-
// {
|
|
695
|
-
// return console.warn("Please provide a prefixed URI of the "+action+" to create");
|
|
696
|
-
// }
|
|
697
|
-
// if(action == 'viewtype')
|
|
698
|
-
// {
|
|
699
|
-
// //add to ontology file
|
|
700
|
-
// let contents = fs.readFileSync(path.join('src','ontologies',ontology),'utf8');
|
|
701
|
-
//
|
|
702
|
-
//
|
|
703
|
-
// //create view file
|
|
704
|
-
// //add view file to index
|
|
705
|
-
// }
|
|
706
|
-
// });
|
|
707
|
-
program.command('info').action(function () {
|
|
708
|
-
var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
|
709
|
-
console.log(ownPackage.version);
|
|
710
|
-
console.log('Running from: ' + __dirname);
|
|
711
|
-
});
|
|
712
|
-
var ensurePath = function () {
|
|
713
|
-
var folders = [];
|
|
714
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
715
|
-
folders[_i] = arguments[_i];
|
|
926
|
+
console.warn(chalk.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
|
|
716
927
|
}
|
|
717
|
-
// let target = path.join(folders.shift());
|
|
718
|
-
var target;
|
|
719
|
-
folders.forEach(function (folder) {
|
|
720
|
-
target = target ? path.join(target, folder) : path.join(folder);
|
|
721
|
-
if (!fs.existsSync(target)) {
|
|
722
|
-
fs.mkdirSync(target);
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
return target;
|
|
726
928
|
};
|
|
727
|
-
program.command('test-build').action(function (target, target2) {
|
|
728
|
-
execPromise('yarn lincd build', true)
|
|
729
|
-
.then(function (result) {
|
|
730
|
-
console.log('success');
|
|
731
|
-
})["catch"](function (err) {
|
|
732
|
-
console.log('failed');
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
program.command('build [target] [target2]').action(function (target, target2) {
|
|
736
|
-
buildModule(target, target2);
|
|
737
|
-
});
|
|
738
929
|
var buildModule = function (target, target2, modulePath, logResults) {
|
|
739
930
|
if (modulePath === void 0) { modulePath = process.cwd(); }
|
|
740
931
|
if (logResults === void 0) { logResults = true; }
|
|
@@ -776,9 +967,6 @@ var buildModule = function (target, target2, modulePath, logResults) {
|
|
|
776
967
|
console.warn('unknown build target. Use es5, es6 or production.');
|
|
777
968
|
}
|
|
778
969
|
};
|
|
779
|
-
// program.command('css').action((message) => {
|
|
780
|
-
// return execp('grunt babel:css-module-transforms');
|
|
781
|
-
// });
|
|
782
970
|
var getLastBuildTime = function (modulePath) {
|
|
783
971
|
return getLastModifiedFile(modulePath + '/@(builds|lib)/**/*.js');
|
|
784
972
|
};
|
|
@@ -808,12 +996,6 @@ var getLastModifiedFile = function (filePath, config) {
|
|
|
808
996
|
// console.log("skipping directory "+fileName);
|
|
809
997
|
return;
|
|
810
998
|
}
|
|
811
|
-
//not counting things that are generated during build process when determining last modified source-code time
|
|
812
|
-
// if(fileName.indexOf(".d.ts") !== -1 || fileName.indexOf(".css.json") !== -1)
|
|
813
|
-
// {
|
|
814
|
-
// // console.log("not counting "+fileName);
|
|
815
|
-
// return;
|
|
816
|
-
// }
|
|
817
999
|
var mtime = fs.statSync(path.join(fileName)).mtime;
|
|
818
1000
|
var modifiedTime = mtime.getTime();
|
|
819
1001
|
if (modifiedTime > lastModifiedTime) {
|
|
@@ -825,14 +1007,6 @@ var getLastModifiedFile = function (filePath, config) {
|
|
|
825
1007
|
});
|
|
826
1008
|
return { lastModified: lastModified, lastModifiedName: lastModifiedName, lastModifiedTime: lastModifiedTime };
|
|
827
1009
|
};
|
|
828
|
-
program.command('publish-updated').action(function () {
|
|
829
|
-
return publishUpdated();
|
|
830
|
-
});
|
|
831
|
-
program.command('status').action(function () {
|
|
832
|
-
return publishUpdated(true).then(function () {
|
|
833
|
-
return buildUpdated(undefined, '', '', true);
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
1010
|
var publishUpdated = function (test) {
|
|
837
1011
|
var _this = this;
|
|
838
1012
|
if (test === void 0) { test = false; }
|
|
@@ -936,12 +1110,6 @@ var executeSingleBuild = function (module, previousResult, test, info) {
|
|
|
936
1110
|
return previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n');
|
|
937
1111
|
}
|
|
938
1112
|
};
|
|
939
|
-
program.command('build-updated [target] [target2]').action(function (target, target2) {
|
|
940
|
-
return buildUpdated(1, target, target2);
|
|
941
|
-
});
|
|
942
|
-
program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
|
|
943
|
-
return buildUpdated(back, target, target2);
|
|
944
|
-
});
|
|
945
1113
|
var buildUpdated = function (back, target, target2, test) {
|
|
946
1114
|
if (test === void 0) { test = false; }
|
|
947
1115
|
// back = back || 1;
|
|
@@ -1005,214 +1173,6 @@ var buildUpdated = function (back, target, target2, test) {
|
|
|
1005
1173
|
var printFailedModules = function (modules) {
|
|
1006
1174
|
log('These modules failed to build:\n\t' + chalk.red(modules.join('\n\t')) + '\n');
|
|
1007
1175
|
};
|
|
1008
|
-
program.command('build-all [target] [target2]').action(function (target, target2) {
|
|
1009
|
-
var dependencies = new Map();
|
|
1010
|
-
console.log('Building all modules of this repository in order of dependencies');
|
|
1011
|
-
var modules = getLocalLincdModuleMap();
|
|
1012
|
-
//get dependencies of each module
|
|
1013
|
-
var leastDependentModule;
|
|
1014
|
-
modules.forEach(function (module) {
|
|
1015
|
-
var pack = (0, utils_1.getPackageJSON)(module.path);
|
|
1016
|
-
if (pack) {
|
|
1017
|
-
//get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
|
|
1018
|
-
var moduleDependencies = Object.keys(pack.dependencies)
|
|
1019
|
-
.filter(function (dependency) { return modules.has(dependency); })
|
|
1020
|
-
.map(function (dependency) {
|
|
1021
|
-
return modules.has(dependency) ? modules.get(dependency) : dependency;
|
|
1022
|
-
});
|
|
1023
|
-
// console.log(module.moduleName,moduleDependencies.map())
|
|
1024
|
-
dependencies.set(module, moduleDependencies);
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
1027
|
-
dependencies.forEach(function (moduleDependencies, module) {
|
|
1028
|
-
if (!moduleDependencies.some(function (dependency) {
|
|
1029
|
-
return typeof dependency !== 'string' && modules.has(dependency.moduleName);
|
|
1030
|
-
})) {
|
|
1031
|
-
leastDependentModule = module;
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1034
|
-
var startFrom;
|
|
1035
|
-
//by default start building
|
|
1036
|
-
var building = true;
|
|
1037
|
-
//option to start from a specific module in the stack
|
|
1038
|
-
if (target == 'from') {
|
|
1039
|
-
startFrom = target2;
|
|
1040
|
-
//if we have a startFrom, then we havnt started the build process yet
|
|
1041
|
-
building = startFrom ? false : true;
|
|
1042
|
-
//clear targets
|
|
1043
|
-
target = '';
|
|
1044
|
-
target2 = '';
|
|
1045
|
-
console.log(chalk.blue('Will skip builds until ' + startFrom));
|
|
1046
|
-
}
|
|
1047
|
-
var stack = [leastDependentModule];
|
|
1048
|
-
var done = new Set();
|
|
1049
|
-
var p = Promise.resolve();
|
|
1050
|
-
var runStack = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1051
|
-
var modulesLeft, failedModules, stackPromise, first_1;
|
|
1052
|
-
return __generator(this, function (_a) {
|
|
1053
|
-
switch (_a.label) {
|
|
1054
|
-
case 0:
|
|
1055
|
-
modulesLeft = modules.size - done.size;
|
|
1056
|
-
if (done.size > 0) {
|
|
1057
|
-
console.log(chalk.magenta('\n-------\nThese modules are next, since all their dependencies have now been build:'));
|
|
1058
|
-
console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
|
|
1059
|
-
// log(stack);
|
|
1060
|
-
}
|
|
1061
|
-
failedModules = [];
|
|
1062
|
-
stackPromise = Promise.all(stack.map(function (module) {
|
|
1063
|
-
// p = p.then(() => {
|
|
1064
|
-
var command;
|
|
1065
|
-
//if we're skipping builds until a certain module
|
|
1066
|
-
if (!building) {
|
|
1067
|
-
//if the module name matches the module we're supposed to start from then start building modules
|
|
1068
|
-
if (module.moduleName == startFrom || module.packageName == startFrom) {
|
|
1069
|
-
building = true;
|
|
1070
|
-
}
|
|
1071
|
-
//else still waiting for the module
|
|
1072
|
-
else {
|
|
1073
|
-
log(chalk.blue('skipping ' + module.moduleName));
|
|
1074
|
-
command = Promise.resolve(true);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
//unless told otherwise, build the module
|
|
1078
|
-
if (!command) {
|
|
1079
|
-
command = execp('cd ' +
|
|
1080
|
-
module.path +
|
|
1081
|
-
' && yarn lincd build' +
|
|
1082
|
-
(target ? ' ' + target : '') +
|
|
1083
|
-
(target2 ? ' ' + target2 : ''));
|
|
1084
|
-
log(chalk.cyan('Building ' + module.moduleName));
|
|
1085
|
-
}
|
|
1086
|
-
return command["catch"](function (err) {
|
|
1087
|
-
var dependentModules = [];
|
|
1088
|
-
dependencies.forEach(function (dModuleDependencies, dModule) {
|
|
1089
|
-
if (dModuleDependencies.indexOf(module) !== -1) {
|
|
1090
|
-
dependentModules.push(dModule);
|
|
1091
|
-
}
|
|
1092
|
-
});
|
|
1093
|
-
if (dependentModules.length > 0) {
|
|
1094
|
-
failedModules.push(module.moduleName);
|
|
1095
|
-
printFailedModules(failedModules);
|
|
1096
|
-
console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
|
|
1097
|
-
module.moduleName +
|
|
1098
|
-
', which ' +
|
|
1099
|
-
dependentModules.length +
|
|
1100
|
-
' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
1101
|
-
console.log(chalk.cyanBright('tip ') +
|
|
1102
|
-
'Run ' +
|
|
1103
|
-
chalk.green("lincd build-all from ".concat(module.moduleName)) +
|
|
1104
|
-
' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
1105
|
-
process.exit(1);
|
|
1106
|
-
}
|
|
1107
|
-
else {
|
|
1108
|
-
failedModules.push(module.moduleName);
|
|
1109
|
-
}
|
|
1110
|
-
})
|
|
1111
|
-
.then(function (res) {
|
|
1112
|
-
done.add(module);
|
|
1113
|
-
modulesLeft--;
|
|
1114
|
-
log(chalk.magenta(modulesLeft + ' modules left'));
|
|
1115
|
-
if (modulesLeft == 0 && failedModules.length > 0) {
|
|
1116
|
-
printFailedModules(failedModules);
|
|
1117
|
-
}
|
|
1118
|
-
return res;
|
|
1119
|
-
});
|
|
1120
|
-
// });
|
|
1121
|
-
// done.add(module);
|
|
1122
|
-
}));
|
|
1123
|
-
//wait till stack is completed
|
|
1124
|
-
return [4 /*yield*/, stackPromise];
|
|
1125
|
-
case 1:
|
|
1126
|
-
//wait till stack is completed
|
|
1127
|
-
_a.sent();
|
|
1128
|
-
// await p;
|
|
1129
|
-
//clear stack for next round
|
|
1130
|
-
stack = [];
|
|
1131
|
-
//find those modules who have all their dependencies already built and add them to the stack
|
|
1132
|
-
modules.forEach(function (module) {
|
|
1133
|
-
var deps = dependencies.get(module);
|
|
1134
|
-
//if the module is not done yet
|
|
1135
|
-
//but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
|
|
1136
|
-
if (!done.has(module) &&
|
|
1137
|
-
deps.every(function (dependency) {
|
|
1138
|
-
return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
|
|
1139
|
-
})) {
|
|
1140
|
-
stack.push(module);
|
|
1141
|
-
}
|
|
1142
|
-
// else if(!done.has(module))
|
|
1143
|
-
// {
|
|
1144
|
-
// console.log(chalk.red(module+' not yet'))
|
|
1145
|
-
// console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
|
|
1146
|
-
// }
|
|
1147
|
-
});
|
|
1148
|
-
//if more to be built, iterate
|
|
1149
|
-
if (stack.length > 0) {
|
|
1150
|
-
return [2 /*return*/, runStack()];
|
|
1151
|
-
}
|
|
1152
|
-
else {
|
|
1153
|
-
//if no more modules to build but we never started building...
|
|
1154
|
-
if (!building) {
|
|
1155
|
-
console.log(chalk.red('Could not find the module to start from. Please provide a correct package name or module name to build from'));
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
first_1 = true;
|
|
1159
|
-
modules.forEach(function (module) {
|
|
1160
|
-
if (!done.has(module)) {
|
|
1161
|
-
var deps = dependencies.get(module);
|
|
1162
|
-
if (first_1) {
|
|
1163
|
-
console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some modules because they depend on each other.'));
|
|
1164
|
-
first_1 = false;
|
|
1165
|
-
}
|
|
1166
|
-
//print the cyclical dependencies
|
|
1167
|
-
console.log(chalk.red(module.moduleName) +
|
|
1168
|
-
' depends on ' +
|
|
1169
|
-
deps
|
|
1170
|
-
.filter(function (dependency) {
|
|
1171
|
-
return typeof dependency !== 'string';
|
|
1172
|
-
})
|
|
1173
|
-
.map(function (d) {
|
|
1174
|
-
return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
|
|
1175
|
-
})
|
|
1176
|
-
.join(', '));
|
|
1177
|
-
//also print some information why these modules have not been moved into the stack
|
|
1178
|
-
var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
|
|
1179
|
-
if (stringDependencies.length > 0) {
|
|
1180
|
-
console.log(chalk.red('And it depends on these module(s) - which seem not to be proper modules :' +
|
|
1181
|
-
stringDependencies.join(', ')));
|
|
1182
|
-
console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
return [2 /*return*/];
|
|
1189
|
-
}
|
|
1190
|
-
});
|
|
1191
|
-
}); };
|
|
1192
|
-
//starts the process
|
|
1193
|
-
runStack();
|
|
1194
|
-
});
|
|
1195
|
-
program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
|
|
1196
|
-
executeCommandForEachModule(getLincdModules(), command, includedSpaces);
|
|
1197
|
-
});
|
|
1198
|
-
program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
|
|
1199
|
-
executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
|
|
1200
|
-
});
|
|
1201
|
-
program
|
|
1202
|
-
.command('module|mod [module] [a1] [a2] [a3] [a4]')
|
|
1203
|
-
.action(function (module) {
|
|
1204
|
-
var args = [];
|
|
1205
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1206
|
-
args[_i - 1] = arguments[_i];
|
|
1207
|
-
}
|
|
1208
|
-
var command = args
|
|
1209
|
-
.slice(0, 3)
|
|
1210
|
-
.filter(function (a) { return a && true; })
|
|
1211
|
-
.join(' ');
|
|
1212
|
-
executeCommandForModule(module, command);
|
|
1213
|
-
})
|
|
1214
|
-
.alias('mod')
|
|
1215
|
-
.alias('m');
|
|
1216
1176
|
var executeCommandForEachModule = function (modules, command, includedSpaces, excludedSpaces) {
|
|
1217
1177
|
//if a specific set of modules is given
|
|
1218
1178
|
if (includedSpaces) {
|
|
@@ -1238,88 +1198,16 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
|
|
|
1238
1198
|
});
|
|
1239
1199
|
return p;
|
|
1240
1200
|
};
|
|
1241
|
-
var executeCommandForModule = function (
|
|
1201
|
+
var executeCommandForModule = function (moduleName, command) {
|
|
1242
1202
|
var moduleDetails = getLincdModules().find(function (modDetails) {
|
|
1243
|
-
return modDetails.packageName.indexOf(
|
|
1203
|
+
return modDetails.packageName.indexOf(moduleName) !== -1 || modDetails.moduleName.indexOf(moduleName) !== -1;
|
|
1244
1204
|
});
|
|
1245
1205
|
if (moduleDetails) {
|
|
1246
|
-
log("Executing 'cd " + moduleDetails.path + ' && lincd ' + command + "'");
|
|
1247
|
-
return execp('cd ' + moduleDetails.path + ' && lincd ' + command);
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
program.command('dev [target] [mode]').action(function (target, mode) {
|
|
1251
|
-
if (!target)
|
|
1252
|
-
target = 'es6';
|
|
1253
|
-
if (mode !== 'production')
|
|
1254
|
-
mode = '';
|
|
1255
|
-
else if (target !== 'es6')
|
|
1256
|
-
log('target must be es6 when developing for production');
|
|
1257
|
-
if (target == 'es5' || target == 'es6') {
|
|
1258
|
-
// log('> Starting continuous development build for '+target+' target')
|
|
1259
|
-
log('starting continuous development build');
|
|
1260
|
-
log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
|
|
1261
|
-
var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
|
|
1262
|
-
command.stdout.pipe(process.stdout);
|
|
1263
|
-
command.stderr.pipe(process.stderr);
|
|
1206
|
+
log("Executing 'cd " + moduleDetails.path + ' && yarn lincd' + (command ? ' ' + command : '') + "'");
|
|
1207
|
+
return execp('cd ' + moduleDetails.path + ' && yarn lincd' + (command ? ' ' + command : ''));
|
|
1264
1208
|
}
|
|
1265
1209
|
else {
|
|
1266
|
-
|
|
1210
|
+
warn("Could not find a module who\'s name (partially) matched " + chalk.cyan(moduleName));
|
|
1267
1211
|
}
|
|
1268
|
-
}
|
|
1269
|
-
program.command('help').action(function (command) {
|
|
1270
|
-
logHelp();
|
|
1271
|
-
});
|
|
1272
|
-
program.command('*').action(function (command) {
|
|
1273
|
-
console.warn(chalk.red('unknown command: ' + command.args.join(' ')));
|
|
1274
|
-
logHelp();
|
|
1275
|
-
});
|
|
1276
|
-
function logHelp() {
|
|
1277
|
-
var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
|
|
1278
|
-
console.log('lincd-cli ' + ownPackage.version);
|
|
1279
|
-
console.log(chalk.green('\nAvailable commands from a module:'));
|
|
1280
|
-
console.log(chalk.blue('- build [es5|es6|production] [es5|es6] ') +
|
|
1281
|
-
chalk.cyan('- creates bundles & compiles source files each target environment'));
|
|
1282
|
-
console.log(chalk.blue('- dev [es5|es6] [production] ') +
|
|
1283
|
-
chalk.cyan('- continuously build bundles & compile source on file changes'));
|
|
1284
|
-
// console.log(
|
|
1285
|
-
// chalk.blue('- init [name] [uribase] ') +
|
|
1286
|
-
// chalk.cyan(
|
|
1287
|
-
// '- sets up a new module, sets up initial files and installs dependencies',
|
|
1288
|
-
// ),
|
|
1289
|
-
// );
|
|
1290
|
-
console.log(chalk.blue('- publish [version|minor|major|patch] ') +
|
|
1291
|
-
chalk.cyan('- publish new version to the npm registry AND to the LINCD.org registry'));
|
|
1292
|
-
//TODO: these all need to be tested to see if they work with the new LINCD setup
|
|
1293
|
-
console.log(chalk.green('\nAvailable commands from a yarn workspace:'));
|
|
1294
|
-
console.log(chalk.blue('- modules|mod|m module-name ...command') +
|
|
1295
|
-
chalk.cyan('- execute a lincd command for a specific module in this workspace. Use can use partial packageNames. So `lincd m xsd build` will trigger `lincd build` for the module lincd-xsd'));
|
|
1296
|
-
console.log(chalk.blue('- build-all [from] [module-name]') +
|
|
1297
|
-
chalk.cyan('- build all modules in order of dependencies. To continue later from a specific module, add `from {modulename}`'));
|
|
1298
|
-
console.log(chalk.blue('- build-updated') +
|
|
1299
|
-
chalk.cyan('- build only those modules that have updated their source since their last local built'));
|
|
1300
|
-
/*
|
|
1301
|
-
console.log(
|
|
1302
|
-
chalk.blue('- build-updated [n] ') +
|
|
1303
|
-
chalk.cyan(
|
|
1304
|
-
'- build only those modules that have updated their source since the last local commit (or optionally n commits back',
|
|
1305
|
-
),
|
|
1306
|
-
);
|
|
1307
|
-
console.log(
|
|
1308
|
-
chalk.blue('- modules [action]') +
|
|
1309
|
-
chalk.cyan('- execute a command for all modules'),
|
|
1310
|
-
);
|
|
1311
|
-
console.log(
|
|
1312
|
-
chalk.blue('- publish-updated [message] ') +
|
|
1313
|
-
chalk.cyan(
|
|
1314
|
-
"- publish all modules who's source changes have been committed to git since the last published version.",
|
|
1315
|
-
),
|
|
1316
|
-
);
|
|
1317
|
-
console.log(
|
|
1318
|
-
chalk.blue('- status') +
|
|
1319
|
-
chalk.cyan('- see which modules need to be published or build'),
|
|
1320
|
-
);*/
|
|
1321
|
-
console.log(chalk.green('\nOther commands:'));
|
|
1322
|
-
console.log(chalk.blue('- info ') + chalk.cyan('- print the version of this tool and where it runs from'));
|
|
1323
|
-
console.log(chalk.blue('- help ') + chalk.cyan('- print this message'));
|
|
1324
|
-
}
|
|
1212
|
+
};
|
|
1325
1213
|
program.parse(process.argv);
|
package/lib/utils.js
CHANGED
|
@@ -33,15 +33,18 @@ var SHACL_1 = require("lincd/lib/shapes/SHACL");
|
|
|
33
33
|
var CoreSet_1 = require("lincd/lib/collections/CoreSet");
|
|
34
34
|
var JSONLDWriter_1 = require("lincd-jsonld/lib/JSONLDWriter");
|
|
35
35
|
var chalk_1 = __importDefault(require("chalk"));
|
|
36
|
-
var getPackageJSON = function (root) {
|
|
36
|
+
var getPackageJSON = function (root, error) {
|
|
37
37
|
if (root === void 0) { root = process.cwd(); }
|
|
38
|
+
if (error === void 0) { error = true; }
|
|
38
39
|
var packagePath = path.join(root, 'package.json');
|
|
39
40
|
if (fs.existsSync(packagePath)) {
|
|
40
41
|
return JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
41
42
|
}
|
|
42
43
|
else if (root === process.cwd()) {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if (error) {
|
|
45
|
+
console.warn('Could not find package.json. Make sure you run this command from the root of a lincd module or a lincd yarn workspace');
|
|
46
|
+
process.exit();
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
50
|
exports.getPackageJSON = getPackageJSON;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lincd-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Command line tools for the lincd.js library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"chalk": "4.1.0",
|
|
32
32
|
"child-process-promise": "^2.2.1",
|
|
33
33
|
"colors": "^1.4.0",
|
|
34
|
-
"commander": "^
|
|
34
|
+
"commander": "^9.4.0",
|
|
35
35
|
"css-loader": "^5.2.7",
|
|
36
36
|
"extract-text-webpack-plugin": "^4.0.0-beta.0",
|
|
37
37
|
"fs-extra": "^10.1.0",
|