pxt-core 8.1.2 → 8.1.3

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.
@@ -216,7 +216,7 @@ function buildHexAsync(buildEngine, mainPkg, extInfo, forceBuild) {
216
216
  let allFiles = U.clone(extInfo.generatedFiles);
217
217
  U.jsonCopyFrom(allFiles, extInfo.extensionFiles);
218
218
  let writeFiles = () => {
219
- for (let f of nodeutil.allFiles(buildEngine.buildPath + "/" + buildEngine.appPath, 8, true)) {
219
+ for (let f of nodeutil.allFiles(buildEngine.buildPath + "/" + buildEngine.appPath, { maxDepth: 8, allowMissing: true })) {
220
220
  let bn = f.slice(buildEngine.buildPath.length);
221
221
  bn = bn.replace(/\\/g, "/").replace(/^\//, "/");
222
222
  if (U.startsWith(bn, "/" + buildEngine.appPath + "/") && !allFiles[bn]) {
@@ -471,7 +471,7 @@ function buildDalConst(buildEngine, mainPkg, rebuild = false, create = false) {
471
471
  if (U.endsWith(dn, ".h"))
472
472
  files.push(dn);
473
473
  else {
474
- let here = nodeutil.allFiles(dn, 20).filter(fn => U.endsWith(fn, ".h"));
474
+ let here = nodeutil.allFiles(dn, { maxDepth: 20 }).filter(fn => U.endsWith(fn, ".h"));
475
475
  U.pushRange(files, here);
476
476
  }
477
477
  }
@@ -487,7 +487,7 @@ function buildDalConst(buildEngine, mainPkg, rebuild = false, create = false) {
487
487
  incPath = buildEngine.buildPath;
488
488
  if (!fs.existsSync(incPath))
489
489
  U.userError("cannot find " + incPath);
490
- files = nodeutil.allFiles(incPath, 20)
490
+ files = nodeutil.allFiles(incPath, { maxDepth: 20 })
491
491
  .filter(fn => U.endsWith(fn, ".h"))
492
492
  .filter(fn => fn.indexOf("/mbed-classic/") < 0)
493
493
  .filter(fn => fn.indexOf("/mbed-os/") < 0);
package/built/cli.js CHANGED
@@ -302,11 +302,11 @@ function onlyExts(files, exts) {
302
302
  }
303
303
  function pxtFileList(pref) {
304
304
  return nodeutil.allFiles(pref + "webapp/public")
305
- .concat(onlyExts(nodeutil.allFiles(pref + "built/web", 1), [".js", ".css"]))
306
- .concat(nodeutil.allFiles(pref + "built/web/fonts", 1))
307
- .concat(nodeutil.allFiles(pref + "built/web/vs", 4))
308
- .concat(nodeutil.allFiles(pref + "built/web/skillmap", 4))
309
- .concat(nodeutil.allFiles(pref + "built/web/authcode", 4));
305
+ .concat(onlyExts(nodeutil.allFiles(pref + "built/web", { maxDepth: 1 }), [".js", ".css"]))
306
+ .concat(nodeutil.allFiles(pref + "built/web/fonts", { maxDepth: 1 }))
307
+ .concat(nodeutil.allFiles(pref + "built/web/vs", { maxDepth: 4 }))
308
+ .concat(nodeutil.allFiles(pref + "built/web/skillmap", { maxDepth: 4 }))
309
+ .concat(nodeutil.allFiles(pref + "built/web/authcode", { maxDepth: 4 }));
310
310
  }
311
311
  function semverCmp(a, b) {
312
312
  let parse = (s) => {
@@ -618,7 +618,7 @@ function targetFileList() {
618
618
  let lst = onlyExts(nodeutil.allFiles("built"), [".js", ".css", ".json", ".webmanifest"])
619
619
  .concat(nodeutil.allFiles(path.join(simDir(), "public")));
620
620
  if (simDir() != "sim")
621
- lst = lst.concat(nodeutil.allFiles(path.join("sim", "public"), 5, true));
621
+ lst = lst.concat(nodeutil.allFiles(path.join("sim", "public"), { maxDepth: 5, allowMissing: true }));
622
622
  pxt.debug(`target files (on disk): ${lst.join('\r\n ')}`);
623
623
  return lst;
624
624
  }
@@ -1133,7 +1133,7 @@ function forEachBundledPkgAsync(f, includeProjects = false) {
1133
1133
  let prev = process.cwd();
1134
1134
  let folders = pxt.appTarget.bundleddirs;
1135
1135
  if (includeProjects) {
1136
- let projects = nodeutil.allFiles("libs", 1, /*allowMissing*/ false, /*includeDirs*/ true).filter(f => /prj$/.test(f));
1136
+ let projects = nodeutil.allFiles("libs", { maxDepth: 1, includeDirs: true }).filter(f => /prj$/.test(f));
1137
1137
  folders = folders.concat(projects);
1138
1138
  }
1139
1139
  return U.promiseMapAllSeries(folders, (dirname) => {
@@ -1298,7 +1298,7 @@ function buildEditorExtensionAsync(dirname, optionName) {
1298
1298
  else
1299
1299
  p = buildFolderAsync(dirname, true, dirname);
1300
1300
  return p.then(() => {
1301
- const prepends = nodeutil.allFiles(path.join(dirname, "prepend"), 1, true)
1301
+ const prepends = nodeutil.allFiles(path.join(dirname, "prepend"), { maxDepth: 1, allowMissing: true })
1302
1302
  .filter(f => /\.js$/.test(f));
1303
1303
  if (prepends && prepends.length) {
1304
1304
  const editorjs = path.join("built", dirname + ".js");
@@ -1899,7 +1899,7 @@ function updateDefaultProjects(cfg) {
1899
1899
  pxt.BLOCKS_PROJECT_NAME,
1900
1900
  pxt.JAVASCRIPT_PROJECT_NAME
1901
1901
  ];
1902
- nodeutil.allFiles("libs", 1, /*allowMissing*/ false, /*includeDirs*/ true)
1902
+ nodeutil.allFiles("libs", { maxDepth: 1, includeDirs: true })
1903
1903
  .filter((f) => {
1904
1904
  return defaultProjects.indexOf(path.basename(f)) !== -1;
1905
1905
  })
@@ -2360,7 +2360,7 @@ function renderDocs(builtPackaged, localDir) {
2360
2360
  docFolders.push(...nodeutil.getBundledPackagesDocs());
2361
2361
  docFolders.push("docs");
2362
2362
  for (const docFolder of docFolders) {
2363
- for (const f of nodeutil.allFiles(docFolder, 8)) {
2363
+ for (const f of nodeutil.allFiles(docFolder, { maxDepth: 8 })) {
2364
2364
  pxt.log(`rendering ${f}`);
2365
2365
  const pathUnderDocs = f.slice(docFolder.length + 1);
2366
2366
  let outputFile = path.join(dst, "docs", pathUnderDocs);
@@ -4484,7 +4484,7 @@ function buildJResSpritesDirectoryAsync(dir) {
4484
4484
  return [(v >> 16) & 0xff, (v >> 8) & 0xff, (v >> 0) & 0xff];
4485
4485
  });
4486
4486
  let ts = `namespace ${metaInfo.star.namespace} {\n`;
4487
- for (let fn of nodeutil.allFiles(dir, 1)) {
4487
+ for (let fn of nodeutil.allFiles(dir, { maxDepth: 1 })) {
4488
4488
  fn = fn.replace(/\\/g, "/");
4489
4489
  let m = /(.*\/)(.*)\.png$/i.exec(fn);
4490
4490
  if (!m)
@@ -5059,6 +5059,12 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5059
5059
  const docsRoot = nodeutil.targetDir;
5060
5060
  const docsTemplate = server.expandDocFileTemplate("docs.html");
5061
5061
  pxt.log(`checking docs`);
5062
+ const ignoredFoldersKey = ".checkdocs-ignore";
5063
+ const ignoredFolders = nodeutil.allFiles("docs", { includeHiddenFiles: true })
5064
+ .filter(el => el.endsWith(ignoredFoldersKey))
5065
+ .map(el => path.dirname(path.join(el.substring(4))) + path.sep);
5066
+ if (ignoredFolders.length)
5067
+ pxt.log(`Ignoring folders [${ignoredFolders.join(", ")}]`);
5062
5068
  const noTOCs = [];
5063
5069
  const todo = [];
5064
5070
  let urls = {};
@@ -5067,12 +5073,12 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5067
5073
  // only check each snippet once.
5068
5074
  const existingSnippets = {};
5069
5075
  let snippets = [];
5070
- const maxFileSize = checkFileSize(nodeutil.allFiles("docs", 10, true, true, ".ignorelargefiles"));
5076
+ const maxFileSize = checkFileSize(nodeutil.allFiles("docs", { maxDepth: 10, allowMissing: true, includeDirs: true, ignoredFileMarker: ".ignorelargefiles" }));
5071
5077
  if (!pxt.appTarget.ignoreDocsErrors
5072
5078
  && maxFileSize > (pxt.appTarget.cloud.maxFileSize || (5000000)))
5073
5079
  U.userError(`files too big in docs folder`);
5074
5080
  // scan and fix image links
5075
- nodeutil.allFiles("docs")
5081
+ nodeutil.allFiles("docs", { ignoredFileMarker: ignoredFoldersKey })
5076
5082
  .filter(f => /\.md/.test(f))
5077
5083
  .forEach(f => {
5078
5084
  let md = fs.readFileSync(f, { encoding: "utf8" });
@@ -5127,6 +5133,9 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5127
5133
  urls[url] = isResource
5128
5134
  ? nodeutil.fileExistsSync(path.join(docsRoot, "docs", url))
5129
5135
  : nodeutil.resolveMd(docsRoot, url);
5136
+ const pathedUrl = path.join(url);
5137
+ if (ignoredFolders.some(el => pathedUrl.startsWith(el)))
5138
+ return;
5130
5139
  if (!isResource && urls[url])
5131
5140
  todo.push(url);
5132
5141
  }
@@ -5144,7 +5153,8 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5144
5153
  entry.subitems.forEach(checkTOCEntry);
5145
5154
  }
5146
5155
  // check over TOCs
5147
- nodeutil.allFiles("docs", 5).filter(f => /SUMMARY\.md$/.test(f))
5156
+ nodeutil.allFiles("docs", { maxDepth: 5, ignoredFileMarker: ignoredFoldersKey })
5157
+ .filter(f => /SUMMARY\.md$/.test(f))
5148
5158
  .forEach(summaryFile => {
5149
5159
  const summaryPath = path.join(path.dirname(summaryFile), 'SUMMARY').replace(/^docs[\/\\]/, '');
5150
5160
  pxt.log(`looking for ${summaryPath}`);
@@ -5182,7 +5192,8 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5182
5192
  if (targetDirs) {
5183
5193
  targetDirs.forEach(dir => {
5184
5194
  pxt.log(`looking for markdown files in ${dir}`);
5185
- nodeutil.allFiles(path.join("docs", dir), 3).filter(f => mdRegex.test(f))
5195
+ nodeutil.allFiles(path.join("docs", dir), { maxDepth: 3, ignoredFileMarker: ".checkdocs-ignore" })
5196
+ .filter(f => mdRegex.test(f))
5186
5197
  .forEach(md => {
5187
5198
  pushUrl(md.slice(5).replace(mdRegex, ""), true);
5188
5199
  });
@@ -5259,6 +5270,9 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5259
5270
  card.otherActions.forEach(a => { if (a.url)
5260
5271
  urls.push(a.url); });
5261
5272
  for (let url of urls) {
5273
+ const pathedUrl = path.join(url);
5274
+ if (ignoredFolders.some(el => pathedUrl.startsWith(el)))
5275
+ return;
5262
5276
  const tutorialMd = nodeutil.resolveMd(docsRoot, url);
5263
5277
  if (!tutorialMd) {
5264
5278
  pxt.log(`unable to resolve ${url}`);
@@ -5308,6 +5322,9 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5308
5322
  card.otherActions.forEach(a => { if (a.url)
5309
5323
  urls.push(a.url); });
5310
5324
  for (let url of urls) {
5325
+ const pathedUrl = path.join(url);
5326
+ if (ignoredFolders.some(el => pathedUrl.startsWith(el)))
5327
+ return;
5311
5328
  const exMd = nodeutil.resolveMd(docsRoot, url);
5312
5329
  if (!exMd) {
5313
5330
  pxt.log(`unable to resolve ${url}`);
@@ -5357,7 +5374,7 @@ function internalCheckDocsAsync(compileSnippets, re, fix, pycheck) {
5357
5374
  async function upgradeCardsAsync() {
5358
5375
  const docsRoot = nodeutil.targetDir;
5359
5376
  // markdowns with cards
5360
- const mds = nodeutil.allFiles(docsRoot, 10, false, false)
5377
+ const mds = nodeutil.allFiles(docsRoot, { maxDepth: 10 })
5361
5378
  .filter(fn => /\.md$/.test(fn))
5362
5379
  .map(fn => ({ filename: fn, content: nodeutil.readText(fn) }))
5363
5380
  .filter(f => /```codecard/.test(f.content));
@@ -5385,7 +5402,7 @@ function internalCacheUsedBlocksAsync() {
5385
5402
  if (targetDirs) {
5386
5403
  targetDirs.forEach(dir => {
5387
5404
  pxt.log(`looking for tutorial markdown in ${dir}`);
5388
- nodeutil.allFiles(path.join("docs", dir), 3).filter(f => mdRegex.test(f))
5405
+ nodeutil.allFiles(path.join("docs", dir), { maxDepth: 3 }).filter(f => mdRegex.test(f))
5389
5406
  .forEach(md => {
5390
5407
  mdPaths.push(md.slice(5).replace(mdRegex, ""));
5391
5408
  });
@@ -5564,7 +5581,7 @@ function webstringsJson() {
5564
5581
  }
5565
5582
  function extractLocStringsAsync(output, dirs) {
5566
5583
  let prereqs = [];
5567
- dirs.forEach(dir => prereqs = prereqs.concat(nodeutil.allFiles(dir, 20)));
5584
+ dirs.forEach(dir => prereqs = prereqs.concat(nodeutil.allFiles(dir, { maxDepth: 20 })));
5568
5585
  let errCnt = 0;
5569
5586
  let translationStrings = {};
5570
5587
  function processLf(filename) {
@@ -43,7 +43,14 @@ export declare function pathToPtr(path: string): string;
43
43
  export declare function mkdirP(thePath: string): void;
44
44
  export declare function cpR(src: string, dst: string, maxDepth?: number): void;
45
45
  export declare function cp(srcFile: string, destDirectory: string, destName?: string): void;
46
- export declare function allFiles(top: string, maxDepth?: number, allowMissing?: boolean, includeDirs?: boolean, ignoredFileMarker?: string): string[];
46
+ interface AllFilesOpts {
47
+ maxDepth?: number;
48
+ allowMissing?: boolean;
49
+ includeDirs?: boolean;
50
+ ignoredFileMarker?: string;
51
+ includeHiddenFiles?: boolean;
52
+ }
53
+ export declare function allFiles(top: string, opts?: AllFilesOpts): string[];
47
54
  export declare function existsDirSync(name: string): boolean;
48
55
  export declare function writeFileSync(p: string, data: any, options?: {
49
56
  encoding?: string | null;
@@ -58,3 +65,4 @@ export declare function getBundledPackagesDocs(): string[];
58
65
  export declare function lazyDependencies(): pxt.Map<string>;
59
66
  export declare function lazyRequire(name: string, install?: boolean): any;
60
67
  export declare function stringify(content: any): string;
68
+ export {};
package/built/nodeutil.js CHANGED
@@ -313,7 +313,7 @@ function mkdirP(thePath) {
313
313
  exports.mkdirP = mkdirP;
314
314
  function cpR(src, dst, maxDepth = 8) {
315
315
  src = path.resolve(src);
316
- let files = allFiles(src, maxDepth);
316
+ let files = allFiles(src, { maxDepth });
317
317
  let dirs = {};
318
318
  for (let f of files) {
319
319
  let bn = f.slice(src.length);
@@ -335,12 +335,13 @@ function cp(srcFile, destDirectory, destName) {
335
335
  fs.writeFileSync(dest, buf);
336
336
  }
337
337
  exports.cp = cp;
338
- function allFiles(top, maxDepth = 8, allowMissing = false, includeDirs = false, ignoredFileMarker = undefined) {
338
+ function allFiles(top, opts = {}) {
339
+ const { maxDepth, allowMissing, includeDirs, ignoredFileMarker, includeHiddenFiles } = Object.assign({ maxDepth: 8 }, opts);
339
340
  let res = [];
340
341
  if (allowMissing && !existsDirSync(top))
341
342
  return res;
342
343
  for (const p of fs.readdirSync(top)) {
343
- if (p[0] == ".")
344
+ if (p[0] == "." && !includeHiddenFiles)
344
345
  continue;
345
346
  const inner = path.join(top, p);
346
347
  const st = fs.statSync(inner);
@@ -349,7 +350,7 @@ function allFiles(top, maxDepth = 8, allowMissing = false, includeDirs = false,
349
350
  if (ignoredFileMarker && fs.existsSync(path.join(inner, ignoredFileMarker)))
350
351
  continue;
351
352
  if (maxDepth > 1)
352
- Util.pushRange(res, allFiles(inner, maxDepth - 1));
353
+ Util.pushRange(res, allFiles(inner, Object.assign(Object.assign({}, opts), { maxDepth: maxDepth - 1 })));
353
354
  if (includeDirs)
354
355
  res.push(inner);
355
356
  }