mirror of https://github.com/webpack/webpack.git
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
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
Author Tobias Koppers @sokra
|
Author Tobias Koppers @sokra
|
||||||
*/
|
*/
|
||||||
var cp = require("child_process");
|
"use strict";
|
||||||
var tc = require("./template-common");
|
|
||||||
var fs = require("fs");
|
|
||||||
|
|
||||||
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";
|
const extraArgs = "";
|
||||||
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 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)
|
if(stderr)
|
||||||
console.log(stderr);
|
console.log(stderr);
|
||||||
if(error !== null)
|
if(error !== null)
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
let readme;
|
||||||
try {
|
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) {
|
} catch(e) {
|
||||||
console.log(stderr);
|
console.log(stderr);
|
||||||
throw e;
|
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);
|
console.log(stdout);
|
||||||
if(stderr)
|
if(stderr)
|
||||||
console.log(stderr);
|
console.log(stderr);
|
||||||
|
|
|
@ -1,27 +1,15 @@
|
||||||
var cp = require('child_process');
|
"use strict";
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
|
|
||||||
var cmds = fs.readdirSync(__dirname).filter(function(dirname) {
|
const cp = require("child_process");
|
||||||
return fs.statSync(path.join(__dirname, dirname)).isDirectory() && dirname !== "node_modules";
|
const examples = require("./examples");
|
||||||
}).sort().map(function(dirname) {
|
|
||||||
|
const cmds = examples.map(function(dirname) {
|
||||||
return "cd " + dirname + " && node build.js";
|
return "cd " + dirname + " && node build.js";
|
||||||
});
|
});
|
||||||
|
|
||||||
var stack = function() {
|
let i = 0;
|
||||||
console.log("done");
|
for(const cmd of cmds.reverse()) {
|
||||||
};
|
console.log(`[${++i}/${cmds.length}] ${cmd}`);
|
||||||
for(var i = cmds.length-1; i >= 0; i--) {
|
cp.execSync(cmd, { encoding: "utf-8" });
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
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("../");
|
const webpack = require("../");
|
||||||
|
|
||||||
describe("Examples", () => {
|
describe("Examples", () => {
|
||||||
const examples = fs.readdirSync(path.join(__dirname, "..", "examples")).map((name) =>
|
const basePath = path.join(__dirname, "..", "examples");
|
||||||
path.join(__dirname, "..", "examples", name)).filter((p) =>
|
const examples = require("../examples/examples.js");
|
||||||
fs.statSync(p).isDirectory() && fs.existsSync(path.join(p, "build.js")));
|
|
||||||
|
|
||||||
examples.forEach((examplePath) => {
|
examples.forEach((examplePath) => {
|
||||||
it("should compile " + path.basename(examplePath), function(done) {
|
it("should compile " + path.relative(basePath, examplePath), function(done) {
|
||||||
this.timeout(20000);
|
this.timeout(20000);
|
||||||
let options = {};
|
let options = {};
|
||||||
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
|
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
|
||||||
|
|
Loading…
Reference in New Issue