getDirectories: (dir) => fs.readdirSync(dir),
.then(() => oldNumberOfFiles = readdirSync('dist').length)
export function getFiles(srcpath: string): string[] { return fs.readdirSync(srcpath).filter(function (file: string) { return fs.statSync(path.join(srcpath, file)).isFile(); }); }
export default function start(serverDataPath: string) { dataPath = serverDataPath; SupCore.log(`Using data from ${dataPath}.`); process.on("uncaughtException", onUncaughtException); loadConfig(); const { version, superpowers: { appApiVersion: appApiVersion } } = JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, { encoding: "utf8" })); SupCore.log(`Server v${version} starting...`); fs.writeFileSync(`${__dirname}/../public/superpowers.json`, JSON.stringify({ version, appApiVersion, hasPassword: config.server.password.length !== 0 }, null, 2)); // SupCore (global as any).SupCore = SupCore; SupCore.systemsPath = path.join(dataPath, "systems"); // List available languages languageIds = fs.readdirSync(`${__dirname}/../public/locales`); languageIds.unshift("none"); // Main HTTP server mainApp = express(); mainApp.use(cookieParser()); mainApp.use(handleLanguage); mainApp.get("/", (req, res) => { res.redirect("/hub"); }); mainApp.get("/login", serveLoginIndex); mainApp.get("/hub", enforceAuth, serveHubIndex); mainApp.get("/project", enforceAuth, serveProjectIndex); mainApp.use("/projects/:projectId/*", serveProjectWildcard); mainApp.use("/", express.static(`${__dirname}/../public`)); mainHttpServer = http.createServer(mainApp); mainHttpServer.on("error", onHttpServerError.bind(null, config.server.mainPort)); io = socketio(mainHttpServer, { transports: [ "websocket" ] }); // Build HTTP server buildApp = express(); buildApp.get("/", redirectToHub); buildApp.get("/systems/:systemId/SupCore.js", serveSystemSupCore); buildApp.use("/", express.static(`${__dirname}/../public`)); buildApp.get("/builds/:projectId/:buildId/*", (req, res) => { const projectServer = hub.serversById[req.params.projectId]; if (projectServer == null) { res.status(404).end("No such project"); return; } let buildId = req.params.buildId as string; if (buildId === "latest") buildId = (projectServer.nextBuildId - 1).toString(); res.sendFile(path.join(projectServer.buildsPath, buildId, req.params[0])); }); buildHttpServer = http.createServer(buildApp); buildHttpServer.on("error", onHttpServerError.bind(null, config.server.buildPort)); loadSystems(mainApp, buildApp, onSystemsLoaded); // Save on exit and handle crashes process.on("SIGINT", onExit); process.on("message", (msg: string) => { if (msg === "stop") onExit(); }); }
const createDTS = () => { const header = `// // Autogenerated from scripts/danger-dts.ts // import * as GitHub from "github" declare module "danger" { ` const footer = `} ` let fileOutput = "" const extras = ["source/platforms/messaging/violation.ts"] const dslFiles = fs.readdirSync("source/dsl").map(f => `source/dsl/${f}`) dslFiles.concat(extras).forEach(file => { // Sometimes they have more stuff, in those cases // offer a way to crop the file. const content = fs.readFileSync(file).toString() if (content.includes("/// End of Danger DSL definition")) { fileOutput += content.split("/// End of Danger DSL definition")[0] } else { fileOutput += content } fileOutput += "\n" }) // The definition of all the exposed vars is inside // the Dangerfile.js file. const allDangerfile = fs.readFileSync("source/runner/Dangerfile.ts").toString() const moduleContext = allDangerfile .split("/// Start of Danger DSL definition")[1] .split("/// End of Danger DSL definition")[0] // we need to add either `declare function` or `declare var` to the interface const context = mapLines(moduleContext, (line: string) => { if (line.length === 0 || line.includes("*")) { const newLine = line.trim() // Make sure TSLint passes if (newLine.startsWith("*")) { return " " + newLine } return newLine } if (line.includes("export type")) { return line } if (line.includes("(")) { return "function " + line.trim() } if (line.includes(":")) { return "const " + line.trim() } return "" }) fileOutput += context // Remove all JS-y bits fileOutput = fileOutput .split("\n") .filter(line => { return !line.startsWith("import") && !line.includes("* @type ") }) .join("\n") const trimmedWhitespaceLines = fileOutput.replace(/\n\s*\n\s*\n/g, "\n") const noRedundantExports = trimmedWhitespaceLines .replace(/export interface/g, "interface") .replace(/export type/g, "type") const indentedBody = mapLines(noRedundantExports, line => (line.length ? ` ${line}` : "")) return header + indentedBody + footer }
function getDirectories(path: string): string[] { return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory)); }
const getDirectories = (source: any) => readdirSync(source).map(name => join(source, name)).filter(isDirectory);
.then(() => { const main = readdirSync('./dist').find(name => !!name.match(/main.[a-z0-9]+\.bundle\.js/)); expectFileToMatch(`dist/${main}`, /bootstrapModuleFactory\(/); })
return service.copyFile(source.resource, target, true).then(res => { // CONWAY.js => conway.js assert.equal(fs.existsSync(res.resource.fsPath), true); assert.ok(fs.readdirSync(testDir).some(f => f === 'conway.js')); });
async function readFilesOrURLsInDirectory(d: string): Promise<TypeSource[]> { const files = fs .readdirSync(d) .map(x => path.join(d, x)) .filter(x => fs.lstatSync(x).isFile()); // Each file is a (Name, JSON | URL) const sourcesInDir: TypeSource[] = []; const graphQLSources: GraphQLTypeSource[] = []; let graphQLSchema: Readable | undefined = undefined; let graphQLSchemaFileName: string | undefined = undefined; for (let file of files) { const name = typeNameFromFilename(file); let fileOrUrl = file; file = file.toLowerCase(); // If file is a URL string, download it if (file.endsWith(".url")) { fileOrUrl = fs.readFileSync(file, "utf8").trim(); } if (file.endsWith(".url") || file.endsWith(".json")) { sourcesInDir.push({ kind: "json", name, samples: [await readableFromFileOrURL(fileOrUrl)] }); } else if (file.endsWith(".schema")) { sourcesInDir.push({ kind: "schema", name, uris: [fileOrUrl] }); } else if (file.endsWith(".gqlschema")) { messageAssert(graphQLSchema === undefined, "DriverMoreThanOneGraphQLSchemaInDir", { dir: dataDir }); graphQLSchema = await readableFromFileOrURL(fileOrUrl); graphQLSchemaFileName = fileOrUrl; } else if (file.endsWith(".graphql")) { graphQLSources.push({ kind: "graphql", name, schema: undefined, query: await getStream(await readableFromFileOrURL(fileOrUrl)) }); } } if (graphQLSources.length > 0) { if (graphQLSchema === undefined) { return messageError("DriverNoGraphQLSchemaInDir", { dir: dataDir }); } const schema = parseJSON(await getStream(graphQLSchema), "GraphQL schema", graphQLSchemaFileName); for (const source of graphQLSources) { source.schema = schema; sourcesInDir.push(source); } } return sourcesInDir; }