lincd-cli 0.2.54 → 0.2.58

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.
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.depCheck = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
15
+ exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.depCheck = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
18
18
  const utils_1 = require("./utils");
@@ -742,6 +742,14 @@ const createComponent = (name, basePath = process.cwd()) => __awaiter(void 0, vo
742
742
  }
743
743
  });
744
744
  exports.createComponent = createComponent;
745
+ const checkImports = () => __awaiter(void 0, void 0, void 0, function* () {
746
+ //read the source of all ts/tsx files in the src folder
747
+ //if there is an import that imports a lincd package with /src/ in it, then warn
748
+ //if there is an import that imports outside of the src folder, then warn
749
+ //TODO: use dependency-cruiser for this
750
+ //https://github.com/sverweij/dependency-cruiser/blob/HEAD/doc/api.md
751
+ });
752
+ exports.checkImports = checkImports;
745
753
  const depCheck = () => __awaiter(void 0, void 0, void 0, function* () {
746
754
  (0, depcheck_1.default)(process.cwd(), {}, (results) => {
747
755
  if (results.missing) {
@@ -963,6 +971,14 @@ const buildPackage = (target, target2, packagePath = process.cwd(), logResults =
963
971
  (target2 ? '-' + target2 : '') +
964
972
  ' --color');
965
973
  let method = logResults ? utils_1.execp : utils_1.execPromise;
974
+ //NOTE: we moved SCSS:JSON out of webpack and grunt, into this file
975
+ //this is the beginning of a transition away from grunt
976
+ //but for the time being it's perhaps a bit strange that we
977
+ // let x = postcss([
978
+ // postcssModules({
979
+ // generateScopedName,
980
+ // }),
981
+ // ]);
966
982
  //execute the command to build the method, and provide the current work directory as option
967
983
  return method(nodeEnv +
968
984
  'grunt build' +
@@ -1269,8 +1285,6 @@ var buildUpdated = function (back, target, target2, test = false) {
1269
1285
  if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1270
1286
  needRebuild = true;
1271
1287
  }
1272
- // console.log(pkg.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
1273
- // console.log(pkg.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
1274
1288
  if (needRebuild || rebuildAllModules) {
1275
1289
  //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1276
1290
  // log(packageName+' modified since last commit on '+now.toString());
@@ -1313,70 +1327,6 @@ var buildUpdated = function (back, target, target2, test = false) {
1313
1327
  }
1314
1328
  });
1315
1329
  return;
1316
- var p = Promise.resolve('');
1317
- packages.forEach((pkg) => {
1318
- let packageName = pkg.packageName;
1319
- p = p
1320
- .then((previousResult) => {
1321
- let lastModifiedSource = getLastModifiedSourceTime(pkg.path);
1322
- let lastModifiedBundle = getLastBuildTime(pkg.path);
1323
- // console.log(pkg.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
1324
- // console.log(pkg.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
1325
- debugInfo('# Checking package ' + packageName);
1326
- if (lastModifiedSource.lastModifiedTime >
1327
- lastModifiedBundle.lastModifiedTime) {
1328
- //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1329
- // log(packageName+' modified since last commit on '+now.toString());
1330
- debugInfo(chalk_1.default.cyan('Last modified source: ' +
1331
- lastModifiedSource.lastModifiedName +
1332
- ' on ' +
1333
- lastModifiedSource.lastModified.toString()));
1334
- debugInfo(chalk_1.default.cyan('Last build: ' +
1335
- (lastModifiedBundle &&
1336
- typeof lastModifiedBundle.lastModified !== 'undefined'
1337
- ? lastModifiedBundle.lastModified.toString()
1338
- : 'never')));
1339
- if (test) {
1340
- debugInfo('need to build ' + packageName);
1341
- }
1342
- else {
1343
- log('building ' + packageName);
1344
- }
1345
- if (!test) {
1346
- return (0, utils_1.execPromise)('cd ' +
1347
- pkg.path +
1348
- ' && yarn build' +
1349
- (target ? ' ' + target : '') +
1350
- (target2 ? ' ' + target2 : '')).then((res) => {
1351
- if (res.indexOf('Aborted due to warnings') !== -1 ||
1352
- res.indexOf('Fatal error') !== -1) {
1353
- console.log(res);
1354
- return (previousResult + ' ' + chalk_1.default.red(packageName + ' failed\n'));
1355
- }
1356
- console.log(chalk_1.default.green(packageName + ' successfully built'));
1357
- return (previousResult + ' ' + chalk_1.default.green(packageName + ' built\n'));
1358
- });
1359
- }
1360
- return (previousResult +
1361
- ' ' +
1362
- chalk_1.default.blue(packageName + ' should be build\n'));
1363
- }
1364
- return previousResult;
1365
- })
1366
- .catch(({ error, stdout, stderr }) => {
1367
- console.log(stdout);
1368
- return previousResult + ' ' + chalk_1.default.red(packageName + ' failed\n');
1369
- });
1370
- });
1371
- return p.then((messages) => {
1372
- if (messages == '') {
1373
- console.log(chalk_1.default.green('Nothing to rebuild.'));
1374
- }
1375
- else {
1376
- console.log('Summary: \n' + messages);
1377
- }
1378
- });
1379
- // });
1380
1330
  });
1381
1331
  };
1382
1332
  exports.buildUpdated = buildUpdated;
@@ -1385,11 +1335,11 @@ const needsRebuilding = function (pkg, log = false) {
1385
1335
  let lastModifiedBundle = getLastBuildTime(pkg.path);
1386
1336
  let result = lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime;
1387
1337
  if (log) {
1388
- debugInfo(chalk_1.default.cyan('Last modified source: ' +
1338
+ console.log(chalk_1.default.cyan('Last modified source: ' +
1389
1339
  lastModifiedSource.lastModifiedName +
1390
1340
  ' on ' +
1391
1341
  lastModifiedSource.lastModified.toString()));
1392
- debugInfo(chalk_1.default.cyan('Last build: ' +
1342
+ console.log(chalk_1.default.cyan('Last build: ' +
1393
1343
  (lastModifiedBundle &&
1394
1344
  typeof lastModifiedBundle.lastModified !== 'undefined'
1395
1345
  ? lastModifiedBundle.lastModified.toString()
package/lib/cli.js CHANGED
@@ -126,6 +126,9 @@ program.command('dev [target] [mode]').action((target, mode) => {
126
126
  program.command('depcheck').action((target, mode) => {
127
127
  (0, cli_methods_1.depCheck)();
128
128
  });
129
+ program.command('check-imports').action((target, mode) => {
130
+ (0, cli_methods_1.checkImports)();
131
+ });
129
132
  program
130
133
  .command('package')
131
134
  .action((name, command, args) => {
@@ -87,7 +87,13 @@ function setupGrunt(grunt, moduleName, config) {
87
87
  'prepare-build',
88
88
  // buildFrontend ? 'webpack:build-es6' : null,
89
89
  buildServer
90
- ? ['clean:lib', 'exec:build-lib', 'copy:lib', 'exec:depcheck']
90
+ ? [
91
+ 'clean:lib',
92
+ 'exec:build-lib',
93
+ 'copy:lib',
94
+ 'exec:depcheck',
95
+ 'exec:check-imports',
96
+ ]
91
97
  : null,
92
98
  // 'exec:shapes',
93
99
  ]));
@@ -114,6 +120,7 @@ function setupGrunt(grunt, moduleName, config) {
114
120
  beforeBuildCommand: config.beforeBuildCommand,
115
121
  'server-dev': 'tsc -w',
116
122
  depcheck: 'yarn lincd depcheck',
123
+ 'check-imports': 'yarn lincd check-imports',
117
124
  test: 'tsc -w',
118
125
  // shapes: 'lincd shapes',
119
126
  'css-declarations': 'tcm -p **/*.scss',
@@ -136,9 +143,21 @@ function setupGrunt(grunt, moduleName, config) {
136
143
  postcss: {
137
144
  options: {
138
145
  map: true,
139
- processors: [require('postcss-modules')({ generateScopedName: utils_1.generateScopedName })],
146
+ // parser: require('postcss-scss'), //require('postcss-comment'),
140
147
  syntax: require('postcss-scss'),
141
- writeDest: false,
148
+ processors: [
149
+ require('postcss-preset-env'),
150
+ require('postcss-strip-inline-comments'),
151
+ require('postcss-modules')({
152
+ generateScopedName: utils_1.generateScopedName.bind(this, config.prod, false),
153
+ globalModulePaths: [
154
+ /tailwind/,
155
+ /tailwindcss/,
156
+ config.cssGlobalModulePaths,
157
+ ].filter(Boolean),
158
+ }),
159
+ ],
160
+ // writeDest: false,
142
161
  },
143
162
  cssjson: {
144
163
  src: 'src/**/*.scss',
@@ -149,19 +168,19 @@ function setupGrunt(grunt, moduleName, config) {
149
168
  },
150
169
  concurrent: {
151
170
  dev: (0, utils_1.flatten)([
152
- buildFrontend ? 'webpack:dev' : null,
171
+ // buildFrontend ? 'webpack:dev' : null,
153
172
  buildServer ? 'exec:server-dev' : null,
154
173
  // buildServer ? 'watch:css-module-transforms' : null,
155
174
  // 'exec:css-declarations-watch'
156
175
  ]),
157
176
  'dev-prod': (0, utils_1.flatten)([
158
- buildFrontend ? 'webpack:dev-prod' : null,
177
+ // buildFrontend ? 'webpack:dev-prod' : null,
159
178
  buildServer ? 'exec:server-dev' : null,
160
179
  // buildServer ? 'watch:css-module-transforms' : null,
161
180
  // 'exec:css-declarations-watch'
162
181
  ]),
163
182
  'dev-es5': (0, utils_1.flatten)([
164
- buildFrontend ? 'webpack:dev-es5' : null,
183
+ // buildFrontend ? 'webpack:dev-es5' : null,
165
184
  buildServer ? 'exec:server-dev' : null,
166
185
  // buildServer ? 'watch:css-module-transforms' : null,
167
186
  // 'exec:css-declarations-watch'
@@ -175,7 +175,7 @@ function generateWebpackConfig(buildName, moduleName, config = {}) {
175
175
  postcssPlugins.push([
176
176
  'postcss-modules',
177
177
  {
178
- generateScopedName: utils_1.generateScopedName.bind(null, moduleName),
178
+ generateScopedName: utils_1.generateScopedName.bind(null, config.prod, true),
179
179
  globalModulePaths: [
180
180
  /tailwind/,
181
181
  /tailwindcss/,
@@ -34,15 +34,15 @@ function handler(source) {
34
34
  //save as userRequest?
35
35
  let resource = this._module.resource;
36
36
  let relativePath = this._module.resourceResolveData.relativePath;
37
- // console.log('-----');
37
+ console.log('-----');
38
38
  // for (let key in this) {
39
39
  // console.log(key, this[key]);
40
40
  // }
41
41
  let isRelativeReq = request.indexOf('./') === 0 || request.indexOf('../') === 0;
42
42
  // if (isRelativeReq) {
43
- // console.log('rootContext', rootContext);
44
- // console.log('context', context);
45
- // console.log('request', request);
43
+ console.log('rootContext', rootContext);
44
+ console.log('context', context);
45
+ console.log('request', request);
46
46
  // // console.log('userRequest', userRequest);
47
47
  // // console.log('resource', resource);
48
48
  // console.log('relativePath', relativePath);
package/lib/utils.js CHANGED
@@ -275,41 +275,28 @@ function execPromise(command, log = false, allowError = false, options, pipeOutp
275
275
  }
276
276
  exports.execPromise = execPromise;
277
277
  // export function generateScopedName(moduleName,name, filename, css) {
278
- function generateScopedName(moduleName, name, filename, css) {
279
- // console.log(moduleName,name,filename,css);
280
- var file = path.basename(filename, '.scss');
278
+ function generateScopedName(isProduction, isWebpack, cssClassName, filepath, css) {
279
+ //for app development we can use short unique hashes
280
+ //but for webpack bundles of lincd modules, we need to ensure unique class names across bundles of many packages
281
+ if (isProduction && !isWebpack) {
282
+ //generate a short unique hash based on cssClassName and filepath
283
+ let hash = require('crypto')
284
+ .createHash('md5')
285
+ .update(cssClassName + filepath)
286
+ .digest('hex')
287
+ .substring(0, 6);
288
+ return hash;
289
+ }
290
+ var filename = path.basename(filepath, '.scss');
281
291
  let nearestPackageJson = findNearestPackageJsonSync(filename);
282
292
  let packageName = nearestPackageJson
283
293
  ? nearestPackageJson.data.name
284
- : moduleName;
285
- return packageName.replace(/[^a-zA-Z0-9_]+/g, '_') + '_' + file + '_' + name;
286
- // process.exit();
287
- // var path = require('path');
288
- var file = path.basename(filename, '.scss');
289
- var module = filename.match(/[\\\/]modules[\\\/]([\w\-_]+)/);
290
- var moduleName;
291
- if (module) {
292
- moduleName = module[1];
293
- }
294
- else {
295
- //if we cant find module name from path, we'll use a hash
296
- //https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
297
- var hash = 0;
298
- if (filename.length == 0) {
299
- moduleName = '_unknown';
300
- }
301
- else {
302
- for (var i = 0; i < filename.length; i++) {
303
- var char = filename.charCodeAt(i);
304
- hash = (hash << 5) - hash + char;
305
- hash = hash & hash; // Convert to 32bit integer
306
- }
307
- moduleName = hash;
308
- }
309
- }
310
- // console.log("Module name: "+moduleName);
311
- // console.log("Returning: " + moduleName + "_" + file + "_" + name);
312
- return moduleName + '_' + file + '_' + name;
294
+ : 'unknown';
295
+ return (packageName.replace(/[^a-zA-Z0-9_]+/g, '_') +
296
+ '_' +
297
+ filename +
298
+ '_' +
299
+ cssClassName);
313
300
  }
314
301
  exports.generateScopedName = generateScopedName;
315
302
  function log(...messages) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "lincd-cli",
3
- "version": "0.2.54",
3
+ "version": "0.2.58",
4
4
  "description": "Command line tools for the lincd.js library",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "prepublishOnly": "npm exec tsc",
8
8
  "build": "npm exec tsc",
9
9
  "_postinstall": "husky install",
10
- "prepack": "yarn version patch && npm exec tsc && pinst --disable",
10
+ "prepack": "npm exec tsc && pinst --disable && yarn version patch",
11
11
  "postpack": "pinst --enable",
12
12
  "dev": "npm exec tsc -w",
13
13
  "prettier": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --check",
@@ -63,10 +63,10 @@
63
63
  "find-nearest-package-json": "^2.0.1",
64
64
  "fs-extra": "^11.1.1",
65
65
  "glob": "^7.1.6",
66
- "grunt": "^1.3.0",
66
+ "grunt": "^1.6.1",
67
67
  "grunt-cli": "^1.4.3",
68
68
  "grunt-concurrent": "^3.0.0",
69
- "grunt-contrib-clean": "^2.0.0",
69
+ "grunt-contrib-clean": "^2.0.1",
70
70
  "grunt-contrib-copy": "^1.0.0",
71
71
  "grunt-exec": "^3.0.0",
72
72
  "grunt-ts": "^6.0.0-beta.22",
@@ -78,12 +78,14 @@
78
78
  "load-grunt-tasks": "^5.1.0",
79
79
  "mini-css-extract-plugin": "^2.7.5",
80
80
  "open": "^8.4.0",
81
- "postcss": "^8.4.17",
82
- "postcss-import": "^15.0.0",
83
- "postcss-loader": "^7.0.1",
81
+ "postcss": "^8.4.31",
82
+ "postcss-comment": "^2.0.0",
83
+ "postcss-import": "^15.1.0",
84
+ "postcss-loader": "^7.3.3",
84
85
  "postcss-modules": "^6.0.0",
85
- "postcss-nested": "^5.0.6",
86
- "postcss-scss": "^4.0.5",
86
+ "postcss-nested": "^6.0.1",
87
+ "postcss-scss": "^4.0.9",
88
+ "postcss-strip-inline-comments": "^0.1.5",
87
89
  "require-extensions": "^0.0.4",
88
90
  "sass": "^1.55.0",
89
91
  "sass-loader": "^13.0.2",