Skip to content

Commit

Permalink
some setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gossi committed Aug 4, 2020
1 parent 17c4b90 commit 1c12451
Show file tree
Hide file tree
Showing 15 changed files with 43,074 additions and 287 deletions.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
testEnvironment: 'node',
transform: {
"^.+\\.ts$": 'esbuild-jest'
},
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/types/'],
}
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
],
"scripts": {
"clean": "rm -rf dist",
"esbuild": "yarn clean && node scripts/build.js",
"esbuild:esm": "esbuild --target=esnext --outfile=dist/theemo.esm.js --platform=node --bundle --format=esm src/index.ts",
"esbuild:cjs": "esbuild --target=esnext --outfile=dist/index.js --platform=node --bundle --format=cjs src/index.ts",
"build": "yarn clean && tsdx build --target node",
"start": "tsdx watch --target node",
"_test": "tsdx test",
"test": "jest",
"lint:js": "eslint --ext ts,js src",
"lint:types": "tsc --noEmit",
"lint": "yarn lint:js && yarn lint:types",
Expand All @@ -43,9 +46,12 @@
"@microsoft/api-extractor": "^7.7.11",
"@types/jest": "^24.0.25",
"@types/node-fetch": "^2.5.4",
"esbuild": "^0.6.13",
"esbuild-jest": "^0.2.0",
"eslint": "6.8.0",
"tsdx": "^0.12.3",
"jest": "^26.2.2",
"tsdx": "^0.13.2",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
}
}
}
52 changes: 52 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// import * as path from 'path'
// import { buildSync } from 'esbuild'
// import { builtinModules } from 'module'

const path = require('path');
const { buildSync } = require('esbuild');
const { builtinModules } = require('module');
const fs = require('fs');

const pkg = require(path.resolve('package.json'))
const external = [
...builtinModules,
...Object.keys(pkg.dependencies || {})
]

const build = (outfile, options) => {
buildSync({
entryPoints: ['src/index.ts'],
outfile,
minify: false,
bundle: true,
write: true,
target: 'es2015',
sourcemap: true,
platform: 'node',
external,
...options
});
}

build('dist/theemo.esm-build.js', {
format: 'esm'
});

build('dist/theemo.cjs.development.js', {
format: 'cjs',
});

build('dist/theemo.cjs.production.min.js', {
format: 'cjs',
minify: true
});

fs.writeFileSync('dist/index.js', `
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./theemo.cjs.production.min.js')
} else {
module.exports = require('./theemo.cjs.development.js')
}
`);
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { program } from 'commander';
import dotenv from 'dotenv';
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
import package_ from '../package.json';
import Theemo from './theemo';

Expand Down
16 changes: 10 additions & 6 deletions src/sync/reader/figma/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ export default class FigmaReader implements ReaderAdapter {
}

async read() {
// read figma
const figmaClient = new FigmaClient({
personalAccessToken: this.config.figmaSecret
});

const file = await figmaClient.getFile(this.config.figmaFile);
const file = await this.load();

// create referencer
await this.referencer.setup();

const parser = new FigmaParser(file, this.referencer, this.config);
return parser.parse();
}

private async load() {
// read figma
const figmaClient = new FigmaClient({
personalAccessToken: this.config.figmaSecret
});

return figmaClient.getFile(this.config.figmaFile);
}
}
25 changes: 15 additions & 10 deletions src/sync/reader/figma/referencers/plugin/theemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,24 @@ export default class TheemoPluginReferencer implements Referencer {

async setup() {
if (!this.references) {
// read references from jsonbin.io
const response = await fetch(
`https://api.jsonbin.io/b/${this.options.jsonbinFile}`,
{
headers: {
'secret-key': this.options.jsonbinSecret
}
}
);
this.references = await response.json();
this.references = await this.load();
console.log(this.references);
}
}

private async load() {
// read references from jsonbin.io
const response = await fetch(
`https://api.jsonbin.io/b/${this.options.jsonbinFile}`,
{
headers: {
'secret-key': this.options.jsonbinSecret
}
}
);
return response.json();
}

find(name: string, type: string): string | undefined {
const nodeReference = this.references.nodes.find(node => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/sync/writer/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Token from 'theemo/token';
import Token from '../../token';

export default interface WriterConfig {
formats: {
Expand Down

0 comments on commit 1c12451

Please sign in to comment.