lincd-cli 0.2.32 → 0.2.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /// <reference path="colors.d.ts" />
4
- var colors = require("colors");
5
- var path = require("path");
6
- var webpack = require('webpack');
7
- var Compilation = webpack.Compilation;
8
- var DeclarationPlugin = /** @class */ (function () {
9
- function DeclarationPlugin(options) {
10
- if (options === void 0) { options = {}; }
4
+ const colors = require("colors");
5
+ const path = require("path");
6
+ const webpack = require('webpack');
7
+ const { Compilation } = webpack;
8
+ class DeclarationPlugin {
9
+ constructor(options = {}) {
11
10
  this.logMessages = true;
12
11
  this.exportRoot = '/lib';
13
12
  this.options = options;
@@ -26,43 +25,42 @@ var DeclarationPlugin = /** @class */ (function () {
26
25
  // (compilation, callback) => {
27
26
  //
28
27
  // }
29
- DeclarationPlugin.prototype.apply = function (compiler) {
30
- var _this = this;
28
+ apply(compiler) {
31
29
  this.debug('applying ');
32
30
  //when the compiler is ready to emit files
33
31
  // compiler.plugin('emit', (compilation,callback) =>
34
- compiler.hooks.compilation.tap('DeclarationPlugin', function (compilation) {
32
+ compiler.hooks.compilation.tap('DeclarationPlugin', (compilation) => {
35
33
  //NOTE: even though the stage comes from the processAssets hook and not the afterProcessAssets hook
36
34
  // somehow this only works WITH the stage defined
37
35
  compilation.hooks.afterProcessAssets.tap({
38
36
  stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
39
37
  name: 'DeclarationPlugin'
40
- }, function () {
38
+ }, () => {
41
39
  // this.debug('indexing and removing declaration assets');
42
40
  //collect all generated declaration files
43
41
  //and remove them from the assets that will be emitted
44
42
  //NOTE: at some point we decided to overwrite declaration files between emits because sometimes only one new declaration file is emitted
45
43
  //this may cause issues when you remove a file during the continuous building process, but better than the other way around for now
46
- if (!_this.declarationFiles) {
47
- _this.declarationFiles = {};
44
+ if (!this.declarationFiles) {
45
+ this.declarationFiles = {};
48
46
  }
49
- compilation.getAssets().forEach(function (asset, key) {
47
+ compilation.getAssets().forEach((asset, key) => {
50
48
  // this.debug('key '+key.toString())
51
49
  // this.debug('value '+Object.getOwnPropertyNames(asset).join(", "))
52
50
  // this.debug('asset: ' + asset.name);
53
51
  if (asset.name.indexOf('.d.ts') !== -1) {
54
- if (_this.declarationFiles[asset.name]) {
55
- _this.debug('overwriting ' + asset.name);
52
+ if (this.declarationFiles[asset.name]) {
53
+ this.debug('overwriting ' + asset.name);
56
54
  }
57
- _this.declarationFiles[asset.name] = asset;
58
- _this.debug('indexed and removed asset: ' + colors.green(asset.name));
55
+ this.declarationFiles[asset.name] = asset;
56
+ this.debug('indexed and removed asset: ' + colors.green(asset.name));
59
57
  compilation.deleteAsset(asset.name);
60
58
  }
61
59
  });
62
- if (Object.keys(_this.declarationFiles).length == 0) {
63
- _this.debug('Didn\'t build .d.ts file because no declaration assets were emitted during build process.'.yellow);
64
- _this.debug('This is likely because webpack is using cache.'.yellow);
65
- _this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'.yellow);
60
+ if (Object.keys(this.declarationFiles).length == 0) {
61
+ this.debug('Didn\'t build .d.ts file because no declaration assets were emitted during build process.'.yellow);
62
+ this.debug('This is likely because webpack is using cache.'.yellow);
63
+ this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'.yellow);
66
64
  // this.log('Make sure to run '.yellow + 'tsc'.blue + ' before running webpack'.yellow);
67
65
  // this.log(
68
66
  // 'Make sure to test for '.yellow +
@@ -74,7 +72,7 @@ var DeclarationPlugin = /** @class */ (function () {
74
72
  return;
75
73
  }
76
74
  //combine them into one declaration file
77
- var combinedDeclaration = _this.generateCombinedDeclaration(_this.declarationFiles); //moduleConfig
75
+ var combinedDeclaration = this.generateCombinedDeclaration(this.declarationFiles); //moduleConfig
78
76
  //and insert that back into the assets
79
77
  // compilation.assets[this.options.out] = {
80
78
  // source: function() {
@@ -85,7 +83,7 @@ var DeclarationPlugin = /** @class */ (function () {
85
83
  // },
86
84
  // };
87
85
  // As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
88
- compilation.emitAsset(_this.options.out, new webpack.sources.RawSource(combinedDeclaration));
86
+ compilation.emitAsset(this.options.out, new webpack.sources.RawSource(combinedDeclaration));
89
87
  //get meta data from module exports
90
88
  /*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
91
89
  //and insert that back into the assets as [module_name].meta.json
@@ -100,26 +98,18 @@ var DeclarationPlugin = /** @class */ (function () {
100
98
  //}
101
99
  });
102
100
  });
103
- };
104
- DeclarationPlugin.prototype.debug = function () {
105
- var msgs = [];
106
- for (var _i = 0; _i < arguments.length; _i++) {
107
- msgs[_i] = arguments[_i];
108
- }
101
+ }
102
+ debug(...msgs) {
109
103
  msgs.unshift('declarations:');
110
104
  if (this.logMessages) {
111
105
  console.log.apply(null, msgs);
112
106
  }
113
- };
114
- DeclarationPlugin.prototype.log = function () {
115
- var msgs = [];
116
- for (var _i = 0; _i < arguments.length; _i++) {
117
- msgs[_i] = arguments[_i];
118
- }
107
+ }
108
+ log(...msgs) {
119
109
  msgs.unshift('declarations:');
120
110
  console.log.apply(null, msgs);
121
- };
122
- DeclarationPlugin.prototype.generateCombinedDeclaration = function (declarationFiles) {
111
+ }
112
+ generateCombinedDeclaration(declarationFiles) {
123
113
  this.debug('generating combined declaration');
124
114
  var declarations = '';
125
115
  //this.debug("daCore: using config ",moduleConfig);
@@ -153,8 +143,8 @@ var DeclarationPlugin = /** @class */ (function () {
153
143
  if ((importPath.substr(0, 2) == './' || importPath.substr(0, 3) == '../') && !importMap[importPath]) {
154
144
  //we will replace it with the local npm module later, calc and save the absolute path for now
155
145
  //we parse from builds, because now TS-LOADER gives paths relative to its output folder
156
- var parsed = path.parse('./builds/' + declarationFileName);
157
- var fileDirectory = parsed.dir;
146
+ let parsed = path.parse('./builds/' + declarationFileName);
147
+ let fileDirectory = parsed.dir;
158
148
  var absoluteImportPath = path.resolve(fileDirectory, importPath);
159
149
  // this.debug('declarationfilename '+declarationFileName);
160
150
  // this.debug('filedir '+fileDirectory);
@@ -169,7 +159,7 @@ var DeclarationPlugin = /** @class */ (function () {
169
159
  excludeLine = excludeLine || /import ["'][a-z0-9A-Z_\-.\/\\]+["']/.test(line);
170
160
  //if defined, check for excluded references
171
161
  if (!excludeLine && this.excludedReferences && line.indexOf('<reference') !== -1) {
172
- excludeLine = this.excludedReferences.some(function (reference) { return line.indexOf(reference) !== -1; });
162
+ excludeLine = this.excludedReferences.some((reference) => line.indexOf(reference) !== -1);
173
163
  }
174
164
  if (excludeLine) {
175
165
  this.debug('Excluding line ' + i + ': ' + line);
@@ -184,32 +174,31 @@ var DeclarationPlugin = /** @class */ (function () {
184
174
  }
185
175
  }
186
176
  //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)
187
- var fixedDeclarationPath = declarationFileName.replace(/\\/g, '/').replace('../', '').replace('.d.ts', '');
177
+ let fixedDeclarationPath = declarationFileName.replace(/\\/g, '/').replace('../', '').replace('.d.ts', '');
188
178
  var moduleDeclaration = npmModuleName + '/' + fixedDeclarationPath;
189
179
  //this.debug('basePath:'+basePath);
190
180
  declarations += "declare module '" + moduleDeclaration + "' {\n\t" + lines.join('\n\t') + '\n}\n\n';
191
181
  this.debug('Defining module ' + colors.yellow(moduleDeclaration) + ' from ' + colors.blue(declarationFileName));
192
182
  }
193
183
  for (var relativeImportPath in importMap) {
194
- var absoluteImportPath_1 = importMap[relativeImportPath];
195
- var npmImportModule = npmModuleName + '/' + absoluteImportPath_1.substr(basePath.length).replace('.d.ts', '').replace(/\\/g, '/');
184
+ let absoluteImportPath = importMap[relativeImportPath];
185
+ let npmImportModule = npmModuleName + '/' + absoluteImportPath.substr(basePath.length).replace('.d.ts', '').replace(/\\/g, '/');
196
186
  this.debug('Replacing ' + colors.blue(relativeImportPath) + ' with ' + colors.yellow(npmImportModule));
197
187
  //wrap in quotes to omit problems with replacing partials and having to fix order of replacements
198
188
  declarations = declarations.replace(new RegExp('(\'|")' + relativeImportPath + '(\'|")', 'g'), '"' + npmImportModule + '"');
199
189
  }
200
- var indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
190
+ let indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
201
191
  this.debug('Replacing index ' + colors.yellow(indexModulePath) + ' with ' + colors.yellow(this.modulePackageInfo.name));
202
192
  declarations = declarations.replace("'" + indexModulePath + "'", "'" + this.modulePackageInfo.name + "'");
203
193
  //replace alias
204
194
  if (this.options.alias) {
205
- for (var aliasKey in this.options.alias) {
195
+ for (let aliasKey in this.options.alias) {
206
196
  //declarations = declarations.replace(aliasKey,this.options.alias[aliasKey]);
207
197
  this.debug('Replacing alias ' + aliasKey + ' with ' + this.options.alias[aliasKey]);
208
198
  declarations = declarations.replace(new RegExp(aliasKey, 'g'), this.options.alias[aliasKey]);
209
199
  }
210
200
  }
211
201
  return declarations;
212
- };
213
- return DeclarationPlugin;
214
- }());
215
- exports["default"] = DeclarationPlugin;
202
+ }
203
+ }
204
+ exports.default = DeclarationPlugin;
@@ -1,23 +1,7 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
19
3
  /// <reference path="colors.d.ts" />
20
- var colors = require("colors");
4
+ const colors = require("colors");
21
5
  var exportRoot = '/lib';
22
6
  var libraryName = 'lincd';
23
7
  var lincdModules = new Map();
@@ -29,31 +13,22 @@ var includedLincdModules = new Set();
29
13
  //it basically turns every import from a lincd module into a lookup for that class/object in the global lincd object
30
14
  //See also: https://webpack.js.org/configuration/externals/
31
15
  var externaliseModules = function (config, es5) {
32
- function debug() {
33
- var msgs = [];
34
- for (var _i = 0; _i < arguments.length; _i++) {
35
- msgs[_i] = arguments[_i];
36
- }
16
+ function debug(...msgs) {
37
17
  msgs.unshift('externals: ');
38
18
  if (config && config.debug) {
39
19
  console.log.apply(null, msgs);
40
20
  }
41
21
  }
42
- function log() {
43
- var msgs = [];
44
- for (var _i = 0; _i < arguments.length; _i++) {
45
- msgs[_i] = arguments[_i];
46
- }
22
+ function log(...msgs) {
47
23
  msgs.unshift('externals: ');
48
24
  console.log.apply(null, msgs);
49
25
  }
50
26
  // let externalKeys: string[] = config.externals ? Object.keys(config.externals) : [];
51
27
  //return the function that is handed to webpack in the 'externals' option.
52
28
  //it determines for each request what is external and what is not
53
- return function (_a, callback) {
29
+ return function ({ context, request, contextInfo }, callback) {
54
30
  // debug('checking '+request);
55
31
  // debug('imported by '+contextInfo.issuer);
56
- var context = _a.context, request = _a.request, contextInfo = _a.contextInfo;
57
32
  if (config.externals && config.externals[request]) {
58
33
  if (!excludedExternals.has(request)) {
59
34
  excludedExternals.add(request);
@@ -110,7 +85,7 @@ var externaliseModules = function (config, es5) {
110
85
  // --> match[0] = @dacore/some-mod
111
86
  // --> match[1] = @dacore
112
87
  // --> match[2] = some-mod
113
- var _b = __read(request.match(/(@[\w\-]+\/)?([\w\-]+)/), 3), packageName = _b[0], scope = _b[1], cleanPackageName = _b[2];
88
+ let [packageName, scope, cleanPackageName] = request.match(/(@[\w\-]+\/)?([\w\-]+)/);
114
89
  //if this module is listed as internal module in the config (or if we internalize all modules with '*')
115
90
  if (config && config.internals && (config.internals.indexOf(packageName) !== -1 || config.internals === '*')) {
116
91
  //then don't exclude and don't continue this function
@@ -122,7 +97,7 @@ var externaliseModules = function (config, es5) {
122
97
  return callback();
123
98
  }
124
99
  //check if this module is a lincd module
125
- var isLincd = isLincdModule(debug, packageName);
100
+ let isLincd = isLincdModule(debug, packageName);
126
101
  if (isLincd) {
127
102
  if (!includedLincdModules.has(packageName)) {
128
103
  includedLincdModules.add(packageName);
@@ -139,11 +114,11 @@ var externaliseModules = function (config, es5) {
139
114
  return callback();
140
115
  }
141
116
  //remove export root path (for example with lincd/lib/models: the module has lib/ as root, so to get to the exported path lincd.models we need to remove it)
142
- var cleanRequest = request.replace(exportRoot, '');
143
- var targetVariable;
117
+ let cleanRequest = request.replace(exportRoot, '');
118
+ let targetVariable;
144
119
  //expects a flat export / global tree with all the modules classes
145
120
  //replace - by _ and remove es5, because both es6 and es5 modules will be listed under the bare module name in the global treemap
146
- var firstSlash = cleanRequest.indexOf('/');
121
+ let firstSlash = cleanRequest.indexOf('/');
147
122
  //if importing {x} from "lincd" (so directly from library without any paths)
148
123
  if (firstSlash === -1 && cleanRequest == libraryName) {
149
124
  //then we refer straight to the global object
@@ -190,8 +165,8 @@ var externaliseModules = function (config, es5) {
190
165
  function isLincdModule(debug, packageName) {
191
166
  if (!lincdModules.has(packageName)) {
192
167
  // debug(colors.green('checking ' + moduleName + '/package.json'));
193
- var isLincdModule_1;
194
- var modulePackage = void 0;
168
+ let isLincdModule;
169
+ let modulePackage;
195
170
  try {
196
171
  modulePackage = require(packageName + '/package.json');
197
172
  }
@@ -199,9 +174,9 @@ function isLincdModule(debug, packageName) {
199
174
  debug(colors.red(packageName + '/package.json' + ' does not exist'));
200
175
  // return callback();
201
176
  }
202
- isLincdModule_1 = modulePackage && modulePackage.lincd && true;
203
- lincdModules.set(packageName, isLincdModule_1);
177
+ isLincdModule = modulePackage && modulePackage.lincd && true;
178
+ lincdModules.set(packageName, isLincdModule);
204
179
  }
205
180
  return lincdModules.get(packageName);
206
181
  }
207
- exports["default"] = externaliseModules;
182
+ exports.default = externaliseModules;
@@ -4,15 +4,13 @@
4
4
  * triggered webpack re-compilation/re-build
5
5
  */
6
6
  'use strict';
7
- exports.__esModule = true;
8
- var WatchRunPlugin = /** @class */ (function () {
9
- function WatchRunPlugin() {
10
- }
11
- WatchRunPlugin.prototype.apply = function (compiler) {
12
- compiler.hooks.watchRun.tap('WatchRun', function (comp) {
13
- var changedTimes = comp.watchFileSystem.watcher.mtimes;
14
- var changedFiles = Object.keys(changedTimes)
15
- .map(function (file) { return "\n ".concat(file); })
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ class WatchRunPlugin {
9
+ apply(compiler) {
10
+ compiler.hooks.watchRun.tap('WatchRun', (comp) => {
11
+ const changedTimes = comp.watchFileSystem.watcher.mtimes;
12
+ const changedFiles = Object.keys(changedTimes)
13
+ .map((file) => `\n ${file}`)
16
14
  .join('');
17
15
  if (changedFiles.length) {
18
16
  console.log('====================================');
@@ -20,9 +18,8 @@ var WatchRunPlugin = /** @class */ (function () {
20
18
  console.log('====================================');
21
19
  }
22
20
  });
23
- };
24
- return WatchRunPlugin;
25
- }());
21
+ }
22
+ }
26
23
  /*class WebpackWatchRunPlugin {
27
24
  constructor(options?) {
28
25
  if (typeof options !== "object") options = {};
@@ -44,4 +41,4 @@ var WatchRunPlugin = /** @class */ (function () {
44
41
  });
45
42
  }
46
43
  }*/
47
- exports["default"] = WatchRunPlugin;
44
+ exports.default = WatchRunPlugin;
package/lib/utils.js CHANGED
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -33,56 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
22
  __setModuleDefault(result, mod);
34
23
  return result;
35
24
  };
36
- var __values = (this && this.__values) || function(o) {
37
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
38
- if (m) return m.call(o);
39
- if (o && typeof o.length === "number") return {
40
- next: function () {
41
- if (o && i >= o.length) o = void 0;
42
- return { value: o && o[i++], done: !o };
43
- }
44
- };
45
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
46
- };
47
- var __read = (this && this.__read) || function (o, n) {
48
- var m = typeof Symbol === "function" && o[Symbol.iterator];
49
- if (!m) return o;
50
- var i = m.call(o), r, ar = [], e;
51
- try {
52
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
53
- }
54
- catch (error) { e = { error: error }; }
55
- finally {
56
- try {
57
- if (r && !r.done && (m = i["return"])) m.call(i);
58
- }
59
- finally { if (e) throw e.error; }
60
- }
61
- return ar;
62
- };
63
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
64
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
65
- if (ar || !(i in from)) {
66
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
67
- ar[i] = from[i];
68
- }
69
- }
70
- return to.concat(ar || Array.prototype.slice.call(from));
71
- };
72
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
73
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
27
  };
75
- exports.__esModule = true;
28
+ Object.defineProperty(exports, "__esModule", { value: true });
76
29
  exports.getLinkedTailwindColors = exports.flatten = exports.warn = exports.debug = exports.log = exports.generateScopedName = exports.execPromise = exports.execp = exports.getGruntConfig = exports.getModulePackageJSON = exports.getLINCDDependencies = exports.getPackageJSON = void 0;
77
- var fs = __importStar(require("fs"));
78
- var path = __importStar(require("path"));
79
- var chalk_1 = __importDefault(require("chalk"));
80
- var child_process_1 = require("child_process");
81
- var _a = require('find-nearest-package-json'), findNearestPackageJson = _a.findNearestPackageJson, findNearestPackageJsonSync = _a.findNearestPackageJsonSync;
82
- var getPackageJSON = function (root, error) {
83
- if (root === void 0) { root = process.cwd(); }
84
- if (error === void 0) { error = true; }
85
- var packagePath = path.join(root, 'package.json');
30
+ const fs = __importStar(require("fs"));
31
+ const path = __importStar(require("path"));
32
+ const chalk_1 = __importDefault(require("chalk"));
33
+ const child_process_1 = require("child_process");
34
+ const { findNearestPackageJson, findNearestPackageJsonSync } = require('find-nearest-package-json');
35
+ var getPackageJSON = function (root = process.cwd(), error = true) {
36
+ let packagePath = path.join(root, 'package.json');
86
37
  if (fs.existsSync(packagePath)) {
87
38
  return JSON.parse(fs.readFileSync(packagePath, 'utf8'));
88
39
  }
@@ -101,43 +52,62 @@ exports.getPackageJSON = getPackageJSON;
101
52
  * Returns an array of lincd packages, with each entry containing an array with the package name and the local path to the package
102
53
  * @param packageJson
103
54
  */
104
- var getLINCDDependencies = function (packageJson, checkedPackages) {
105
- var e_1, _a;
106
- if (checkedPackages === void 0) { checkedPackages = new Set(); }
55
+ var getLINCDDependencies = function (packageJson, checkedPackages = new Set()) {
56
+ var _a;
107
57
  if (!packageJson) {
108
58
  packageJson = (0, exports.getPackageJSON)();
109
59
  }
110
- var dependencies = __assign(__assign({}, packageJson.dependencies), packageJson.devDependencies);
111
- var lincdPackagePaths = [];
112
- try {
113
- for (var _b = __values(Object.keys(dependencies)), _c = _b.next(); !_c.done; _c = _b.next()) {
114
- var dependency = _c.value;
115
- try {
116
- if (!checkedPackages.has(dependency)) {
117
- checkedPackages.add(dependency);
118
- var _d = __read((0, exports.getModulePackageJSON)(dependency), 2), modulePackageJson = _d[0], modulePath = _d[1];
119
- if (modulePackageJson === null || modulePackageJson === void 0 ? void 0 : modulePackageJson.lincd) {
120
- lincdPackagePaths.push([modulePackageJson.name, modulePath]);
121
- //also check if this package has any dependencies that are lincd packages
122
- lincdPackagePaths = lincdPackagePaths.concat((0, exports.getLINCDDependencies)(modulePackageJson, checkedPackages));
123
- }
124
- if (!modulePackageJson) {
125
- //this seems to only happen with yarn workspaces for some grunt related dependencies of lincd-cli
126
- // console.log(`could not find package.json of ${dependency}`);
127
- }
60
+ let dependencies = Object.assign(Object.assign({}, packageJson.dependencies), packageJson.devDependencies);
61
+ let lincdPackagePaths = [];
62
+ let firstTime = checkedPackages.size === 0;
63
+ for (var dependency of Object.keys(dependencies)) {
64
+ try {
65
+ if (!checkedPackages.has(dependency)) {
66
+ let [modulePackageJson, modulePath] = (0, exports.getModulePackageJSON)(dependency);
67
+ checkedPackages.add(dependency);
68
+ if (modulePackageJson === null || modulePackageJson === void 0 ? void 0 : modulePackageJson.lincd) {
69
+ lincdPackagePaths.push([modulePackageJson.name, modulePath, [...Object.keys(Object.assign(Object.assign({}, modulePackageJson.dependencies), modulePackageJson.devDependencies))]]);
70
+ //also check if this package has any dependencies that are lincd packages
71
+ lincdPackagePaths = lincdPackagePaths.concat((0, exports.getLINCDDependencies)(modulePackageJson, checkedPackages));
72
+ }
73
+ if (!modulePackageJson) {
74
+ //this seems to only happen with yarn workspaces for some grunt related dependencies of lincd-cli
75
+ // console.log(`could not find package.json of ${dependency}`);
128
76
  }
129
77
  }
130
- catch (err) {
131
- console.log("could not check if ".concat(dependency, " is a lincd package: ").concat(err));
132
- }
78
+ }
79
+ catch (err) {
80
+ console.log(`could not check if ${dependency} is a lincd package: ${err}`);
133
81
  }
134
82
  }
135
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
136
- finally {
137
- try {
138
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
83
+ if (firstTime) {
84
+ let dependencyMap = new Map();
85
+ let lincdPackageNames = new Set(lincdPackagePaths.map(([packageName, modulePath, pkgDependencies]) => packageName));
86
+ //remove lincd-cli from the list of lincd packages
87
+ lincdPackageNames.delete('lincd-cli');
88
+ lincdPackagePaths.forEach(([packageName, modulePath, pkgDependencies]) => {
89
+ dependencyMap.set(packageName, new Set(pkgDependencies.filter(dependency => lincdPackageNames.has(dependency))));
90
+ });
91
+ //remove lincd-modules from the dependencies of lincd-cli (it's not a hard dependency, and it messes things up)
92
+ (_a = dependencyMap.get('lincd-cli')) === null || _a === void 0 ? void 0 : _a.delete('lincd-modules');
93
+ //add the nested dependencies for each lincd package
94
+ for (let [packageName, pkgDependencies] of dependencyMap) {
95
+ pkgDependencies.forEach((dependency) => {
96
+ if (dependencyMap.has(dependency)) {
97
+ dependencyMap.get(dependency).forEach((nestedDependency) => {
98
+ pkgDependencies.add(nestedDependency);
99
+ });
100
+ }
101
+ });
139
102
  }
140
- finally { if (e_1) throw e_1.error; }
103
+ //sort the lincd packages by least dependent first
104
+ lincdPackagePaths.sort(([packageNameA, modulePathA, pkgDependenciesA], [packageNameB, modulePathB, pkgDependenciesB]) => {
105
+ //if package A depends on package B, then package B should come first
106
+ if (dependencyMap.get(packageNameA).has(packageNameB)) {
107
+ return 1;
108
+ }
109
+ return -1;
110
+ });
141
111
  }
142
112
  return lincdPackagePaths;
143
113
  };
@@ -163,10 +133,8 @@ var getModulePackageJSON = function (module_name, work_dir) {
163
133
  return [package_json, module_dir];
164
134
  };
165
135
  exports.getModulePackageJSON = getModulePackageJSON;
166
- var getGruntConfig = function (root, error) {
167
- if (root === void 0) { root = process.cwd(); }
168
- if (error === void 0) { error = true; }
169
- var gruntFile = path.join(root, 'Gruntfile.js');
136
+ var getGruntConfig = function (root = process.cwd(), error = true) {
137
+ let gruntFile = path.join(root, 'Gruntfile.js');
170
138
  if (fs.existsSync(gruntFile)) {
171
139
  return require(gruntFile)();
172
140
  }
@@ -178,14 +146,11 @@ var getGruntConfig = function (root, error) {
178
146
  }
179
147
  };
180
148
  exports.getGruntConfig = getGruntConfig;
181
- function execp(cmd, log, allowError, options) {
182
- if (log === void 0) { log = false; }
183
- if (allowError === void 0) { allowError = false; }
184
- if (options === void 0) { options = {}; }
149
+ function execp(cmd, log = false, allowError = false, options = {}) {
185
150
  // opts || (opts = {});
186
151
  if (log)
187
- console.log(chalk_1["default"].cyan(cmd));
188
- return new Promise(function (resolve, reject) {
152
+ console.log(chalk_1.default.cyan(cmd));
153
+ return new Promise((resolve, reject) => {
189
154
  var child = (0, child_process_1.exec)(cmd, options);
190
155
  child.stdout.pipe(process.stdout);
191
156
  child.stderr.pipe(process.stderr);
@@ -233,17 +198,14 @@ function execp(cmd, log, allowError, options) {
233
198
  });
234
199
  }
235
200
  exports.execp = execp;
236
- function execPromise(command, log, allowError, options, pipeOutput) {
237
- if (log === void 0) { log = false; }
238
- if (allowError === void 0) { allowError = false; }
239
- if (pipeOutput === void 0) { pipeOutput = false; }
201
+ function execPromise(command, log = false, allowError = false, options, pipeOutput = false) {
240
202
  return new Promise(function (resolve, reject) {
241
203
  if (log)
242
- console.log(chalk_1["default"].cyan(command));
243
- var child = (0, child_process_1.exec)(command, options, function (error, stdout, stderr) {
204
+ console.log(chalk_1.default.cyan(command));
205
+ let child = (0, child_process_1.exec)(command, options, (error, stdout, stderr) => {
244
206
  if (error) {
245
207
  if (!allowError) {
246
- reject({ error: error, stdout: stdout, stderr: stderr });
208
+ reject({ error, stdout, stderr });
247
209
  return;
248
210
  }
249
211
  else if (log) {
@@ -251,7 +213,7 @@ function execPromise(command, log, allowError, options, pipeOutput) {
251
213
  }
252
214
  }
253
215
  //TODO: getting a typescript error for 'trim()', this worked before, is it still used? do we log anywhere?
254
- var result = stdout['trim']();
216
+ let result = stdout['trim']();
255
217
  if (log) {
256
218
  // console.log(chalk"RESOLVING "+command);
257
219
  console.log(result);
@@ -271,8 +233,8 @@ exports.execPromise = execPromise;
271
233
  function generateScopedName(moduleName, name, filename, css) {
272
234
  // console.log(moduleName,name,filename,css);
273
235
  var file = path.basename(filename, '.scss');
274
- var nearestPackageJson = findNearestPackageJsonSync(filename);
275
- var packageName = nearestPackageJson ? nearestPackageJson.data.name : moduleName;
236
+ let nearestPackageJson = findNearestPackageJsonSync(filename);
237
+ let packageName = nearestPackageJson ? nearestPackageJson.data.name : moduleName;
276
238
  return packageName.replace(/[^a-zA-Z0-9_]+/g, '_') + '_' + file + '_' + name;
277
239
  // process.exit();
278
240
  // var path = require('path');
@@ -303,33 +265,21 @@ function generateScopedName(moduleName, name, filename, css) {
303
265
  return moduleName + '_' + file + '_' + name;
304
266
  }
305
267
  exports.generateScopedName = generateScopedName;
306
- function log() {
307
- var messages = [];
308
- for (var _i = 0; _i < arguments.length; _i++) {
309
- messages[_i] = arguments[_i];
310
- }
311
- messages.forEach(function (message) {
312
- console.log(chalk_1["default"].cyan(message));
268
+ function log(...messages) {
269
+ messages.forEach((message) => {
270
+ console.log(chalk_1.default.cyan(message));
313
271
  });
314
272
  }
315
273
  exports.log = log;
316
- function debug(config) {
317
- var messages = [];
318
- for (var _i = 1; _i < arguments.length; _i++) {
319
- messages[_i - 1] = arguments[_i];
320
- }
274
+ function debug(config, ...messages) {
321
275
  if (config.debug) {
322
- log.apply(void 0, __spreadArray([], __read(messages), false));
276
+ log(...messages);
323
277
  }
324
278
  }
325
279
  exports.debug = debug;
326
- function warn() {
327
- var messages = [];
328
- for (var _i = 0; _i < arguments.length; _i++) {
329
- messages[_i] = arguments[_i];
330
- }
331
- messages.forEach(function (message) {
332
- console.log(chalk_1["default"].red(message));
280
+ function warn(...messages) {
281
+ messages.forEach((message) => {
282
+ console.log(chalk_1.default.red(message));
333
283
  });
334
284
  }
335
285
  exports.warn = warn;
@@ -342,7 +292,7 @@ exports.flatten = flatten;
342
292
  function getLinkedTailwindColors() {
343
293
  return {
344
294
  'primary-color': 'var(--primary-color)',
345
- 'font-color': 'var(--font-color)'
295
+ 'font-color': 'var(--font-color)',
346
296
  };
347
297
  }
348
298
  exports.getLinkedTailwindColors = getLinkedTailwindColors;