Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 28, 2022
1 parent 3229161 commit d8b5f1d
Show file tree
Hide file tree
Showing 101 changed files with 2,828 additions and 25,633 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
},
"overrides": [
{
"files": ["test/**", "www/*.js"],
"files": ["test/**", "www/**"],
"env": {
"jest": true
},
"rules": {
"global-require": "off",
"no-console": "off",
"react/react-in-jsx-scope": "off",
"import/extensions": "off",
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": true }
Expand Down
64 changes: 0 additions & 64 deletions docs/cross-file-dependencies.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build:pick": "cherry-pick --cwd=lib --input-dir=../src/runtime --cjs-dir=cjs --esm-dir=esm",
"build:runtime": "4c build src/runtime --no-copy-files --no-types",
"build:tools": "4c build -d lib --no-esm -- --ignore \"**/runtime/**\"",
"build": "yarn build:tools && yarn build:runtime && yarn build:pick && yarn copy:types",
"build": "yarn build:tools && yarn build:runtime && yarn build:pick && yarn copy:types && yarn file-butler prepare-publish-dir lib",
"deploy-docs": "yarn --cwd www build --prefix-paths && gh-pages -d www/public",
"release": "4c release",
"start": "yarn --cwd ./example start"
Expand Down
186 changes: 95 additions & 91 deletions src/vite-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
// import { createFilter } from '@rollup/pluginutils';

// import { collectStyles, replaceStyleTemplates } from './utils/loaders';

// function astroturf({ include, exclude, ...rest } = {}) {
// const filter = createFilter(include || /\.(jsx?|tsx?)/i, exclude);
// const cssLookup = new Map();
// const pathMap = new Map();
// const sourceMetadata = new Map();

// function transform(content, filename) {
// const metadata = collectStyles(content, filename, undefined, rest);

// const { code, map } = replaceStyleTemplates(
// filename,
// content,
// metadata.changeset,
// true,
// );

// sourceMetadata.set(filename, metadata);

// metadata.styles.forEach(({ absoluteFilePath, requirePath, value }) => {
// cssLookup.set(absoluteFilePath, value);
// pathMap.set(requirePath, absoluteFilePath);
// });

// return {
// code,
// map,
// styles: metadata.styles,
// };
// }

// return {
// name: 'astroturf',

// load(id) {
// return cssLookup.get(id) || cssLookup.get(process.cwd() + id);
// },

// resolveId(importee) {
// importee = importee.split('?')[0];
// const id = cssLookup.get(importee) || pathMap.get(importee);
// return id;
// },

// async handleHotUpdate(hmr) {
// if (!filter(hmr.file)) return undefined;

// // console.log("ff", hmr, hmr.modules);
// const prev = sourceMetadata.get(hmr.file);

// if (!prev) return undefined;

// const module = hmr.modules.find((m) => m.file === hmr.file);
// const affectedModules = new Set(hmr.modules);

// const content = await hmr.read();
// const { styles } = transform(content, hmr.file);

// try {
// module.importedModules?.forEach((m) => {
// if (
// styles.find(
// (s) =>
// s.absoluteFilePath === m.file ||
// s.absoluteFilePath === process.cwd() + m.file,
// )
// ) {
// affectedModules.add(m);
// }
// });
// } catch (err) {
// console.log(err);
// }

// return [...affectedModules];
// },

// transform(content, id) {
// if (!filter(id) || !content.includes('astroturf')) {
// return undefined;
// }

// const { code, map } = transform(content, id);

// return { code, map };
// },
// };
// }

// export default astroturf;
import { collectStyles, replaceStyleTemplates } from './utils/loaders';

function astroturf({ ...rest }: any = {}) {
// const filter = createFilter(include || /\.(jsx?|tsx?)/i, exclude);
const cssLookup = new Map();
const pathMap = new Map();
const sourceMetadata = new Map();

function filter(file) {
return !!file.match(/\.(jsx?|tsx?)/i);
}

function transform(content, filename) {
const metadata = collectStyles(content, filename, undefined as any, rest);

const { code, map } = replaceStyleTemplates(
filename,
content,
metadata.changeset,
true,
);

sourceMetadata.set(filename, metadata);

metadata.styles.forEach(({ absoluteFilePath, requirePath, value }) => {
cssLookup.set(absoluteFilePath, value);
pathMap.set(requirePath, absoluteFilePath);
});

return {
code,
map,
styles: metadata.styles,
};
}

return {
name: 'astroturf',

load(id) {
return cssLookup.get(id) || cssLookup.get(process.cwd() + id);
},

resolveId(importee) {
importee = importee.split('?')[0];
const id = cssLookup.get(importee) || pathMap.get(importee);
return id;
},

async handleHotUpdate(hmr) {
if (!filter(hmr.file)) return undefined;

// console.log("ff", hmr, hmr.modules);
const prev = sourceMetadata.get(hmr.file);

if (!prev) return undefined;

const module = hmr.modules.find((m) => m.file === hmr.file);
const affectedModules = new Set(hmr.modules);

const content = await hmr.read();
const { styles } = transform(content, hmr.file);

try {
module.importedModules?.forEach((m) => {
if (
styles.find(
(s) =>
s.absoluteFilePath === m.file ||
s.absoluteFilePath === process.cwd() + m.file,
)
) {
affectedModules.add(m);
}
});
} catch (err) {
console.log(err);
}

return [...affectedModules];
},

transform(content, id) {
if (!filter(id) || !content.includes('astroturf')) {
return undefined;
}

const { code, map } = transform(content, id);

return { code, map };
},
};
}

export default astroturf;
3 changes: 0 additions & 3 deletions www/.eslintrc

This file was deleted.

File renamed without changes.
21 changes: 0 additions & 21 deletions www/LICENSE

This file was deleted.

36 changes: 36 additions & 0 deletions www/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh

# abort on errors
set -e

# build
yarn run build

# navigate into the build output directory
cd dist

# place .nojekyll to bypass Jekyll processing
echo > .nojekyll

mkdir -p introduction && cp -R index.html "$_"
mkdir -p advanced && cp -R index.html "$_"
mkdir -p tooling && cp -R index.html "$_"
mkdir -p cross-file-dependencies && cp -R index.html "$_"
mkdir -p setup && cp -R index.html "$_"


# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME

git init
git checkout -B main
git add -A
git commit -m 'deploy'

# if you are deploying to https://<USERNAME>.github.io
# git push -f [email protected]:<USERNAME>/<USERNAME>.github.io.git main

# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f [email protected]:4Catalyzer/astroturf.git main:gh-pages

cd -
3 changes: 0 additions & 3 deletions www/gatsby-browser.js

This file was deleted.

40 changes: 0 additions & 40 deletions www/gatsby-config.js

This file was deleted.

Loading

0 comments on commit d8b5f1d

Please sign in to comment.