Skip to content

Commit 4ca0405

Browse files
committed
First pass at migrating to TypeScript
1 parent c20bcc8 commit 4ca0405

File tree

147 files changed

+1012
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1012
-551
lines changed

.github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ jobs:
1616
- run: yarn install --frozen-lockfile
1717
- run: yarn run lint
1818
- run: yarn run fix
19-
- run: yarn run test
19+
- run: yarn run build
20+
# FIXME
21+
# - run: yarn run test

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
.DS_Store
22
.nyc_output/
33
*.log
4-
lib/
4+
*.tsbuildinfo
55
node_modules/
6+
packages/*/lib/
67
packages/**/fixtures/**/build/
78
packages/**/fixtures/**/figma-plugin/
89
packages/**/fixtures/**/manifest.json
910
packages/create-figma-plugin/docs
1011
packages/create-figma-plugin/README.md
11-
packages/ui/build/
12+
packages/ui/storybook/

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Lim Yuan Qing
3+
Copyright (c) Yuan Qing Lim
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

babel.config.js

-13
This file was deleted.

lerna.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"version": "0.0.68",
33
"npmClient": "yarn",
44
"useWorkspaces": true,
5-
"packages": [
6-
"packages/*"
7-
],
5+
"packages": ["packages/*"],
86
"command": {
97
"bootstrap": {
108
"forceLocal": true

package.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
{
22
"private": true,
33
"scripts": {
4-
"build": "yarn run clean && lerna exec --scope '@create-figma-plugin/{build,common}' --scope create-figma-plugin 'babel src --copy-files --delete-dir-on-start --out-dir lib --root-mode upward'",
4+
"build": "lerna run build --ignore @create-figma-plugin/ui",
55
"bump": "node scripts/bump-dependencies.js",
6-
"clean": "rimraf .nyc_output '*.log' 'packages/*/lib' 'packages/**/fixtures/**/{build,figma-plugin,manifest.json,node_modules}' 'packages/create-figma-plugin/{docs,README.md}' packages/ui/build",
6+
"clean": "rimraf .nyc_output '*.log' 'packages/*/{lib,tsconfig.tsbuildinfo}' 'packages/**/fixtures/**/{build,figma-plugin,manifest.json,node_modules}' 'packages/create-figma-plugin/{docs,README.md}' packages/ui/build",
77
"coverage": "yarn run build && nyc --exclude 'packages/*/lib' -- ava",
88
"docs": "node scripts/insert-toc.js",
9-
"fix": "concurrently --raw 'yarn run fix-css' 'yarn run fix-js'",
10-
"fix-css": "prettier --write 'packages/*/src/**/*.scss'",
11-
"fix-js": "prettier-standard '*.js' 'scripts/**/*.js' 'packages/*/{.storybook,src,test}/**/*.js'",
12-
"lint": "concurrently --raw 'yarn run lint-css' 'yarn run lint-js'",
13-
"lint-css": "stylelint 'packages/*/src/**/*.scss'",
14-
"lint-js": "standardx '*.js' 'scripts/**/*.js' 'packages/*/{.storybook,src,test}/**/*.js'",
9+
"fix": "prettier-standard 'scripts/**/*.js' 'packages/*/{.storybook,src,test}/**/*.ts' && prettier --write '*.json' 'packages/*/*.json' 'packages/*/src/**/*.scss'",
10+
"lint": "standardx 'scripts/**/*.js' 'packages/*/{.storybook,src,test}/**/*.ts' && stylelint 'packages/*/src/**/*.scss'",
1511
"postinstall": "yarn run build",
1612
"publish": "yarn run build && cpy 'docs/**/*.md' README.md packages/create-figma-plugin --parents && lerna publish from-package",
1713
"reset": "yarn run clean && lerna clean --yes && rimraf yarn.lock node_modules 'packages/*/node_modules' && yarn install && yarn run build",
@@ -20,20 +16,15 @@
2016
"watch": "chokidar '*.js' 'packages/*/src/**/*.js' --command 'yarn build' --initial --silent"
2117
},
2218
"devDependencies": {
23-
"@babel/cli": "^7.8.4",
24-
"@babel/core": "^7.9.6",
25-
"@babel/plugin-transform-modules-commonjs": "^7.9.6",
26-
"@babel/plugin-transform-react-jsx": "^7.9.4",
2719
"@figma/plugin-typings": "^1.15.0",
2820
"@storybook/addon-storysource": "^5.3.18",
2921
"@storybook/preact": "^5.3.18",
3022
"@storybook/source-loader": "^5.3.18",
3123
"@storybook/storybook-deployer": "^2.8.5",
24+
"@typescript-eslint/eslint-plugin": "^2.31.0",
25+
"@typescript-eslint/parser": "^2.31.0",
3226
"ava": "^3.8.1",
33-
"babel-loader": "^8.1.0",
34-
"babel-plugin-require-context-hook": "^1.0.0",
3527
"chokidar-cli": "^2.1.0",
36-
"concurrently": "^5.2.0",
3728
"cpy-cli": "^3.1.0",
3829
"eslint-plugin-react-hooks": "^4.0.0",
3930
"esm": "^3.2.25",
@@ -53,16 +44,17 @@
5344
"standardx": "^5.0.0",
5445
"stylelint": "^13.3.3",
5546
"stylelint-config-prettier": "^8.0.1",
56-
"stylelint-prettier": "^1.1.2"
47+
"stylelint-prettier": "^1.1.2",
48+
"typescript": "^3.8.3",
49+
"typescript-plugin-css-modules": "^2.3.0"
5750
},
5851
"ava": {
5952
"files": [
6053
"packages/*/test/**/*.js",
6154
"!**/fixtures/**"
6255
],
6356
"require": [
64-
"esm",
65-
"./packages/common/src/silence-logging.js"
57+
"esm"
6658
],
6759
"timeout": "30s",
6860
"verbose": true
@@ -77,6 +69,8 @@
7769
"rules": {
7870
"indent": "off",
7971
"no-console": "error",
72+
"no-unused-vars": "off",
73+
"@typescript-eslint/no-unused-vars": "error",
8074
"react-hooks/rules-of-hooks": "error",
8175
"react-hooks/exhaustive-deps": "warn"
8276
}
@@ -96,6 +90,12 @@
9690
"prettier"
9791
]
9892
},
93+
"standardx": {
94+
"parser": "@typescript-eslint/parser",
95+
"plugins": [
96+
"@typescript-eslint/eslint-plugin"
97+
]
98+
},
9999
"stylelint": {
100100
"extends": [
101101
"stylelint-prettier/recommended"

packages/build/.babelrc

-5
This file was deleted.

packages/build/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"figma-plugins"
1313
],
1414
"license": "MIT",
15-
"author": "Lim Yuan Qing",
15+
"author": "Yuan Qing Lim",
1616
"repository": {
1717
"type": "git",
1818
"url": "git://github.com/yuanqing/create-figma-plugin.git",
@@ -24,13 +24,16 @@
2424
"bin": {
2525
"build-figma-plugin": "lib/cli.js"
2626
},
27+
"scripts": {
28+
"build": "yarn run clean && tsc --build",
29+
"clean": "rimraf '*.log' lib tsconfig.tsbuildinfo"
30+
},
2731
"dependencies": {
2832
"@babel/core": "^7.9.6",
2933
"@babel/plugin-proposal-object-rest-spread": "^7.9.6",
3034
"@babel/plugin-transform-react-jsx": "^7.9.4",
3135
"@babel/plugin-transform-template-literals": "^7.8.3",
3236
"@create-figma-plugin/common": "^0.0.68",
33-
"@create-figma-plugin/utilities": "^0.0.68",
3437
"babel-loader": "^8.1.0",
3538
"chokidar": "^3.4.0",
3639
"css-loader": "^3.5.3",
File renamed without changes.

packages/build/src/build-bundle-async.js packages/build/src/build-bundle-async.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { constants } from '@create-figma-plugin/common'
2-
import findUp from 'find-up'
2+
import * as findUp from 'find-up'
33
import { basename, extname } from 'path'
4-
import tempWrite from 'temp-write'
5-
import webpack from 'webpack'
4+
import * as tempWrite from 'temp-write'
5+
import * as webpack from 'webpack'
66
import { createWebpackConfig } from './create-webpack-config'
77

88
export async function buildBundleAsync (config, isDevelopment) {
@@ -17,7 +17,10 @@ export async function buildBundleAsync (config, isDevelopment) {
1717
const key = extractBasename(constants.build.pluginUiFilePath)
1818
entry[key] = uiEntryFile
1919
}
20-
let webpackConfig = createWebpackConfig(entry, isDevelopment)
20+
let webpackConfig: webpack.Configuration = createWebpackConfig(
21+
entry,
22+
isDevelopment
23+
)
2124
const customWebpackConfigPath = await findUp(
2225
constants.build.webpackConfigFileName
2326
)

packages/build/src/build-manifest-async.js packages/build/src/build-manifest-async.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { constants } from '@create-figma-plugin/common'
22
import { outputFile } from 'fs-extra'
33

44
export async function buildManifestAsync (config) {
5-
const result = {
5+
const result: any = {
6+
// FIXME
67
name: config.name,
78
id: config.id,
89
api: config.apiVersion
@@ -43,7 +44,8 @@ function normalizeMenu (menu) {
4344
if (typeof item.separator !== 'undefined') {
4445
return item
4546
}
46-
const result = {
47+
const result: any = {
48+
// FIXME
4749
name: item.name
4850
}
4951
if (typeof item.command !== 'undefined') {

packages/build/src/cli.js packages/build/src/cli.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import sade from 'sade'
44
import { buildAsync } from './build-async'
55
import { watch } from './watch'
6-
import packageJson from '../package.json'
76

87
sade('build-figma-plugin', true)
9-
.describe(packageJson.description)
8+
.describe(
9+
'Build a Figma plugin, with support for multiple menu commands that each have their own UI implementation'
10+
)
1011
.option('-d, --dev', 'Create an unminified bundle with sourcemaps', false)
1112
.option('-w, --watch', 'Rebuild the plugin on code changes', false)
1213
.action(async function ({ dev: isDevelopment, watch: isWatch }) {

packages/build/src/create-webpack-config.js packages/build/src/create-webpack-config.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { join, resolve } from 'path'
22
import TerserPlugin from 'terser-webpack-plugin'
3-
import webpack from 'webpack'
3+
import * as webpack from 'webpack'
44
import { constants } from '@create-figma-plugin/common'
55

6-
export function createWebpackConfig (entry, isDevelopment) {
6+
export function createWebpackConfig (
7+
entry,
8+
isDevelopment
9+
): webpack.Configuration {
710
const mode = isDevelopment ? 'development' : 'production'
811
return {
912
mode,
@@ -79,7 +82,7 @@ export function createWebpackConfig (entry, isDevelopment) {
7982
],
8083
extensions: ['.js', '.ts', '.tsx', '.json']
8184
},
82-
devtool: isDevelopment ? 'inline-cheap-module-source-map' : 'none',
85+
devtool: isDevelopment ? 'inline-cheap-module-source-map' : false,
8386
stats: 'errors-only',
8487
plugins: [
8588
new webpack.EnvironmentPlugin({

packages/build/src/watch.js packages/build/src/watch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chokidar from 'chokidar'
1+
import * as chokidar from 'chokidar'
22
import { constants, log } from '@create-figma-plugin/common'
33
import { buildAsync } from './build-async'
44

packages/build/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.shared.json",
3+
"compilerOptions": {
4+
"outDir": "lib",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts"],
8+
"references": [{ "path": "../common" }]
9+
}

packages/common/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"publishConfig": {
55
"access": "public"
66
},
7-
"description": "Internal code used across the `create-figma-plugin` monorepo",
7+
"description": "Internal utilities used across the `create-figma-plugin` monorepo",
88
"keywords": [
99
"create-figma-plugin",
1010
"figma",
1111
"figma-plugin",
1212
"figma-plugins"
1313
],
1414
"license": "MIT",
15-
"author": "Lim Yuan Qing",
15+
"author": "Yuan Qing Lim",
1616
"repository": {
1717
"type": "git",
1818
"url": "git://github.com/yuanqing/create-figma-plugin.git",
@@ -22,11 +22,14 @@
2222
"lib"
2323
],
2424
"main": "lib/index.js",
25+
"scripts": {
26+
"build": "yarn run clean && tsc --build",
27+
"clean": "rimraf '*.log' lib tsconfig.tsbuildinfo"
28+
},
2529
"dependencies": {
2630
"@sindresorhus/slugify": "^0.11.0",
2731
"chalk": "^4.0.0",
2832
"fs-extra": "^9.0.0",
2933
"npmlog": "^4.1.2"
30-
},
31-
"sideEffects": false
34+
}
3235
}
File renamed without changes.
File renamed without changes.

packages/common/src/log.js packages/common/src/log.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import npmlog from 'npmlog'
1+
import * as npmlog from 'npmlog'
22

33
npmlog.disp.error = 'error'
44
npmlog.style.error = {
@@ -18,13 +18,8 @@ function success (message) {
1818
npmlog.success('', message)
1919
}
2020

21-
function silenceLogging () {
22-
npmlog.level = 'silent'
23-
}
24-
2521
export const log = {
2622
error,
2723
info,
28-
silenceLogging,
2924
success
3025
}

packages/common/src/read-config-async.js packages/common/src/read-config-async.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { exists } from 'fs-extra'
1+
import { pathExists } from 'fs-extra'
22
import { join } from 'path'
3-
import slugify from '@sindresorhus/slugify'
3+
import * as slugify from '@sindresorhus/slugify'
44
import { constants } from './constants'
55

66
const defaultConfig = {
@@ -14,7 +14,7 @@ const defaultConfig = {
1414

1515
export async function readConfigAsync () {
1616
const packageJsonPath = join(process.cwd(), 'package.json')
17-
if ((await exists(packageJsonPath)) === false) {
17+
if ((await pathExists(packageJsonPath)) === false) {
1818
return defaultConfig
1919
}
2020
const packageJson = require(packageJsonPath)
@@ -35,7 +35,7 @@ export async function readConfigAsync () {
3535

3636
function parseCommand (config) {
3737
const { name, main, ui, menu } = config
38-
const result = {}
38+
const result: any = {} // FIXME
3939
result.name = name
4040
if (typeof main !== 'undefined') {
4141
result.command =

packages/common/src/silence-logging.js

-3
This file was deleted.

packages/common/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.shared.json",
3+
"compilerOptions": {
4+
"outDir": "lib",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts"]
8+
}

packages/create-figma-plugin/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"figma-plugins"
1010
],
1111
"license": "MIT",
12-
"author": "Lim Yuan Qing",
12+
"author": "Yuan Qing Lim",
1313
"repository": {
1414
"type": "git",
1515
"url": "git://github.com/yuanqing/create-figma-plugin.git",
@@ -22,6 +22,10 @@
2222
"bin": {
2323
"create-figma-plugin": "lib/cli.js"
2424
},
25+
"scripts": {
26+
"build": "yarn run clean && tsc --build",
27+
"clean": "rimraf '*.log' lib tsconfig.tsbuildinfo"
28+
},
2529
"dependencies": {
2630
"@create-figma-plugin/common": "^0.0.68",
2731
"degit": "^2.8.0",

0 commit comments

Comments
 (0)