Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
chore: factor out analyzer (#740)
Browse files Browse the repository at this point in the history
* chore: factor out utils

* chore: factor out types

* chore: factor out types

* chore: persist all artifacts

* chore: fix circle config

* chore: factor out analyzer

* chore: remove remaining perform-analysis references

* chore: move analyze bin to analyze package

* chore: clean up references

* chore: prune dependency tree

* chore: add missing types pkg

* chore: change product name for release channels

* chore: set artifact name based on channel

* chore: escape ext

* chore: do not duplicate

* chore: vendor standalone bundle of analyzer

* refactor: pass data instead of fns to analyzer

* feat: make analysis runs stateless

* fix: restart project syncing when id changes

* chore: add new package to ci

* fix: remove obsolete deps

* fix: remove unneeded webpack entry

* fix: add missing entry file
  • Loading branch information
marionebl authored Jan 31, 2019
1 parent a18e8ac commit 7a4a4a4
Show file tree
Hide file tree
Showing 365 changed files with 7,031 additions and 1,715 deletions.
53 changes: 38 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ commands:
- save_cache:
paths:
- node_modules
- packages/analyzer/node_modules
- packages/analyzer-cli/node_modules
- packages/components/node_modules
- packages/core/node_modules
- packages/essentials/node_modules
- packages/message/node_modules
- packages/model/node_modules
- packages/model-tree/node_modules
- packages/site/node_modules
- packages/tools/node_modules
- packages/types/node_modules
- packages/util/node_modules
key: v5-dependencies-<< parameters.key >>-{{ checksum "yarn.lock" }}

- run:
Expand All @@ -68,26 +77,29 @@ jobs:
name: Install yarn
command: yarn global add [email protected]

- restore_cache:
keys:
- v5-dependencies-macos-{{ checksum "yarn.lock" }}
- v5-dependencies-macos-
- setup:
key: macos

- run:
name: Install dependencies
command: yarn install --frozen-lockfile || yarn
name: Add npm bin to path
command: echo 'export PATH="$(npm bin):$PATH"' >> $BASH_ENV

- save_cache:
paths:
- node_modules
- packages/components/node_modules
- packages/core/node_modules
- packages/tools/node_modules
key: v5-dependencies-macos-{{ checksum "yarn.lock" }}
deps:
docker:
- image: circleci/node:8

working_directory: ~/repo

steps:
- setup:
key: linux

- attach_workspace:
at: ~/repo

- run:
name: Add npm bin to path
command: echo 'export PATH="$(npm bin):$PATH"' >> $BASH_ENV
name: Check dependencies
command: lerna run check:dependencies --stream

test:
docker:
Expand Down Expand Up @@ -137,10 +149,18 @@ jobs:
- persist_to_workspace:
root: ~/repo
paths:
- packages/analyzer/lib
- packages/analyzer-cli/lib
- packages/components/lib
- packages/core/lib
- packages/essentials/lib
- packages/message/lib
- packages/model/lib
- packages/model-tree/lib
- packages/site/lib
- packages/tools/lib
- packages/types/lib
- packages/util/lib

ncc:
docker:
Expand Down Expand Up @@ -352,6 +372,9 @@ workflows:
- install_macos
- lint
- compile
- deps:
requires:
- compile
- test:
requires:
- compile
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ lib
nccbuild
dist
node_modules
**/vendor/alva-analyze.js
**/vendor/alva-analyze.js.map
*.log
.DS_Store
.static
31 changes: 19 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
// @ts-check
module.exports = {
preset: "ts-jest",
testMatch: ["**/*.test.ts", "**/*.test.tsx"],
preset: 'ts-jest',
testMatch: ['**/*.test.ts', '**/*.test.tsx'],
modulePathIgnorePatterns: ['<rootDir>\/packages\/core\/nccbuild\/(.*)'],
roots: [
"packages/core",
"packages/essentials",
"packages/site",
"packages/tools"
],
testPathIgnorePatterns: [
"node_modules",
"lib"
'packages/analyzer',
'packages/components',
'packages/core',
'packages/essentials',
'packages/message',
'packages/model',
'packages/model-tree',
'packages/site',
'packages/tools',
'packages/types',
'packages/util'
],
testPathIgnorePatterns: ['node_modules', 'lib'],
globals: {
"ts-jest": {
diagnostics: false
'ts-jest': {
diagnostics: {
ignoreCodes: [151001, 2339]
}
}
}
};
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "tslint --project . -c tslint.json 'src/**/*.ts'",
"precommit": "lint-staged",
"watch": "lerna run watch --stream",
"analyze:essentials": "alva analyze --out=packages/essentials/src/analysis.ts --in=packages/essentials/package.json"
"analyze:essentials": "alva analyze --in=packages/essentials/package.json --out=packages/essentials/src/analysis.ts --builtins"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -42,21 +42,27 @@
"@commitlint/prompt-cli": "7.1.2",
"@meetalva/core": "0.9.2",
"@meetalva/site": "0.8.1",
"@meetalva/tools": "0.8.1",
"@meetalva/tools": "1.0.0",
"@patternplate/cli": "^3.2.6",
"@patternplate/render-styled-components": "2.5.18",
"@types/jest": "22.2.2",
"css-loader": "1.0.0",
"dependency-check": "^3.3.0",
"husky": "0.14.3",
"jest": "^23.6.0",
"jest-dom": "^3.0.0",
"jest-util": "^23.4.0",
"lerna": "^3.6.0",
"monaco-editor-webpack-plugin": "1.4.0",
"lint-staged": "7.0.4",
"prettier": "1.12.0",
"style-loader": "0.21.0",
"ts-jest": "^23.10.5",
"ts-loader": "4.4.1",
"tslint": "5.11.0",
"tslint-config-prettier": "1.15.0",
"typescript": "3.2.2"
"typescript": "3.2.2",
"webpack-cli": "3.1.0"
},
"homepage": "https://meetalva.io/",
"workspaces": [
Expand Down
2 changes: 2 additions & 0 deletions packages/analyzer-cli/bin/analyze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/bin/analyze');
35 changes: 35 additions & 0 deletions packages/analyzer-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@meetalva/analyzer-cli",
"version": "1.0.0",
"description": "Derive component meta data and bundles from React projects",
"bin": {
"alva-analyze": "./bin/analyze"
},
"scripts": {
"check:dependencies": "alva-dependencies -i typescript-eslint-parser"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meetalva/alva.git"
},
"author": {
"email": "[email protected]",
"name": "Meet Alva Team",
"url": "https://meetalva.io/"
},
"license": "MIT",
"homepage": "https://meetalva.github.io/",
"bugs": {
"url": "https://github.com/meetalva/alva/issues"
},
"devDependencies": {
"@meetalva/tools": "1.0.0"
},
"dependencies": {
"@meetalva/analyzer": "1.0.0",
"@meetalva/model": "1.0.0",
"@meetalva/types": "1.0.0",
"@types/node": "^10.12.18",
"yargs-parser": "10.1.0"
}
}
51 changes: 51 additions & 0 deletions packages/analyzer-cli/src/bin/analyze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as Fs from 'fs';
import * as Path from 'path';
import * as Util from 'util';
import * as Model from '@meetalva/model';
import * as Analyzer from '@meetalva/analyzer';
import * as Types from '@meetalva/types';

const yargsParser = require('yargs-parser');
const writeFile = Util.promisify(Fs.writeFile);

async function main() {
const flags = yargsParser(process.argv.slice(2));

const missing = ['in', 'out'].filter(
flag => !flags.hasOwnProperty(flag) || typeof flags[flag] !== 'string'
);

const analyzeBuiltins = flags.hasOwnProperty('builtins') ? flags.builtins : false;

if (missing.length > 0) {
console.error(`missing required flags: ${missing.map(m => `--${m}`).join(', ')}`);
process.exit(1);
}

const cwd = flags.cwd || process.cwd();
const path = Path.resolve(cwd, flags.in);
const outPath = flags.out ? Path.resolve(cwd, flags.out) : '';
const analysis = await Analyzer.analyze(path, { analyzeBuiltins });

if (analysis.type === Types.LibraryAnalysisResultType.Error) {
console.trace(analysis.error);
process.exit(1);
return;
}

const project = Model.Project.create({ name: 'Project', draft: true, path: 'project' });
const library = Model.PatternLibrary.fromAnalysis(analysis.result, {
project,
analyzeBuiltins,
installType: Types.PatternLibraryInstallType.Local
});

await writeFile(
outPath,
`export const analysis = ${JSON.stringify(library.toJSON(), null, ' ')}`
);
}

main().catch(err => {
throw err;
});
29 changes: 29 additions & 0 deletions packages/analyzer-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"references": [
{
"path": "../analyzer"
},
{
"path": "../types"
},
{
"path": "../model"
}
],
"compilerOptions": {
"composite": true,
"outDir": "lib",
"skipLibCheck": true,
"lib": ["es2017"],
"experimentalDecorators": true,
"moduleResolution": "node",
"module": "commonjs",
"rootDir": "src",
"target": "es2017",
"jsx": "react",
"strict": true,
"sourceMap": true,
"declarationMap": true
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions packages/analyzer/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib';
1 change: 1 addition & 0 deletions packages/analyzer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib');
49 changes: 49 additions & 0 deletions packages/analyzer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@meetalva/analyzer",
"version": "1.0.0",
"description": "Derive component meta data and bundles from React projects",
"scripts": {
"check:dependencies": "alva-dependencies -i typescript-eslint-parser"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meetalva/alva.git"
},
"author": {
"email": "[email protected]",
"name": "Meet Alva Team",
"url": "https://meetalva.io/"
},
"license": "MIT",
"homepage": "https://meetalva.github.io/",
"bugs": {
"url": "https://github.com/meetalva/alva/issues"
},
"devDependencies": {
"@meetalva/tools": "1.0.0"
},
"dependencies": {
"@meetalva/types": "1.0.0",
"@meetalva/util": "1.0.0",
"@types/lodash": "4.14.107",
"@types/node": "^10.12.18",
"@types/npm-package-arg": "^6.1.0",
"@types/webpack": "^4.4.21",
"lodash": "4.17.5",
"memory-fs": "0.4.1",
"npm-package-arg": "^6.1.0",
"pacote": "^9.4.0",
"precinct": "5.0.1",
"read-pkg": "3.0.0",
"resolve-pkg": "^1.0.0",
"resolve": "1.8.1",
"semver": "^5.6.0",
"ts-simple-ast": "20.0.0",
"tslib": "1.9.0",
"typescript-eslint-parser": "^21.0.2",
"typescript": "3.2.2",
"unionfs": "^3.0.2",
"uuid": "3.2.1",
"webpack": "^4.28.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as npa from 'npm-package-arg';
import * as Fs from 'fs';
import * as Path from 'path';
import * as semver from 'semver';
import { mkdirp } from '../alva-util';
import { mkdirp } from '@meetalva/util';
import * as ChildProcess from 'child_process';
import { copy } from 'fs-extra';

const pacote = require('pacote');
const resolvePkg = require('resolve-pkg');
Expand Down Expand Up @@ -58,7 +57,7 @@ function fork(command: string, args: string[], opts: ChildProcess.ForkOptions):

export async function getPackage(
raw: string,
opts: { cwd: string; appPath: string }
opts: { cwd: string; dirname: string; appPath: string }
): Promise<PackageResult | Error> {
try {
const parsed = npa(raw);
Expand Down Expand Up @@ -130,11 +129,10 @@ async function getVersion(name: npa.Result): Promise<string | undefined> {
}
}

function getVendorDir(opts: { cwd: string; appPath: string }): string {
function getVendorDir(opts: { cwd: string; appPath: string; dirname: string }): string {
const vendors = [
Path.join(opts.appPath.replace('app.asar', 'app.asar.unpacked'), 'vendor'),
Path.join(__dirname, 'vendor'),
Path.join(__dirname, '..', '..', 'vendor')
Path.join(opts.dirname, 'vendor')
];

const vendor = vendors.find(dir => {
Expand Down
Loading

1 comment on commit 7a4a4a4

@marionebl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.