diff options
Diffstat (limited to 'cli/scripts')
| -rw-r--r-- | cli/scripts/generate.mjs | 297 | ||||
| -rw-r--r-- | cli/scripts/nginx/.dockerignore | 1 | ||||
| -rw-r--r-- | cli/scripts/nginx/Dockerfile.cacher | 11 | ||||
| -rw-r--r-- | cli/scripts/nginx/docker-compose.yml | 9 | ||||
| -rw-r--r-- | cli/scripts/nginx/nginx.conf | 39 | ||||
| -rw-r--r-- | cli/scripts/npm-native-packages/.gitignore | 1 | ||||
| -rw-r--r-- | cli/scripts/npm-native-packages/npm-native-packages.js | 57 | ||||
| -rw-r--r-- | cli/scripts/npm-native-packages/template/README.md | 3 | ||||
| -rw-r--r-- | cli/scripts/npm-native-packages/template/bin/turbo | 15 | ||||
| -rw-r--r-- | cli/scripts/npm-native-packages/template/template.package.json | 12 | ||||
| -rw-r--r-- | cli/scripts/templates/jest.config.js | 10 | ||||
| -rw-r--r-- | cli/scripts/templates/src/__tests__/index.test.ts | 7 | ||||
| -rw-r--r-- | cli/scripts/templates/src/__tests__/tsconfig.json | 4 | ||||
| -rw-r--r-- | cli/scripts/templates/src/index.ts | 3 | ||||
| -rw-r--r-- | cli/scripts/templates/tsconfig.json | 9 |
15 files changed, 0 insertions, 478 deletions
diff --git a/cli/scripts/generate.mjs b/cli/scripts/generate.mjs deleted file mode 100644 index 1b9cbec..0000000 --- a/cli/scripts/generate.mjs +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env node -import shelljs from "shelljs"; -import path from "path"; -import fs from "fs-extra"; -import faker from "faker"; -import graphGenerator from "ngraph.generators"; -import copy from "copy-template-dir"; -import { fileURLToPath } from "url"; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -faker.seed(123); - -const scope = `@${faker.hacker - .noun() - .toLowerCase() - .replace(/\s/g, "-") - .replace("1080p-", "rando")}`; - -const type = process.argv[2]; - -// TODO: algo should be customizable along with the size -const packageGraph = graphGenerator.complete(5); - -// Generate the package name & versions -packageGraph.forEachNode((node) => { - node.data = { - name: `${scope}/${faker.hacker.adjective()}-${faker.hacker.noun()}` - .toLocaleLowerCase() - .replace(/\s/g, "-"), - version: faker.system.semver(), - }; -}); - -// Generate package dependencies -packageGraph.forEachNode((node) => { - const links = packageGraph.getLinks(node.id); - - if (links) { - for (const link of links) { - if (link.fromId === node.id) { - const depNode = packageGraph.getNode(link.toId); - node.data.dependencies = node.data.dependencies || {}; - node.data.dependencies[depNode.data.name] = `^${depNode.data.version}`; - node.data.implicitDependencies = node.data.implicitDependencies || []; - node.data.implicitDependencies.push( - depNode.data.name.replace(/^@[^/]+\//, "") - ); - } - } - } -}); - -// Generate the monorepo -// 1. the root package.json -// 2. create packages/ -// 3. create package directories -const root = path.join(__dirname, "../demo", type); - -function generate(root, skipInstall) { - fs.mkdirSync(root, { recursive: true }); - if (type !== "nx") { - fs.writeFileSync( - path.join(root, ".gitignore"), - `node_modules -dist -.turbo -out -turbo -turbo-linux -.yalc` - ); - if (fs.existsSync(root)) { - try { - fs.rmSync(root + "/packages", { recursive: true }); - } catch (error) {} - } - - let deps = - type !== "turbo" - ? { - devDependencies: { - [type]: "*", - }, - } - : {}; - - fs.writeFileSync( - path.join(root, "package.json"), - JSON.stringify( - { - name: "monorepo", - version: "0.0.0", - private: true, - workspaces: ["packages/*"], - ...deps, - packageManager: "yarn@1.22.17", - }, - null, - 2 - ) - ); - - fs.writeFileSync( - path.join(root, "tsconfig.json"), - JSON.stringify( - { - compilerOptions: { - composite: false, - declaration: true, - declarationMap: true, - esModuleInterop: true, - forceConsistentCasingInFileNames: true, - inlineSourceMap: true, - inlineSources: false, - isolatedModules: true, - moduleResolution: "node", - noUnusedLocals: false, - noUnusedParameters: false, - preserveWatchOutput: true, - skipLibCheck: true, - strict: true, - lib: ["es2020"], - module: "commonjs", - target: "es2020", - }, - }, - null, - 2 - ) - ); - } - - if (type === "turbo") { - fs.writeFileSync( - path.join(root, "turbo.json"), - JSON.stringify( - { - npmClient: "yarn", - cacheStorageConfig: { - provider: "local", - cacheUrl: "https://1a77600385dd.ngrok.io", - }, - pipeline: { - build: { - outputs: ["dist/**/*"], - dependsOn: ["^build"], - }, - test: { - dependsOn: ["build"], - }, - dev: { - cache: false, - }, - }, - }, - null, - 2 - ) - ); - } - - if (type === "lerna") { - fs.writeFileSync( - path.join(root, "lerna.json"), - JSON.stringify( - { - packages: ["packages/*"], - version: "0.0.0", - }, - null, - 2 - ) - ); - } - - if (type === "lage") { - fs.writeFileSync( - path.join(root, "lage.config.js"), - ` -module.exports = { - pipeline: { - build: ['^build'], - test: ['build'], - lint: [], - }, - npmClient: 'yarn', - cacheOptions: { - cacheStorageConfig: { - provider: 'local', - }, - outputGlob: ['dist/**'], - }, -}; - ` - ); - } - - if (type !== "nx") { - fs.mkdirSync(path.join(root, "packages")); - } else { - shelljs.exec( - `cd ${path.join( - __dirname, - "../demo" - )} && yarn create nx-workspace nx --preset=empty --nx-cloud=false --packageManager=yarn --cli=nx --linter=eslint` - ); - shelljs.exec(`cd ${root} && yarn add @nrwl/node`); - } - - if (type !== "nx") { - packageGraph.forEachNode((node) => { - const packageRoot = path.join( - root, - "packages", - node.data.name.replace(/^@[^/]+\//, "") - ); - fs.mkdirSync(packageRoot, { recursive: true }); - copy( - path.join(__dirname, "templates"), - path.join(packageRoot), - { - name: node.data.name.replace(/^@[^/]+\//, ""), - }, - () => {} - ); - - fs.writeFileSync( - path.join(packageRoot, "package.json"), - JSON.stringify( - { - name: node.data.name, - version: node.data.version, - dependencies: node.data.dependencies, - files: ["dist/**"], - main: "dist/index.js", - types: "dist/index.d.ts", - devDependencies: { - typescript: "^4.6.3", - jest: "^27.0.0", - "ts-jest": "^27.0.0", - "@types/jest": "^27.0.0", - }, - scripts: { - build: "tsc", - dev: "tsc -w", - test: "jest", - }, - }, - null, - 2 - ) - ); - }); - } - - if (type === "nx") { - packageGraph.forEachNode((node) => { - shelljs.exec( - `cd ${root} && yarn nx g @nrwl/node:library --buildable --publishable --name="${node.data.name.replace( - /^@[^/]+\//, - "" - )}" --importPath="${node.data.name.replace(/^@[^/]+\//, "")}"` - ); - // instead of dealing with actual code, just list as implicitDependencies - const safeName = node.data.name.replace(/^@[^/]+\//, ""); - const workspace = fs.readJSONSync(path.join(root, "workspace.json")); - workspace.projects[safeName] = { - ...workspace.projects[safeName], - implicitDependencies: node.data.implicitDependencies || [], - }; - fs.writeFileSync( - path.join(root, "nx.json"), - JSON.stringify(workspace, null, 2) - ); - }); - } - if (!skipInstall) { - shelljs.exec(`cd ${root} && yarn install`); - } - fs.ensureDirSync(path.join(root, ".git")); - fs.writeFileSync( - path.join(root, ".git", "config"), - ` -[user] - name = GitHub Actions - email = actions@users.noreply.github.com -` - ); - shelljs.exec( - `cd ${root} && git init -q && git add . && git commit -m "init"` - ); -} - -generate(root); -if (type === "turbo") { - generate(root + "-installed", true); -} diff --git a/cli/scripts/nginx/.dockerignore b/cli/scripts/nginx/.dockerignore deleted file mode 100644 index 4c8fbef..0000000 --- a/cli/scripts/nginx/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -cacher_root diff --git a/cli/scripts/nginx/Dockerfile.cacher b/cli/scripts/nginx/Dockerfile.cacher deleted file mode 100644 index aedf629..0000000 --- a/cli/scripts/nginx/Dockerfile.cacher +++ /dev/null @@ -1,11 +0,0 @@ -FROM ubuntu:xenial - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - nginx \ - nginx-extras \ - && rm -rf /var/lib/apt/lists/* - -COPY nginx.conf /etc/nginx/nginx.conf - -CMD nginx -g "daemon off;" diff --git a/cli/scripts/nginx/docker-compose.yml b/cli/scripts/nginx/docker-compose.yml deleted file mode 100644 index d93ef16..0000000 --- a/cli/scripts/nginx/docker-compose.yml +++ /dev/null @@ -1,9 +0,0 @@ -services: - cacher: - build: - context: . - dockerfile: Dockerfile.cacher - volumes: - - ./cacher_root:/var/www/cache - ports: - - "7070:7070" diff --git a/cli/scripts/nginx/nginx.conf b/cli/scripts/nginx/nginx.conf deleted file mode 100644 index d56b5c0..0000000 --- a/cli/scripts/nginx/nginx.conf +++ /dev/null @@ -1,39 +0,0 @@ -user root; -worker_processes auto; -pid /run/nginx.pid; - -events { - worker_connections 768; - # multi_accept on; -} - -http { - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - # server_tokens off; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - access_log /dev/stdout; - error_log /dev/stderr; - - gzip on; - gzip_disable "msie6"; - - server { - listen 7070 default_server; - - root /var/www; - - location /v8/artifacts { - dav_methods PUT; - autoindex on; - allow all; - client_max_body_size 512M; - } - } -} diff --git a/cli/scripts/npm-native-packages/.gitignore b/cli/scripts/npm-native-packages/.gitignore deleted file mode 100644 index 84c048a..0000000 --- a/cli/scripts/npm-native-packages/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build/ diff --git a/cli/scripts/npm-native-packages/npm-native-packages.js b/cli/scripts/npm-native-packages/npm-native-packages.js deleted file mode 100644 index 06ab67f..0000000 --- a/cli/scripts/npm-native-packages/npm-native-packages.js +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env node - -const fs = require("fs"); -const path = require("path"); - -// Map to node os and arch names. -const nodeOsLookup = { - darwin: "darwin", - linux: "linux", - windows: "win32", -}; - -const nodeArchLookup = { - amd64: "x64", - arm64: "arm64", -}; - -const humanizedArchLookup = { - amd64: "64", - arm64: "arm64", -}; - -const template = require("./template/template.package.json"); -const os = process.argv[2]; -const arch = process.argv[3]; -const version = process.argv[4]; - -template.name = `turbo-${os}-${humanizedArchLookup[arch]}`; -template.description = `The ${os}-${humanizedArchLookup[arch]} binary for turbo, a monorepo build system.`; -template.os = [nodeOsLookup[os]]; -template.cpu = [nodeArchLookup[arch]]; -template.version = version; - -const outputPath = path.join(__dirname, "build", template.name); -fs.rmSync(outputPath, { recursive: true, force: true }); -fs.mkdirSync(path.join(outputPath, "bin"), { recursive: true }); - -if (os === "windows") { - fs.copyFileSync( - path.join(__dirname, "template", "bin", "turbo"), - path.join(outputPath, "bin", "turbo") - ); -} -fs.copyFileSync( - path.join(__dirname, "template", "README.md"), - path.join(outputPath, "README.md") -); -fs.writeFileSync( - path.join(outputPath, "package.json"), - JSON.stringify(template, null, 2) -); - -const goBin = os === "windows" ? "go-turbo.exe" : "go-turbo"; -fs.copyFileSync( - path.join(__dirname, "..", "..", `dist-${os}-${arch}`, goBin), - path.join(outputPath, "bin", goBin) -); diff --git a/cli/scripts/npm-native-packages/template/README.md b/cli/scripts/npm-native-packages/template/README.md deleted file mode 100644 index fcbd4c0..0000000 --- a/cli/scripts/npm-native-packages/template/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# `turbo` - -This is a platform-specific binary for Turborepo, a monorepo build system. See https://github.com/vercel/turbo for details. diff --git a/cli/scripts/npm-native-packages/template/bin/turbo b/cli/scripts/npm-native-packages/template/bin/turbo deleted file mode 100644 index 4557a07..0000000 --- a/cli/scripts/npm-native-packages/template/bin/turbo +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node - -// Unfortunately even though npm shims "bin" commands on Windows with auto- -// generated forwarding scripts, it doesn't strip the ".exe" from the file name -// first. So it's possible to publish executables via npm on all platforms -// except Windows. I consider this a npm bug. -// -// My workaround is to add this script as another layer of indirection. It'll -// be slower because node has to boot up just to shell out to the actual exe, -// but Windows is somewhat of a second-class platform to npm so it's the best -// I can do I think. -const path = require('path'); -const turbo_exe = path.join(__dirname, 'turbo.exe'); -const child_process = require('child_process'); -child_process.spawnSync(turbo_exe, process.argv.slice(2), { stdio: 'inherit' }); diff --git a/cli/scripts/npm-native-packages/template/template.package.json b/cli/scripts/npm-native-packages/template/template.package.json deleted file mode 100644 index fdc72c0..0000000 --- a/cli/scripts/npm-native-packages/template/template.package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "turbo-{{Os}}-{{Arch}}", - "version": "{{Version}", - "description": "The {{Os}}-{{Arch}} binary for turbo, a monorepo build system.", - "repository": "https://github.com/vercel/turbo", - "bugs": "https://github.com/vercel/turbo/issues", - "homepage": "https://turbo.build/repo", - "license": "MPL-2.0", - "os": ["{{Os}}"], - "cpu": ["{{Arch}}"], - "preferUnplugged": true -} diff --git a/cli/scripts/templates/jest.config.js b/cli/scripts/templates/jest.config.js deleted file mode 100644 index 0548306..0000000 --- a/cli/scripts/templates/jest.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - roots: ["<rootDir>/src"], - transform: { - "^.+\\.tsx?$": "ts-jest", - }, - // testRegex: '(/__tests__/.*(\\.|/)(test|spec))\\.tsx?$', - moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], - modulePathIgnorePatterns: ["<rootDir>/src/__fixtures__"], - preset: "ts-jest", -}; diff --git a/cli/scripts/templates/src/__tests__/index.test.ts b/cli/scripts/templates/src/__tests__/index.test.ts deleted file mode 100644 index 9a4831a..0000000 --- a/cli/scripts/templates/src/__tests__/index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { sum } from "../."; - -describe("Hello", () => { - it("renders without crashing", () => { - expect(sum(1, 2)).toEqual(3); - }); -}); diff --git a/cli/scripts/templates/src/__tests__/tsconfig.json b/cli/scripts/templates/src/__tests__/tsconfig.json deleted file mode 100644 index bf65be6..0000000 --- a/cli/scripts/templates/src/__tests__/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "include": [".", "../."] -} diff --git a/cli/scripts/templates/src/index.ts b/cli/scripts/templates/src/index.ts deleted file mode 100644 index 715e93e..0000000 --- a/cli/scripts/templates/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const sum = (a: number, b: number) => { - return a + b; -}; diff --git a/cli/scripts/templates/tsconfig.json b/cli/scripts/templates/tsconfig.json deleted file mode 100644 index 76ae392..0000000 --- a/cli/scripts/templates/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "dist" - }, - "include": ["src"], - "exclude": ["node_modules"] -} |
