Skip to content

Instantly share code, notes, and snippets.

@truongsinh
Created January 10, 2019 04:29
Show Gist options
  • Save truongsinh/49aaf7c1e5e7c681134920733b77971b to your computer and use it in GitHub Desktop.
Save truongsinh/49aaf7c1e5e7c681134920733b77971b to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const dest = __dirname + "/../packages/";
const { readdir, writeFile, exists, mkdir } = require("fs");
const { promisify } = require("util");
const [readDirAsync, writeFileAsync, existsAsync, mkdirAsync] = [
promisify(readdir),
promisify(writeFile),
promisify(exists),
promisify(mkdir)
];
var shell = require("shelljs");
class Lazy {
constructor(iterable, callback) {
this.iterable = iterable;
this.callback = callback;
}
filter(callback) {
return new LazyFilter(this, callback);
}
map(callback) {
return new LazyMap(this, callback);
}
next() {
return this.iterable.next();
}
take(n) {
const values = [];
for (let i = 0; i < n; i++) {
values.push(this.next().value);
}
return values;
}
}
class LazyFilter extends Lazy {
next() {
while (true) {
const item = this.iterable.next();
if (this.callback(item.value)) {
return item;
}
}
}
}
class LazyMap extends Lazy {
next() {
const item = this.iterable.next();
const mappedValue = this.callback(item.value);
return { value: mappedValue, done: item.done };
}
}
const main = async () => {
const dirList = await readDirAsync(dest);
const dirListGenerator = new Lazy(
(function*() {
for (let i = 0; i < dirList.length; i++) {
yield dirList[i];
}
})()
);
dirList
// dirListGenerator
.map(async dirName => {
if (!dirName) {
return;
}
const packageName = dirName.replace(/_/g, "");
try {
const androidTestPath =
__dirname +
"/../packages/" +
dirName +
"/android/src/test/java/io/flutter/plugins/" +
packageName;
if (!(await existsAsync(androidTestPath))) {
shell.mkdir("-p", androidTestPath);
}
let dirContent = await readDirAsync(androidTestPath);
if (dirContent.length !== 0) {
return;
}
const content = `package io.flutter.plugins.${packageName}
import org.junit.Assert.assertNull
import org.junit.Test
class DummyTest {
}
`;
await writeFileAsync(androidTestPath + "/dummy.kt", content);
} catch (e) {
console.log(e);
}
});
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment