Refactor example scripts and test to allow nested folders
This commit is contained in:
parent
ed50812a6c
commit
d411468639
|
@ -2,26 +2,30 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var cp = require("child_process");
|
||||
var tc = require("./template-common");
|
||||
var fs = require("fs");
|
||||
"use strict";
|
||||
|
||||
var extraArgs = "";
|
||||
const cp = require("child_process");
|
||||
const path = require("path");
|
||||
const tc = require("./template-common");
|
||||
const fs = require("fs");
|
||||
|
||||
var targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
|
||||
var displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports";
|
||||
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path \"js/\" -p " + extraArgs + targetArgs, function(error, stdout, stderr) {
|
||||
const extraArgs = "";
|
||||
|
||||
const targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
|
||||
const displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports";
|
||||
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
|
||||
if(stderr)
|
||||
console.log(stderr);
|
||||
if(error !== null)
|
||||
console.log(error);
|
||||
let readme;
|
||||
try {
|
||||
var readme = tc.replaceResults(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
|
||||
readme = tc.replaceResults(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
|
||||
} catch(e) {
|
||||
console.log(stderr);
|
||||
throw e;
|
||||
}
|
||||
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path \"js/\" --output-pathinfo " + extraArgs + targetArgs, function(error, stdout, stderr) {
|
||||
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
if(stderr)
|
||||
console.log(stderr);
|
||||
|
|
|
@ -1,27 +1,15 @@
|
|||
var cp = require('child_process');
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
"use strict";
|
||||
|
||||
var cmds = fs.readdirSync(__dirname).filter(function(dirname) {
|
||||
return fs.statSync(path.join(__dirname, dirname)).isDirectory() && dirname !== "node_modules";
|
||||
}).sort().map(function(dirname) {
|
||||
const cp = require("child_process");
|
||||
const examples = require("./examples");
|
||||
|
||||
const cmds = examples.map(function(dirname) {
|
||||
return "cd " + dirname + " && node build.js";
|
||||
});
|
||||
|
||||
var stack = function() {
|
||||
console.log("done");
|
||||
};
|
||||
for(var i = cmds.length-1; i >= 0; i--) {
|
||||
var cmd = cmds[i];
|
||||
stack = (function(next, cmd) {
|
||||
return function() {
|
||||
console.log(cmd);
|
||||
cp.exec(cmd, function(error, stdout, stderr) {
|
||||
if(error) console.error(error);
|
||||
else if(stderr) console.error(stderr), next();
|
||||
else next();
|
||||
});
|
||||
}
|
||||
}(stack, cmd));
|
||||
let i = 0;
|
||||
for(const cmd of cmds.reverse()) {
|
||||
console.log(`[${++i}/${cmds.length}] ${cmd}`);
|
||||
cp.execSync(cmd, { encoding: "utf-8" });
|
||||
}
|
||||
stack();
|
||||
console.log("done");
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
function findInFolder(folder, depth) {
|
||||
if(fs.existsSync(path.join(folder, "template.md"))) {
|
||||
return [folder];
|
||||
} else if(depth > 0) {
|
||||
const files = fs.readdirSync(folder);
|
||||
const results = [];
|
||||
for(const file of files) {
|
||||
const innerPath = path.join(folder, file);
|
||||
if(fs.statSync(innerPath).isDirectory()) {
|
||||
const innerResult = findInFolder(innerPath, depth - 1);
|
||||
for(const item of innerResult)
|
||||
results.push(item);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = findInFolder(__dirname, 2).sort();
|
|
@ -7,12 +7,11 @@ const fs = require("fs");
|
|||
const webpack = require("../");
|
||||
|
||||
describe("Examples", () => {
|
||||
const examples = fs.readdirSync(path.join(__dirname, "..", "examples")).map((name) =>
|
||||
path.join(__dirname, "..", "examples", name)).filter((p) =>
|
||||
fs.statSync(p).isDirectory() && fs.existsSync(path.join(p, "build.js")));
|
||||
const basePath = path.join(__dirname, "..", "examples");
|
||||
const examples = require("../examples/examples.js");
|
||||
|
||||
examples.forEach((examplePath) => {
|
||||
it("should compile " + path.basename(examplePath), function(done) {
|
||||
it("should compile " + path.relative(basePath, examplePath), function(done) {
|
||||
this.timeout(20000);
|
||||
let options = {};
|
||||
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
|
||||
|
|
Loading…
Reference in New Issue