-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ceb957
Showing
17 changed files
with
7,511 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
public | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@smarterlabs/eslint-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# System generated files | ||
.DS_Store | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Dependency directories | ||
node_modules | ||
|
||
# Development/Environment | ||
.env | ||
.env.* | ||
test-env.txt | ||
!.env.example | ||
dist | ||
dist-* | ||
build | ||
public | ||
storybook-static | ||
.cache | ||
.serverless | ||
_optimize | ||
/netlify.toml | ||
.npmrc | ||
|
||
# Temporary | ||
temp | ||
temp-* | ||
|
||
# Local Netlify folder | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v12.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Director |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "independent", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "director", | ||
"private": true, | ||
"author": "https://smarterlabs.com", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"bootstrap": "yarn run clean && cd packages/data && yarn build", | ||
"build": "cd packages/sandbox-director && yarn build", | ||
"clean": "npx lerna run clean --stream --no-sort --concurrency 999", | ||
"dev": "npx lerna run dev --stream --no-sort --concurrency 999", | ||
"lint": "npx eslint ./", | ||
"lint:fix": "npx eslint ./ --fix", | ||
"stop": "sudo killall -9 node" | ||
}, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"**/*.js": [ | ||
"eslint --fix" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@smarterlabs/eslint-config": "^1.0.9", | ||
"eslint": "^6.8.0", | ||
"husky": "^4.2.5", | ||
"lerna": "^3.20.2", | ||
"lint-staged": "^10.2.2", | ||
"open-cli": "^6.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@smarterlabs/director", | ||
"version": "0.0.0", | ||
"main": "src/director.js", | ||
"dependencies": { | ||
"del": "^5.1.0", | ||
"express": "^4.17.1", | ||
"fs-extra": "^9.0.0", | ||
"http-proxy-middleware": "^1.0.3", | ||
"open": "^7.0.3", | ||
"yargs": "^15.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { move } = require(`fs-extra`) | ||
const { join } = require(`path`) | ||
|
||
module.exports = async function build(options){ | ||
console.log(`Assembling build...`) | ||
let promises = [] | ||
options.paths.forEach(path => { | ||
let src = join(options.src, path.src) | ||
let dist = join(options.dist, path.url || path.dist) | ||
promises.push(move(src, dist, { overwrite: true })) | ||
}) | ||
await Promise.all(promises) | ||
console.log(`Done assembling`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const del = require(`del`) | ||
|
||
module.exports = async function clean(options){ | ||
await del([options.dist]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const express = require(`express`) | ||
const { createProxyMiddleware } = require(`http-proxy-middleware`) | ||
const open = require(`open`) | ||
|
||
const app = express() | ||
const proxy = createProxyMiddleware | ||
const defaultOptions = { | ||
paths: [], | ||
port: 5555, | ||
} | ||
|
||
module.exports = function startServer(options){ | ||
options = { | ||
...defaultOptions, | ||
...options, | ||
} | ||
let paths = getPaths(options) | ||
|
||
paths.forEach(path => { | ||
app.use(path.url, proxy({ | ||
target: `http://localhost:${path.port}`, | ||
changeOrigin: true, | ||
pathRewrite: { | ||
[path.url]: ``, | ||
}, | ||
...options.proxyOptions, | ||
...path.proxyOptions, | ||
})) | ||
}) | ||
|
||
app.listen(options.port) | ||
console.log(`Director started at ${options.port}`) | ||
if(options.open){ | ||
open(`http://localhost:${options.port}/`) | ||
} | ||
} | ||
|
||
// Build an array of objects containing path information | ||
function getPaths(options) { | ||
let paths = [] | ||
|
||
if (Array.isArray(options.paths)) { | ||
paths.push(...options.paths) | ||
} | ||
else { | ||
let keys = Object.keys(options.paths) | ||
keys.forEach(url => { | ||
paths.push({ | ||
url, | ||
...options.paths[url], | ||
}) | ||
}) | ||
} | ||
if (options.sort) { | ||
paths.sort(options.sort) | ||
} | ||
|
||
return paths | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const argv = require(`yargs`).argv | ||
const dev = require(`./dev`) | ||
const build = require(`./build`) | ||
const clean = require(`./clean`) | ||
|
||
const cmd = (label) => argv._.includes(label) | ||
|
||
module.exports = function Director(options){ | ||
options = { | ||
...defaultOptions, | ||
...options, | ||
} | ||
const director = { | ||
dev: () => dev(options), | ||
build: () => build(options), | ||
clean: () => clean(options), | ||
} | ||
if (cmd(`develop`)) { | ||
director.dev() | ||
} | ||
else if (cmd(`build`)){ | ||
director.build() | ||
} | ||
else if (cmd(`clean`)){ | ||
director.clean() | ||
} | ||
return director | ||
} | ||
|
||
const defaultOptions = { | ||
sort: (a, b) => { | ||
if(a.url == `/`) return 1 | ||
if(b.url == `/`) return -1 | ||
let aDepth = a.url.split(`/`).length | ||
let bDepth = b.url.split(`/`).length | ||
if(aDepth > bDepth) return -1 | ||
else if(aDepth < bDepth) return 1 | ||
return 0 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@app/sandbox-a", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "serve www -l 5000" | ||
}, | ||
"dependencies": { | ||
"serve": "^11.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body>Success!</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const Director = require(`@smarterlabs/director`) | ||
|
||
Director({ | ||
paths: { | ||
'/': { | ||
port: 5000, | ||
src: `sandbox-a/www`, | ||
}, | ||
}, | ||
src: `../`, | ||
dist: `dist`, | ||
port: 5555, | ||
open: true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@app/sandbox-director", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"build": "node director build", | ||
"clean": "node director clean", | ||
"dev": "node director develop" | ||
}, | ||
"dependencies": { | ||
"@smarterlabs/director": "*" | ||
} | ||
} |
Oops, something went wrong.