forked from electrode-io/electrode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xrun-tasks.js
208 lines (181 loc) · 5.51 KB
/
xrun-tasks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"use strict";
const xrun = require("@xarc/run");
const xsh = require("xsh");
const shell = xsh.$;
const exec = xsh.exec;
const fs = require("fs");
const Path = require("path");
const _ = require("lodash");
const { spawn } = require("child_process");
const packagesDir = Path.join(__dirname, "packages");
const removeNpmScope = (name) => {
if (name.startsWith("@")) {
const parts = name.split("/");
if (parts.length === 2) {
if (parts[1] === "create-app") {
return parts[1];
}
return parts[0].substr(1) + "-" + parts[1];
}
}
return name;
};
const pullLocalPackages = (dir) => {
dir = Path.isAbsolute(dir) ? dir : Path.join(__dirname, dir);
const localPkgs = [
"@xarc/app",
"electrode-react-webapp",
"electrode-redux-router-engine",
"electrode-auto-ssr",
"electrode-cookies",
"electrode-ui-config",
"subapp-redux",
"subapp-server",
"subapp-web",
];
const localDevPkgs = ["@xarc/app-dev"];
const localPackagesDir = Path.relative(dir, packagesDir);
const appPkgFile = Path.join(dir, "package.json");
const appPkgData = fs.readFileSync(appPkgFile).toString();
const appPkg = JSON.parse(appPkgData);
const updateToLocalPkgs = (section, pkgs) => {
if (appPkg[section]) {
pkgs.forEach((pkg) => {
if (appPkg[section][pkg]) {
_.set(
appPkg,
["fyn", section, pkg],
Path.join(localPackagesDir, removeNpmScope(pkg)).replace(/\\/g, "/")
);
}
});
}
};
updateToLocalPkgs("dependencies", localPkgs);
updateToLocalPkgs("devDependencies", localDevPkgs);
fs.writeFileSync(appPkgFile, `${JSON.stringify(appPkg, null, 2)}\n`);
return appPkgData;
};
const runAppTest = (dir, forceLocal) => {
return new Promise((resolve, reject) => {
const child = spawn(
`fyn`,
`--pg simple -q=v i --run-npm build test --sl fyn-ci-${process.pid}.log`.split(" "),
{
cwd: dir,
// somehow the stdout from fyn got chopped off by node.js, and the only way to
// get them all is let spawn pipe the output directly to parent stdout
stdio: [null, process.stdout, process.stderr],
}
);
child.on("close", (code) => {
if (code) {
reject(new Error(`Failed runAppTest for app at ${dir} - fyn exit code ${code}`));
} else {
resolve();
}
});
});
};
const testCreateApp = async (testDir, name, clean, runTest, prompts) => {
name = name || "my-app";
const testAppDir = Path.join(testDir, name);
if (!clean) {
shell.mkdir("-p", testAppDir);
}
shell.pushd(testAppDir);
await require("./packages/create-app/src/create")();
shell.popd();
};
xrun.load("user", {
".lerna.check": "~$lerna run --stream check",
bootstrap: "~$fynpo",
test: ["bootstrap", ".lerna.check", "build-test"],
"test-create-app": [".test-create-app"],
"test-boilerplate": [".test-boilerplate"],
"test-stylus-sample": [".test-stylus-sample"],
"update-changelog": ["~$node tools/update-changelog.js"],
"build-test": {
desc: "Run CI test",
task: () => {
process.env.BUILD_TEST = "true";
// process.env.NODE_PRESERVE_SYMLINKS = "1";
const tasks = [
// "test-boilerplate", // TODO: webpack 5
"test-stylus-sample",
".test-jest-sample",
];
let updated;
return exec("lerna updated")
.then((output) => {
updated = output.stdout
.split("\n")
.filter((x) => x.startsWith("- "))
.map((x) => x.substr(2));
const updatedStr = updated.join(" ");
if (updatedStr.indexOf("@xarc/app") >= 0) {
tasks.push(".build-react-component", ".test-tree-shaking");
}
return xrun.serial(tasks);
})
.catch((err) => {
if (!err.output.stderr.includes("No changed packages found")) {
throw err;
}
});
},
},
".build-sample-dll": () => {
return runAppTest(Path.join(__dirname, "samples/react-vendor-dll"));
},
".build-react-component": () => {
return runAppTest(Path.join(__dirname, "samples/react-component"));
},
".test-boilerplate": {
desc: "Run tests for the boilerplage app universal-react-node",
dep: [".build-sample-dll"],
task: () => {
return runAppTest(Path.join(__dirname, "samples/universal-react-node"));
},
},
".test-tree-shaking": {
desc: "Run tests for the demo-tree-shaking sample app",
task: () => {
return runAppTest(Path.join(__dirname, "samples/demo-tree-shaking"));
},
},
".test-stylus-sample": {
desc: "Run tests for the boilerplage app stylus-sample",
task: () => {
return runAppTest(Path.join(__dirname, "samples/stylus-sample"));
},
},
".test-jest-sample": {
desc: "Run tests for the boilerplage app react-jest-app",
task: () => {
return runAppTest(Path.join(__dirname, "samples/react-jest-app"));
},
},
"samples-local": {
desc: "modify all samples to pull electrode packages from local",
task: () => {
[
"electrode-demo-index",
"stylus-sample",
"universal-material-ui",
"universal-react-node",
"react-jest-app",
].forEach((a) => {
pullLocalPackages(Path.join(__dirname, "samples", a));
});
},
},
".test-create-app": {
async task() {
const testDir = Path.join(__dirname, "tmp");
await testCreateApp(testDir, "my-app");
const testAppDir = Path.join(testDir, "my-app");
pullLocalPackages(testAppDir);
},
},
});