lincd-cli 0.1.13 → 0.1.15
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.scss +3 -0
- 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/{app3/.env-cmdrc → app-with-backend/.env-cmdrc.json} +1 -1
- package/defaults/app-with-backend/babel.config.js +10 -0
- package/defaults/app-with-backend/backend/server.js +5 -0
- package/defaults/{app3 → app-with-backend}/frontend/scripts/build.js +15 -15
- package/defaults/app-with-backend/frontend/src/App.scss +45 -0
- package/defaults/app-with-backend/frontend/src/App.scss.json +1 -0
- package/defaults/app-with-backend/frontend/src/App.tsx +123 -0
- package/defaults/app-with-backend/frontend/src/components/Spinner.scss +16 -0
- package/defaults/app-with-backend/frontend/src/components/Spinner.scss.json +1 -0
- package/defaults/app-with-backend/frontend/src/components/Spinner.tsx +10 -0
- package/defaults/app-with-backend/frontend/src/index.tsx +16 -0
- package/defaults/app-with-backend/frontend/src/pages/Home.tsx +14 -0
- package/defaults/app-with-backend/frontend/src/pages/Page1.tsx +7 -0
- package/defaults/{app2 → app-with-backend}/frontend/web/favicon.ico +0 -0
- package/defaults/{app3 → app-with-backend}/package.json +12 -11
- package/defaults/app-with-backend/tsconfig.json +17 -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 +3 -3
- package/lib/config-grunt.js +1 -4
- package/lib/config-webpack.js +74 -40
- package/lib/plugins/declaration-plugin.js +75 -69
- package/lib/plugins/externalise-modules.js +30 -14
- package/package.json +24 -18
- package/defaults/app2/frontend/scripts/build.js +0 -100
- package/defaults/app2/package.json +0 -71
- package/defaults/app2/tailwind.config.js +0 -3
- package/defaults/app3/backend/server.js +0 -5
- package/defaults/app3/frontend/scripts/webpack-config.js +0 -121
- package/defaults/app3/frontend/web/favicon.ico +0 -0
- package/defaults/app3/tailwind.config.js +0 -3
- package/plugins/declaration-plugin.js +0 -248
- package/plugins/externalise-modules.js +0 -161
- package/plugins/watch-run.js +0 -47
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const webpack = require('webpack');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
7
|
-
|
|
8
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
9
|
-
|
|
10
|
-
// Can be overwritten by environment variables
|
|
11
|
-
// Should relate to express.static in server.ts, which makes the build files available through a URL
|
|
12
|
-
const ASSET_PATH = process.env.ASSET_PATH || '/js/';
|
|
13
|
-
|
|
14
|
-
webpack(
|
|
15
|
-
{
|
|
16
|
-
mode: isProduction ? 'production' : 'development',
|
|
17
|
-
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
|
|
18
|
-
entry: [path.resolve(__dirname, '../src/index.tsx')],
|
|
19
|
-
watch: isProduction ? false : true,
|
|
20
|
-
output: {
|
|
21
|
-
path: path.resolve(__dirname, '../build'),
|
|
22
|
-
filename: 'main.js',
|
|
23
|
-
publicPath: ASSET_PATH,
|
|
24
|
-
},
|
|
25
|
-
plugins: [
|
|
26
|
-
new webpack.WatchIgnorePlugin([/\.d\.ts$/]),
|
|
27
|
-
new MiniCssExtractPlugin(),
|
|
28
|
-
new webpack.EnvironmentPlugin(Object.keys(process.env)),
|
|
29
|
-
],
|
|
30
|
-
module: {
|
|
31
|
-
rules: [
|
|
32
|
-
{
|
|
33
|
-
test: /\.(scss|css)$/,
|
|
34
|
-
use: [
|
|
35
|
-
MiniCssExtractPlugin.loader,
|
|
36
|
-
{
|
|
37
|
-
loader: 'css-loader',
|
|
38
|
-
options: {
|
|
39
|
-
url: false,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
loader: 'postcss-loader',
|
|
44
|
-
options: {
|
|
45
|
-
postcssOptions: {
|
|
46
|
-
plugins: {
|
|
47
|
-
'postcss-import': {},
|
|
48
|
-
'postcss-nested': {},
|
|
49
|
-
tailwindcss: {
|
|
50
|
-
content: ['./frontend/src/**/*.{tsx,ts}'],
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
loader: 'sass-loader',
|
|
58
|
-
options: {sourceMap: true},
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
test: /\.tsx?$/,
|
|
64
|
-
use:
|
|
65
|
-
'ts-loader?' +
|
|
66
|
-
JSON.stringify({
|
|
67
|
-
compilerOptions: {
|
|
68
|
-
module: 'esnext',
|
|
69
|
-
moduleResolution: 'node',
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
exclude: /node_modules/,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
resolve: {
|
|
77
|
-
extensions: ['.tsx', '.ts', '.js'],
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
(err, stats) => {
|
|
81
|
-
if (err) {
|
|
82
|
-
console.error(err.stack || err);
|
|
83
|
-
if (err.details) {
|
|
84
|
-
console.error(err.details);
|
|
85
|
-
}
|
|
86
|
-
process.exit(1);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const info = stats.toJson();
|
|
90
|
-
if (stats.hasErrors()) {
|
|
91
|
-
console.log('Finished running webpack with errors.');
|
|
92
|
-
info.errors.forEach((e) => console.error(e));
|
|
93
|
-
} else {
|
|
94
|
-
console.log(chalk.green('Finished running webpack.'));
|
|
95
|
-
// console.log(
|
|
96
|
-
// chalk.green('\t'+Object.keys(stats.compilation.assets).join('\n\t')),
|
|
97
|
-
// );
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "${hyphen_name}",
|
|
3
|
-
"displayName": "${name}",
|
|
4
|
-
"description": "",
|
|
5
|
-
"version": "0.1.0",
|
|
6
|
-
"private": true,
|
|
7
|
-
"author": "",
|
|
8
|
-
"engines": {
|
|
9
|
-
"node": ">=14.9.0"
|
|
10
|
-
},
|
|
11
|
-
"main": "backend/src/server.js",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"start": "concurrently --names \"WEBP,_TSC,SERV\" \"yarn run bundler:dev\" \"npm run tsc\" \"npm run server:dev\"",
|
|
15
|
-
"build:prod": "yarn bundler:prod && yarn tsc:prod",
|
|
16
|
-
"server:dev": "cross-env NODE_ENV=development nodemon --ignore frontend/build -e js,json --delay 1 ./backend/src/server.js",
|
|
17
|
-
"server:prod": "cross-env NODE_ENV=production nodemon -e js,json --delay 1 ./backend/src/server.js",
|
|
18
|
-
"tsc": "cross-env NODE_ENV=development tsc --watch --project ./tsconfig.json",
|
|
19
|
-
"tsc:prod": "cross-env NODE_ENV=production tsc --project ./tsconfig.json",
|
|
20
|
-
"bundler:dev": "cross-env NODE_ENV=development nodemon --watch frontend/scripts frontend/scripts/build.js",
|
|
21
|
-
"bundler:prod": "cross-env NODE_ENV=production node frontend/scripts/build.js"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"lincd",
|
|
25
|
-
"linked data",
|
|
26
|
-
"interoperable",
|
|
27
|
-
"semantic web",
|
|
28
|
-
"web3"
|
|
29
|
-
],
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"lincd": "^0.3",
|
|
32
|
-
"lincd-jsonld": "^0.1",
|
|
33
|
-
"node-fetch": "^2.6.7",
|
|
34
|
-
"prism-react-renderer": "^1.3.5",
|
|
35
|
-
"react": "^18.2",
|
|
36
|
-
"react-dom": "^18.2",
|
|
37
|
-
"react-error-boundary": "^3.1.3",
|
|
38
|
-
"react-router-dom": "^6.3.0",
|
|
39
|
-
"react-select": "^5.4.0"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@types/node": "^17.0.30",
|
|
43
|
-
"@types/react": "^18.0.17",
|
|
44
|
-
"@types/react-dom": "^18.0.6",
|
|
45
|
-
"chalk": "4.1.2",
|
|
46
|
-
"classnames": "^2.3.1",
|
|
47
|
-
"compression": "^1.7.4",
|
|
48
|
-
"concurrently": "^5.3.0",
|
|
49
|
-
"cors": "^2.8.5",
|
|
50
|
-
"express": "^4.17.1",
|
|
51
|
-
"lincd-cli": "^0.1",
|
|
52
|
-
"ignore-styles": "^5.0.1",
|
|
53
|
-
"mini-css-extract-plugin": "^1.3.3",
|
|
54
|
-
"nodemon": "^2.0.6",
|
|
55
|
-
"css-loader": "^5.2.7",
|
|
56
|
-
"postcss": "^8.4.14",
|
|
57
|
-
"postcss-import": "^14.1.0",
|
|
58
|
-
"postcss-modules": "",
|
|
59
|
-
"postcss-nested": "^5.0.6",
|
|
60
|
-
"resolve": "1.12.0",
|
|
61
|
-
"rimraf": "^3.0.2",
|
|
62
|
-
"sass-loader": "^10.0",
|
|
63
|
-
"tailwindcss": "^3.0.24",
|
|
64
|
-
"ts-loader": "^8.0.12",
|
|
65
|
-
"typescript": "4.6.4",
|
|
66
|
-
"webpack": "4.44.2",
|
|
67
|
-
"webpack-cli": "^4.2.0",
|
|
68
|
-
"cross-env": "^7.0.3",
|
|
69
|
-
"prettier": "1.19.1"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
3
|
-
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
4
|
-
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
|
5
|
-
const ReactRefreshTypeScript = require('react-refresh-typescript');
|
|
6
|
-
const webpack = require('webpack');
|
|
7
|
-
|
|
8
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
9
|
-
|
|
10
|
-
// Can be overwritten by environment variables
|
|
11
|
-
// Should relate to express.static in server.ts, which makes the build files available through a URL
|
|
12
|
-
const ASSET_PATH = process.env.ASSET_PATH || '/js/';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// console.log(chalk.blueBright("Starting webpack"));
|
|
16
|
-
class WatchRunPlugin {
|
|
17
|
-
apply(compiler) {
|
|
18
|
-
compiler.hooks.watchRun.tap('WatchRun', (comp) => {
|
|
19
|
-
// const changedTimes = comp.watchFileSystem.watcher?.mtimes;
|
|
20
|
-
[comp.watchFileSystem.watcher,comp.watchFileSystem.wfs?.watcher].forEach(watcher => {
|
|
21
|
-
if(!watcher) return;
|
|
22
|
-
const changedTimes = watcher.mtimes;
|
|
23
|
-
const changedFiles = Object.keys(changedTimes)
|
|
24
|
-
.map(file => `\n ${file}`)
|
|
25
|
-
.join('');
|
|
26
|
-
if (changedFiles.length) {
|
|
27
|
-
console.log('Changed files:', changedFiles);
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = function getWebpackConfig()
|
|
35
|
-
{
|
|
36
|
-
return {
|
|
37
|
-
mode: isProduction ? 'production' : 'development',
|
|
38
|
-
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
|
|
39
|
-
entry: ['webpack-hot-middleware/client', path.resolve(__dirname, '../src/index.tsx')],
|
|
40
|
-
watch: isProduction ? false : true,
|
|
41
|
-
output: {
|
|
42
|
-
path: path.resolve(__dirname, '../build'),
|
|
43
|
-
filename: 'main.js',
|
|
44
|
-
publicPath: ASSET_PATH,
|
|
45
|
-
},
|
|
46
|
-
watchOptions: {
|
|
47
|
-
ignored: [/\.d\.ts$/, /\.scss\.json$/, /\.js\.map$/],
|
|
48
|
-
aggregateTimeout: 500
|
|
49
|
-
},
|
|
50
|
-
plugins: [
|
|
51
|
-
// new WatchRunPlugin(),
|
|
52
|
-
//for some reason we currently need both watchOptions.ignore + this WatchIgnorePlugin. They both ignore different files... Both only part of what we want to ignore
|
|
53
|
-
new webpack.WatchIgnorePlugin([/\.d\.ts$/, /\.scss\.json/]),
|
|
54
|
-
new MiniCssExtractPlugin(),
|
|
55
|
-
new webpack.EnvironmentPlugin(Object.keys(process.env)),
|
|
56
|
-
new ForkTsCheckerWebpackPlugin(),
|
|
57
|
-
!isProduction && new ReactRefreshWebpackPlugin(),
|
|
58
|
-
!isProduction && new webpack.HotModuleReplacementPlugin(),
|
|
59
|
-
].filter(Boolean),
|
|
60
|
-
module: {
|
|
61
|
-
rules: [
|
|
62
|
-
{
|
|
63
|
-
test: /\.(scss|css)$/,
|
|
64
|
-
use: [
|
|
65
|
-
MiniCssExtractPlugin.loader,
|
|
66
|
-
{
|
|
67
|
-
loader: 'css-loader',
|
|
68
|
-
options: {
|
|
69
|
-
url: false,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
loader: 'postcss-loader',
|
|
74
|
-
options: {
|
|
75
|
-
postcssOptions: {
|
|
76
|
-
plugins: {
|
|
77
|
-
'postcss-import': {},
|
|
78
|
-
'postcss-modules': {
|
|
79
|
-
globalModulePaths: [/tailwind/],
|
|
80
|
-
},
|
|
81
|
-
'postcss-nested': {},
|
|
82
|
-
tailwindcss: {
|
|
83
|
-
content: ['./frontend/src/**/*.{tsx,ts}'],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
loader: 'sass-loader',
|
|
91
|
-
options: {sourceMap: true},
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
test: /\.tsx?$/,
|
|
97
|
-
use: [{
|
|
98
|
-
loader: 'ts-loader?' +
|
|
99
|
-
JSON.stringify({
|
|
100
|
-
compilerOptions: {
|
|
101
|
-
module: 'esnext',
|
|
102
|
-
moduleResolution: 'node',
|
|
103
|
-
}
|
|
104
|
-
}),
|
|
105
|
-
options: {
|
|
106
|
-
getCustomTransformers: () => ({
|
|
107
|
-
before: [!isProduction && ReactRefreshTypeScript()]
|
|
108
|
-
}),
|
|
109
|
-
transpileOnly: !isProduction,
|
|
110
|
-
}
|
|
111
|
-
}],
|
|
112
|
-
exclude: /node_modules/,
|
|
113
|
-
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
resolve: {
|
|
118
|
-
extensions: ['.tsx', '.ts', '.js'],
|
|
119
|
-
},
|
|
120
|
-
}
|
|
121
|
-
}
|
|
Binary file
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
/// <reference path="colors.d.ts" />
|
|
4
|
-
var colors = require("colors");
|
|
5
|
-
var path = require("path");
|
|
6
|
-
var DeclarationPlugin = /** @class */ (function () {
|
|
7
|
-
function DeclarationPlugin(options) {
|
|
8
|
-
if (options === void 0) { options = {}; }
|
|
9
|
-
this.logMessages = true;
|
|
10
|
-
this.exportRoot = '/lib';
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.options['out'] = options.out
|
|
13
|
-
? options.out
|
|
14
|
-
: './builds/declarations.d.ts';
|
|
15
|
-
this.options['config'] = options.config
|
|
16
|
-
? options.config
|
|
17
|
-
: process.cwd() + '/daconfig.js';
|
|
18
|
-
//var moduleConfig = this.getModuleConfig();
|
|
19
|
-
this.options['root'] = options.root || this.exportRoot; //'/lib'
|
|
20
|
-
this.logMessages = options.debug ? options.debug : false;
|
|
21
|
-
this.modulePackageInfo = require(process.cwd() + '/package.json');
|
|
22
|
-
// this.debug('found package name: '+this.modulePackageInfo.name);
|
|
23
|
-
}
|
|
24
|
-
DeclarationPlugin.prototype.apply = function (compiler) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
this.debug('applying');
|
|
27
|
-
//when the compiler is ready to emit files
|
|
28
|
-
// compiler.plugin('emit', (compilation,callback) =>
|
|
29
|
-
compiler.hooks.emit.tapAsync('DeclarationPlugin', function (compilation, callback) {
|
|
30
|
-
// this.debug('emitted');
|
|
31
|
-
// this.debug(Object.keys(compilation.assets));
|
|
32
|
-
//collect all generated declaration files
|
|
33
|
-
//and remove them from the assets that will be emitted
|
|
34
|
-
//NOTE: at some point we decided to overwrite declaration files between emits because sometimes only one new declaration file is emitted
|
|
35
|
-
//this may cause issues when you remove a file during the continuous building process, but better than the other way around for now
|
|
36
|
-
if (!_this.declarationFiles) {
|
|
37
|
-
_this.declarationFiles = {};
|
|
38
|
-
}
|
|
39
|
-
for (var filename in compilation.assets) {
|
|
40
|
-
if (filename.indexOf('.d.ts') !== -1) {
|
|
41
|
-
if (_this.declarationFiles[filename]) {
|
|
42
|
-
_this.debug('overwriting ' + filename);
|
|
43
|
-
}
|
|
44
|
-
_this.declarationFiles[filename] = compilation.assets[filename];
|
|
45
|
-
// this.debug('not using: '+filename);
|
|
46
|
-
delete compilation.assets[filename];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (Object.keys(_this.declarationFiles).length == 0) {
|
|
50
|
-
_this.log('Cannot build .d.ts file because no declarations where found.'.red);
|
|
51
|
-
_this.log('Make sure to add '.yellow +
|
|
52
|
-
'"declaration":true'.blue.bold['underline'] +
|
|
53
|
-
' to tsconfig.json'.yellow);
|
|
54
|
-
_this.log('Make sure to run '.yellow +
|
|
55
|
-
'tsc'.blue +
|
|
56
|
-
' before running webpack'.yellow);
|
|
57
|
-
_this.log('Make sure to test for '.yellow +
|
|
58
|
-
'/(?!.*.d.ts).ts(x?)$/'.blue.bold['underline'] +
|
|
59
|
-
' in the ts-loader in webpack.config.json'.yellow);
|
|
60
|
-
_this.log(('Assets: ' + Object.keys(compilation.assets).toString()).yellow);
|
|
61
|
-
callback();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
//var moduleConfig = this.getModuleConfig();
|
|
65
|
-
//this.debug(moduleConfig);
|
|
66
|
-
//if (moduleConfig)
|
|
67
|
-
//{
|
|
68
|
-
//combine them into one declaration file
|
|
69
|
-
var combinedDeclaration = _this.generateCombinedDeclaration(_this.declarationFiles); //moduleConfig
|
|
70
|
-
//and insert that back into the assets
|
|
71
|
-
compilation.assets[_this.options.out] = {
|
|
72
|
-
source: function () {
|
|
73
|
-
return combinedDeclaration;
|
|
74
|
-
},
|
|
75
|
-
size: function () {
|
|
76
|
-
return combinedDeclaration.length;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
//get meta data from module exports
|
|
80
|
-
/*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
|
|
81
|
-
//and insert that back into the assets as [module_name].meta.json
|
|
82
|
-
compilation.assets[this.options.out.replace(".d.ts",".meta.rdf.json")] = {
|
|
83
|
-
source: function() {
|
|
84
|
-
return metaRdfJson;
|
|
85
|
-
},
|
|
86
|
-
size: function() {
|
|
87
|
-
return metaRdfJson.length;
|
|
88
|
-
}
|
|
89
|
-
};*/
|
|
90
|
-
//}
|
|
91
|
-
//webpack may continue now
|
|
92
|
-
callback();
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
DeclarationPlugin.prototype.debug = function () {
|
|
96
|
-
var msgs = [];
|
|
97
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
98
|
-
msgs[_i] = arguments[_i];
|
|
99
|
-
}
|
|
100
|
-
msgs.unshift('declarations:');
|
|
101
|
-
if (this.logMessages) {
|
|
102
|
-
console.log.apply(null, msgs);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
DeclarationPlugin.prototype.log = function () {
|
|
106
|
-
var msgs = [];
|
|
107
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
-
msgs[_i] = arguments[_i];
|
|
109
|
-
}
|
|
110
|
-
msgs.unshift('declarations:');
|
|
111
|
-
console.log.apply(null, msgs);
|
|
112
|
-
};
|
|
113
|
-
DeclarationPlugin.prototype.generateCombinedDeclaration = function (declarationFiles) {
|
|
114
|
-
this.debug('generating combined declaration');
|
|
115
|
-
var declarations = '';
|
|
116
|
-
//this.debug("daCore: using config ",moduleConfig);
|
|
117
|
-
//this.debug("Combining these files:"+Object.keys(declarationFiles).toString());
|
|
118
|
-
//get current directory that webpack is run from (base of project), and replace backward slashes by forward ones to compare
|
|
119
|
-
var basePath = process.cwd().replace(/\\/g, '/') + '/';
|
|
120
|
-
this.debug('Base path:', colors.blue(basePath));
|
|
121
|
-
var npmModuleName = this.modulePackageInfo.name;
|
|
122
|
-
var moduleName = npmModuleName.replace(/\@\w+\//, '');
|
|
123
|
-
var importMap = {};
|
|
124
|
-
for (var declarationFileName in declarationFiles) {
|
|
125
|
-
//this.debug("Parsing "+declarationFileName);
|
|
126
|
-
var declarationFile = declarationFiles[declarationFileName];
|
|
127
|
-
//var data = declarationFile._value;
|
|
128
|
-
var data = declarationFile.source();
|
|
129
|
-
if (!data.split) {
|
|
130
|
-
console.warn(typeof data, declarationFileName +
|
|
131
|
-
' - cannot split declaration contents. Not a string?');
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
var lines = data.split('\n');
|
|
135
|
-
var i = lines.length;
|
|
136
|
-
while (i--) {
|
|
137
|
-
var line = lines[i];
|
|
138
|
-
//exclude empty lines
|
|
139
|
-
var excludeLine = line == '';
|
|
140
|
-
//if importing something, or re-exporting something
|
|
141
|
-
if (/import ([a-z0-9A-Z_\-\*\{\}\s,]+)/.test(line) ||
|
|
142
|
-
/export ([a-z0-9A-Z_-\{\}\s,\*]+) from/.test(line)) {
|
|
143
|
-
var fileImports = line.indexOf('"') !== -1
|
|
144
|
-
? line.match(/\"([^\"]+)\"/)
|
|
145
|
-
: line.match(/\'([^\']+)\'/);
|
|
146
|
-
if (fileImports && fileImports.length > 1) {
|
|
147
|
-
var importPath = fileImports[1];
|
|
148
|
-
//if it is importing a relative path and it is a new one
|
|
149
|
-
if ((importPath.substr(0, 2) == './' ||
|
|
150
|
-
importPath.substr(0, 3) == '../') &&
|
|
151
|
-
!importMap[importPath]) {
|
|
152
|
-
//we will replace it with the local npm module later, calc and save the absolute path for now
|
|
153
|
-
//we parse from builds, because now TS-LOADER gives paths relative to its output folder
|
|
154
|
-
var parsed = path.parse('./builds/' + declarationFileName);
|
|
155
|
-
var fileDirectory = parsed.dir;
|
|
156
|
-
var absoluteImportPath = path.resolve(fileDirectory, importPath);
|
|
157
|
-
// this.debug('declarationfilename '+declarationFileName);
|
|
158
|
-
// this.debug('filedir '+fileDirectory);
|
|
159
|
-
this.debug('import ' + colors.blue(importPath), ' -> ' + colors.green(absoluteImportPath));
|
|
160
|
-
importMap[importPath] = absoluteImportPath;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
//exclude re-exports
|
|
165
|
-
//excludeLine = excludeLine || (/export ([a-z0-9A-Z_-\{\}\s,\*]+) from/).test(line);
|
|
166
|
-
//exclude unnamed local imports like: import "./some.scss" or import "./someFile"t
|
|
167
|
-
excludeLine =
|
|
168
|
-
excludeLine || /import ["'][a-z0-9A-Z_\-.\/\\]+["']/.test(line);
|
|
169
|
-
//if defined, check for excluded references
|
|
170
|
-
if (!excludeLine &&
|
|
171
|
-
this.excludedReferences &&
|
|
172
|
-
line.indexOf('<reference') !== -1) {
|
|
173
|
-
excludeLine = this.excludedReferences.some(function (reference) { return line.indexOf(reference) !== -1; });
|
|
174
|
-
}
|
|
175
|
-
if (excludeLine) {
|
|
176
|
-
this.debug('Excluding line ' + i + ': ' + line);
|
|
177
|
-
lines.splice(i, 1);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
if (line.indexOf('declare ') !== -1) {
|
|
181
|
-
lines[i] = line.replace('declare ', '');
|
|
182
|
-
}
|
|
183
|
-
//add tab
|
|
184
|
-
lines[i] = lines[i];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
//declare module '@dacore/dacore-es6/lib/sub/File' {
|
|
188
|
-
//@dacore/core/F:/wamp-new/www/dacore/modules/core/lib/ontologies/xsd
|
|
189
|
-
//F:/wamp-new/www/dacore/modules/core/lib/ontologies/xsd.d.ts
|
|
190
|
-
// var declarationFileNameWithoutBase = declarationFileName.substr(0,basePath.length) == basePath ? declarationFileName.substr(basePath.length) : declarationFileName;
|
|
191
|
-
//TS Loader now uses paths relative to output dir. so here we remove a single ../ from the path (which is in there because /builds is the output dir and /lib is the relative path of the file)
|
|
192
|
-
var fixedDeclarationPath = declarationFileName
|
|
193
|
-
.replace(/\\/g, '/')
|
|
194
|
-
.replace('../', '')
|
|
195
|
-
.replace('.d.ts', '');
|
|
196
|
-
var moduleDeclaration = npmModuleName + '/' + fixedDeclarationPath;
|
|
197
|
-
//var moduleDeclaration = npmModuleName+'/'+declarationFileName.replace(/\\/g,"/").replace(".d.ts","");
|
|
198
|
-
//this.debug('basePath:'+basePath);
|
|
199
|
-
declarations +=
|
|
200
|
-
"declare module '" +
|
|
201
|
-
moduleDeclaration +
|
|
202
|
-
"' {\n\t" +
|
|
203
|
-
lines.join('\n\t') +
|
|
204
|
-
'\n}\n\n';
|
|
205
|
-
// this.debug('fixed:'+declarationFileName+' -> '+fixedDeclarationPath);
|
|
206
|
-
this.debug('Defining module ' +
|
|
207
|
-
colors.yellow(moduleDeclaration) +
|
|
208
|
-
' from ' +
|
|
209
|
-
colors.blue(declarationFileName));
|
|
210
|
-
}
|
|
211
|
-
for (var relativeImportPath in importMap) {
|
|
212
|
-
var absoluteImportPath_1 = importMap[relativeImportPath];
|
|
213
|
-
var npmImportModule = npmModuleName +
|
|
214
|
-
'/' +
|
|
215
|
-
absoluteImportPath_1
|
|
216
|
-
.substr(basePath.length)
|
|
217
|
-
.replace('.d.ts', '')
|
|
218
|
-
.replace(/\\/g, '/');
|
|
219
|
-
//this.debug("From: "+absoluteImportPath+" to npm: "+npmImportModule);
|
|
220
|
-
this.debug('Replacing ' +
|
|
221
|
-
colors.blue(relativeImportPath) +
|
|
222
|
-
' with ' +
|
|
223
|
-
colors.yellow(npmImportModule));
|
|
224
|
-
//wrap in quotes to omit problems with replacing partials and having to fix order of replacements
|
|
225
|
-
declarations = declarations.replace(new RegExp('(\'|")' + relativeImportPath + '(\'|")', 'g'), '"' + npmImportModule + '"');
|
|
226
|
-
}
|
|
227
|
-
var indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
|
|
228
|
-
this.debug('Replacing index ' +
|
|
229
|
-
colors.yellow(indexModulePath) +
|
|
230
|
-
' with ' +
|
|
231
|
-
colors.yellow(this.modulePackageInfo.name));
|
|
232
|
-
declarations = declarations.replace("'" + indexModulePath + "'", "'" + this.modulePackageInfo.name + "'");
|
|
233
|
-
//replace alias
|
|
234
|
-
if (this.options.alias) {
|
|
235
|
-
for (var aliasKey in this.options.alias) {
|
|
236
|
-
//declarations = declarations.replace(aliasKey,this.options.alias[aliasKey]);
|
|
237
|
-
this.debug('Replacing alias ' +
|
|
238
|
-
aliasKey +
|
|
239
|
-
' with ' +
|
|
240
|
-
this.options.alias[aliasKey]);
|
|
241
|
-
declarations = declarations.replace(new RegExp(aliasKey, 'g'), this.options.alias[aliasKey]);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return declarations;
|
|
245
|
-
};
|
|
246
|
-
return DeclarationPlugin;
|
|
247
|
-
}());
|
|
248
|
-
exports["default"] = DeclarationPlugin;
|