Skip to content

Commit bc4e079

Browse files
committedJun 3, 2022
chore: clean build scripts
1 parent aa19e23 commit bc4e079

8 files changed

+87
-31
lines changed
 

‎.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ module.exports = {
44
'./packages/common/eslint-config',
55
'./packages/common/eslint-config/vue'
66
],
7+
rules: {
8+
'import/no-extraneous-dependencies': [
9+
'error',
10+
{
11+
devDependencies: ['./scripts/**/*']
12+
}
13+
]
14+
},
715
overrides: [
816
{
917
files: ['*.ts', '*.tsx'],

‎package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+23-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"precommit": "lint-staged",
7+
"bootstrap": "npm run lerna:clean && npm run lerna:bootstrap && npm run build:lib",
8+
"bootstrap:ci": "npm run lerna:clean && npm run lerna:bootstrap:ci && npm run build:lib",
9+
10+
"build:lib": "babel-node scripts/buildProjectLib.js",
11+
12+
"check:instances": "babel-node ./scripts/checkInstances.js",
13+
14+
"create:dts": "babel-node scripts/generateDts.js",
15+
"create:package": "npx yo ./packages/generators/generator-package",
16+
17+
"lerna:bootstrap": "lerna bootstrap -- --legacy-peer-deps",
18+
"lerna:bootstrap:ci": "lerna bootstrap --no-ci -- --legacy-peer-deps",
19+
"lerna:clean": "lerna clean --yes",
20+
821
"lint": "eslint .",
922
"lint:fix": "eslint . --fix",
23+
24+
"precommit": "lint-staged",
25+
"prepare": "husky install",
26+
"publish": "npm run build:lib && node ./scripts/publish.js",
27+
1028
"test": "cross-env NODE_ENV=test jest",
1129
"test:update": "cross-env NODE_ENV=test jest -u",
12-
"publish": "npm run build:lib && node ./scripts/publish.js",
13-
"clean": "lerna clean --yes",
14-
"check:instances": "babel-node ./scripts/checkInstances.js",
15-
"bootstrap": "npm run clean && lerna bootstrap -- --legacy-peer-deps",
16-
"bootstrap:ci": "npm run clean && lerna bootstrap --no-ci -- --legacy-peer-deps",
17-
"prepare": "husky install",
30+
31+
"types:check": "tsc --noEmit",
1832
"updateDeipDeps": "node ./scripts/updateDeipDeps.js",
19-
"create:package": "npx yo ./packages/generators/generator-package",
20-
"build:lib": "babel-node scripts/buildProjectLib.js",
21-
"watch:dev": "npm run build:lib && babel-node ./scripts/watchDev.js",
22-
"types:check": "tsc --noEmit"
33+
"watch:dev": "npm run build:lib && babel-node ./scripts/watchDev.js"
2334
},
2435
"keywords": [],
2536
"author": "",
@@ -72,6 +83,7 @@
7283
"ora": "^5.4.1",
7384
"sass": "^1.34.1",
7485
"sass-loader": "^10.2.1",
86+
"shelljs": "^0.8.5",
7587
"shx": "^0.3.4",
7688
"style-loader": "^2.0.0",
7789
"typescript": "^4.7.2",

‎scripts/checkInstances.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* eslint-disable */
21
import glob from 'glob';
32
import path from 'path';
43
import fs from 'fs-extra';
5-
/* eslint-enable */
64

75
import { getPackages } from './utils';
86

‎scripts/generateDts.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import yargs from 'yargs';
2+
import path from 'path';
3+
4+
import { asyncExec } from './utils';
5+
6+
const { argv } = yargs(process.argv.slice(2));
7+
8+
(async () => {
9+
const inPath = path.join(path.resolve(), argv._[0]);
10+
const dtsFileName = path.parse(inPath).base.replace('.js', '.d.ts');
11+
const outPath = path.join(path.resolve(), argv.out, dtsFileName);
12+
13+
const flags = '--declaration --allowJs --emitDeclarationOnly';
14+
const command = `npx -p typescript tsc ${inPath} ${flags} --outFile ${outPath}`;
15+
16+
await asyncExec(command);
17+
})();

‎scripts/publish.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/* eslint-disable */
21
const inquirer = require('inquirer');
32
const ora = require('ora');
43
const execa = require('execa');
54
const chalk = require('chalk');
65
const fs = require('fs-extra');
76
const path = require('path');
8-
const argv = require('yargs/yargs')(process.argv.slice(2)).argv
9-
/* eslint-enable */
7+
8+
// eslint-disable-next-line import/extensions
9+
const { argv } = require('yargs/yargs')(process.argv.slice(2));
1010

1111
const {
1212
bootstrap = true,
@@ -23,7 +23,10 @@ const { command: { version: { allowBranch } } } = fs.readJsonSync(path.join(root
2323
/**
2424
* @return {string} Current branch name
2525
*/
26-
const getCurrentBranch = async () => (await execa.command('git rev-parse --abbrev-ref HEAD')).stdout;
26+
const getCurrentBranch = async () => {
27+
const { stdout } = await execa.command('git rev-parse --abbrev-ref HEAD');
28+
return stdout;
29+
};
2730

2831
/**
2932
* @param error
@@ -47,18 +50,33 @@ const checkBranchUpToDate = async (currentBranch) => {
4750

4851
const { stdout } = await execa.command('git status -uno');
4952

50-
const isAhead = stdout.includes('Your branch is ahead');
51-
const isBehind = stdout.includes('Your branch is behind');
52-
const isDirty = stdout.includes('Changes not staged');
53+
const aheadMsg = {
54+
phrase: 'Your branch is ahead',
55+
recommend: 'Use "git push" to publish your local commits'
56+
};
57+
const behindMsg = {
58+
phrase: 'Your branch is behind',
59+
recommend: 'Use "git pull" to update your local branch'
60+
};
61+
const dirtyMsg = {
62+
phrase: 'Changes not staged',
63+
recommend: 'Use "git add [file]..." to update what will be committed'
64+
};
65+
66+
const remoteBranch = `origin/${currentBranch}`;
67+
68+
const isAhead = stdout.includes(aheadMsg.phrase);
69+
const isBehind = stdout.includes(behindMsg.phrase);
70+
const isDirty = stdout.includes(dirtyMsg.phrase);
5371

5472
if (isAhead) {
55-
throw new Error(`Your branch is ahead of 'origin/${currentBranch}'. Use "git push" to publish your local commits`);
73+
throw new Error(`${aheadMsg.phrase} of '${remoteBranch}'. ${aheadMsg.recommend}`);
5674
}
5775
if (isBehind) {
58-
throw new Error(`Your branch is behind of 'origin/${currentBranch}'. Use "git pull" to update your local branch`);
76+
throw new Error(`${behindMsg.phrase} of '${remoteBranch}'. ${behindMsg.recommend}`);
5977
}
6078
if (isDirty) {
61-
throw new Error('Changes not staged for commit. Use "git add [file]..." to update what will be committed');
79+
throw new Error(`${dirtyMsg.phrase} for commit. ${dirtyMsg.recommend}`);
6280
}
6381

6482
return true;
@@ -146,6 +164,7 @@ Make sure everything is done correctly.
146164
const publishBranch = await getCurrentBranch();
147165

148166
if (!allowBranch.includes(publishBranch)) {
167+
// eslint-disable-next-line max-len
149168
errorHandler(`Wrong Branch ${publishBranch}. Publish can be started only from ${allowBranch.join(' ,')}.`);
150169
}
151170

‎scripts/updateDeipDeps.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/* eslint-disable */
21
const inquirer = require('inquirer');
32
const execa = require('execa');
4-
/* eslint-enable */
53

64
const prompt = inquirer.createPromptModule();
75

@@ -26,6 +24,12 @@ prompt([{
2624
process.exit();
2725
}
2826

29-
await execa.command('npx lerna exec -- "npx ncu \'/^@(deip|casimir)\\/.*$/\' -u"', { stdio: 'inherit', shell: true });
27+
const commandStack = [
28+
'npx lerna exec',
29+
'--',
30+
'"npx ncu \'/^@(deip|casimir)\\/.*$/\' -u"'
31+
];
32+
33+
await execa.command(commandStack.join(' '), { stdio: 'inherit', shell: true });
3034
process.exit();
3135
});

‎scripts/watchDev.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* eslint-disable */
21
import chokidar from 'chokidar';
32
import path from 'path';
43
import ora from 'ora';
5-
/* eslint-enable */
64

75
import { getPackages, buildPackageLib, findPackageRoot } from './utils';
86

0 commit comments

Comments
 (0)
Please sign in to comment.