forked from qooxdoo/qooxdoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
248 lines (233 loc) · 7.3 KB
/
compile.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
const path = require("path");
const fs = require("fs");
qx.Class.define("qx.compiler.CompilerApi", {
extend: qx.tool.cli.api.CompilerApi,
members: {
async load() {
let yargs = qx.tool.cli.commands.Test.getYargsCommand;
qx.tool.cli.commands.Test.getYargsCommand = () => {
let args = yargs();
args.builder.diag = {
describe: "show diagnostic output",
type: "boolean",
default: false
};
args.builder.terse = {
describe: "show only summary and errors",
type: "boolean",
default: false
};
args.builder.headless = {
describe: "runs test headless",
type: "boolean",
default: false,
};
args.builder.browsers = {
describe:
"list of browsers to test against, currently supported chromium, firefox, webkit, none (=node tests only)",
type: "string"
};
return args;
};
this.addListener(
"changeCommand",
function () {
let command = this.getCommand();
if (command instanceof qx.tool.cli.commands.package.Publish) {
command.addListener("beforeCommit", this.__fixDocVersion, this);
}
},
this
);
let data = await this.base(arguments);
if (!data.environment) data.environment = {};
let manifestConfig = await qx.tool.config.Manifest.getInstance().load();
let manifestData = manifestConfig.getData();
data.environment["qx.compiler.version"] = manifestData.info.version;
return data;
},
async __fixDocVersion(evt) {
const data = evt.getData();
const vars = path.join(process.cwd(), "docs", "_variables.json");
if (await fs.existsAsync(vars)) {
let var_data = await qx.tool.utils.Json.loadJsonAsync(vars);
var_data.qooxdoo.version = data.version;
if (data.argv.dryrun) {
qx.tool.compiler.Console.info(
"Dry run: Not changing _variables.json version..."
);
} else {
await qx.tool.utils.Json.saveJsonAsync(vars, var_data);
if (!data.argv.quiet) {
qx.tool.compiler.Console.info(
`Updated version in _variables.json.`
);
}
}
}
},
/**
* runs after the whole process is finished
* @param cmd {qx.tool.cli.commands.Command} current command
* @param res {boolean} result of the just finished process
*/
async afterProcessFinished(cmd, res) {
if (res) {
return;
}
if (cmd.classname !== "qx.tool.cli.commands.package.Publish") {
return;
}
// token
let cfg = await qx.tool.cli.ConfigDb.getInstance();
let npm = cfg.db("npm", {});
if (!npm.token) {
// call require("inquirer") here - not in the head.
// otherwise it will be called during initialization.
// that does not work if you use qooxdoo as package
const inquirer = require("inquirer");
let response = await inquirer.prompt([
{
type: "input",
name: "token",
message:
"Publishing to npm requires an access token - visit https://www.npmjs.com/settings/tokens to obtain one " +
"(you must assign permission to publish);\nWhat is your npm acess Token ? "
}
]);
if (!response.token) {
qx.tool.compiler.Console.error("You have not provided a npm token.");
return;
}
npm.token = response.token;
cfg.save();
}
let token = npm.token;
if (!token) {
throw new qx.tool.utils.Utils.UserError(`npm access token required.`);
}
let args = ["publish", "--access public"];
if (cmd.argv.dryrun) {
args.push("--dry-run");
}
if (cmd.argv.prerelease) {
args.push("--tag beta");
}
let env = process.env;
// for use of INPUT_TOKEN see:
// https://github.com/JS-DevTools/npm-publish/blob/master/src/npm.ts
// https://github.com/JS-DevTools/npm-publish/blob/0f451a94170d1699fd50710966d48fb26194d939/src/npm-env.ts#L6
env.INPUT_TOKEN = token;
if (cmd.argv.verbose) {
this.info(`run npm with ${args}`);
}
await qx.tool.utils.Utils.runCommand({
cwd: ".",
cmd: "npm",
args: args,
env: env,
log: console.log,
error: console.log
});
},
/**
* Register compiler tests
* @param {qx.tool.cli.commands.Command} command
* @return {Promise<void>}
*/
async beforeTests(command) {
const that = this;
command.addTest(
new qx.tool.cli.api.Test("lint", async function () {
console.log("# ********* running lint ");
this.setFailFast(true);
result = await qx.tool.utils.Utils.runCommand({
cwd: ".",
cmd: "node",
args: [
path.join(
__dirname,
"bin",
command.getTargetType(),
"qx"
),
"lint",
"--warnAsError"
],
shell: true,
log: console.log,
error: console.log
});
if (result.exitCode === 0) {
qx.tool.compiler.Console.log("ok");
} else {
qx.tool.compiler.Console.log("not ok");
}
this.setExitCode(result.exitCode);
})
);
let argList = [
"colorize",
"verbose",
"quiet",
"fail-fast",
"diag",
"terse"
];
command.addTest(
new qx.tool.cli.api.Test("compiler test", async function () {
qx.tool.compiler.Console.log("# ******** running compiler test");
let args = argList;
let curArgs = that.__getArgs(command, args);
if (command.argv.verbose) {
console.log(curArgs);
}
result = await qx.tool.utils.Utils.runCommand({
cwd: "test/tool",
cmd: "node",
args: curArgs
});
this.setExitCode(result.exitCode);
})
);
if (command.argv["browsers"] != "none") {
command.addTest(
new qx.tool.cli.api.Test("framework test", async function () {
console.log("# ******** running framework test");
this.setFailFast(true);
let args = argList.slice();
args.push("browsers");
args.push("headless");
let curArgs = that.__getArgs(command, args);
curArgs.push("--fail-fast");
if (command.argv.verbose) {
console.log(curArgs);
}
result = await qx.tool.utils.Utils.runCommand({
cwd: "test/framework",
cmd: "node",
args: curArgs
});
this.setExitCode(result.exitCode);
})
);
}
},
__getArgs(command, argList) {
let res = [];
res.push(
path.join(__dirname, "bin", command.getTargetType(), "qx")
);
res.push("test");
for (const arg of argList) {
if (command.argv[arg]) {
res.push(` --${arg}=${command.argv[arg]}`);
}
}
return res;
}
}
});
module.exports = {
CompilerApi: qx.compiler.CompilerApi
};