Skip to content

Commit

Permalink
workflow: upgrade scripts and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick committed Oct 25, 2019
1 parent 6538d8e commit 5ac2555
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 25 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/scripts/jest.js",
"stopOnEntry": false,
"args": ["${fileBasename}", "--runInBand", "--detectOpenHandles"],
"cwd": "${workspaceFolder}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": ["--nolazy"],
"env": {
"NODE_ENV": "development"
},
"console": "integratedTerminal",
"sourceMaps": true
}
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use the project's typescript version
"typescript.tsdk": "node_modules/typescript/lib",

"cSpell.enabledLanguageIds": ["markdown", "plaintext", "text", "yml"],

// Use prettier to format typescript, javascript and JSON files
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const lernaJson = require("./lerna.json");

module.exports = {
preset: "ts-jest",
globals: {
__DEV__: true,
__VERSION__: lernaJson.version,
__BROWSER__: false,
__JSDOM__: true,
__FEATURE_OPTIONS__: true,
Expand Down
4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"packages": [
"catalog",
"theme",
"packages/*"
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent"
"version": "0.1.0"
}
1 change: 1 addition & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare var __DEV__: boolean;
declare var __JSDOM__: boolean;
declare var __BROWSER__: boolean;
declare var __COMMIT__: string;
declare var __VERSION__: string;

// Feature flags
declare var __FEATURE_OPTIONS__: boolean;
Expand Down
39 changes: 25 additions & 14 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const fs = require("fs");
const path = require("path");
const ts = require("rollup-plugin-typescript2");
const replace = require("rollup-plugin-replace");
const alias = require("rollup-plugin-alias");
const json = require("rollup-plugin-json");
const peerDepsExternal = require("rollup-plugin-peer-deps-external");
import fs from "fs";
import path from "path";
import ts from "rollup-plugin-typescript2";
import replace from "rollup-plugin-replace";
import alias from "rollup-plugin-alias";
import json from "rollup-plugin-json";
import lernaJson from "./lerna.json";
import peerDepsExternal from "rollup-plugin-peer-deps-external";

if (!process.env.TARGET) {
throw new Error("TARGET package must be specified via --environment flag.");
Expand Down Expand Up @@ -70,14 +71,15 @@ if (process.env.NODE_ENV === "production") {
});
}

module.exports = packageConfigs;
export default packageConfigs;

function createConfig(output, plugins = []) {
const isProductionBuild =
process.env.__DEV__ === "false" || /\.prod\.js$/.test(output.file);
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file);
const isBunlderESMBuild = /\.esm\.js$/.test(output.file);
const isBundlerESMBuild = /\.esm-bundler\.js$/.test(output.file);
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file);
const isRuntimeCompileBuild = /vue\./.test(output.file);

if (isGlobalBuild) {
output.name = packageOptions.name;
Expand Down Expand Up @@ -125,9 +127,10 @@ function createConfig(output, plugins = []) {
peerDepsExternal(),
createReplacePlugin(
isProductionBuild,
isBunlderESMBuild,
isBundlerESMBuild,
(isGlobalBuild || isBrowserESMBuild) &&
!packageOptions.enableNonBrowserBranches
!packageOptions.enableNonBrowserBranches,
isRuntimeCompileBuild
),
...plugins
],
Expand All @@ -140,19 +143,27 @@ function createConfig(output, plugins = []) {
};
}

function createReplacePlugin(isProduction, isBunlderESMBuild, isBrowserBuild) {
function createReplacePlugin(
isProduction,
isBundlerESMBuild,
isBrowserBuild,
isRuntimeCompileBuild
) {
return replace({
__COMMIT__: `"${process.env.COMMIT}"`,
__DEV__: isBunlderESMBuild
__VERSION__: `"${lernaJson.version}"`,
__DEV__: isBundlerESMBuild
? // preserve to be handled by bundlers
`process.env.NODE_ENV !== 'production'`
: // hard coded dev/prod builds
!isProduction,
// If the build is expected to run directly in the browser (global / esm-browser builds)
__BROWSER__: isBrowserBuild,
// support compile in browser?
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
// support options?
// the lean build drops options related code with buildOptions.lean: true
__FEATURE_OPTIONS__: !packageOptions.lean,
__FEATURE_OPTIONS__: !packageOptions.lean && !process.env.LEAN,
__FEATURE_SUSPENSE__: true,
// this is only used during tests
__JSDOM__: false
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function checkAllSizes(targets) {

function checkSize(target) {
const pkgDir = path.resolve(`packages/${target}`);
const esmProdBuild = `${pkgDir}/dist/${target}.esm-browser.prod.js`;
const esmProdBuild = `${pkgDir}/dist/${target}.global.prod.js`;
if (fs.existsSync(esmProdBuild)) {
const file = fs.readFileSync(esmProdBuild);
const minSize = (file.length / 1024).toFixed(2) + "kb";
Expand Down
7 changes: 7 additions & 0 deletions scripts/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* This file is the entry for debug single test file in vscode
*
* Not using node_modules/.bin/jest due to cross platform issues, see
* https://github.com/microsoft/vscode-recipes/issues/107
*/
require("jest").run(process.argv);
11 changes: 10 additions & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require("fs");
const chalk = require("chalk");

const targets = (exports.targets = fs.readdirSync("packages").filter(f => {
if (!fs.statSync(`packages/${f}`).isDirectory()) {
Expand Down Expand Up @@ -26,6 +27,14 @@ exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
if (matched.length) {
return matched;
} else {
throw new Error(`Target ${partialTargets} not found!`);
console.log();
console.error(
` ${chalk.bgRed.white(" ERROR ")} ${chalk.red(
`Target ${chalk.underline(partialTargets)} not found!`
)}`
);
console.log();

process.exit(1);
}
};
7 changes: 1 addition & 6 deletions scripts/verifyCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ if (!commitRE.test(msg) && !mergeCommitRE.test(msg)) {
` ${chalk.green(
`fix(v-model): handle events on blur (close #28)`
)}\n\n` +
chalk.red(` See .github/commit-convention.md for more details.\n`) +
chalk.red(
` You can also use ${chalk.cyan(
`npm run commit`
)} to interactively generate a commit message.\n`
)
chalk.red(` See .github/commit-convention.md for more details.\n`)
);
process.exit(1);
}

0 comments on commit 5ac2555

Please sign in to comment.