Skip to content

Commit

Permalink
chore: update repository to yarn (microsoft#2382)
Browse files Browse the repository at this point in the history
* test conversion to yarn

* test updated yaml for circleci

* fixing builds

* update circleci to install via yarn docs

* setup prettier as global install for test

* use sudo to install lerna

* update typings for tooling package plugin controls

* fix component explorer issues

* doc updates

* fix angular tests with tsconfig

* test cache and frozen lockfile

* ensure workspaces are built

* change build to prepare

* fixing tests

* update component explore readme conversion path for node modules

* setup tests to stream again

* update working documentation

* update lockfile

* change back to npm from yarn install

* update readmes to reflect npm vs yarn

* revert tooling changes
  • Loading branch information
chrisdholt authored Oct 29, 2019
1 parent fab852e commit 4b7bb2d
Show file tree
Hide file tree
Showing 59 changed files with 25,651 additions and 303 deletions.
19 changes: 8 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ aliases:
docker:
- image: "circleci/node:latest"
working_directory: ~/fast-dna

- &node_install
run:
name: Install Node
command: |
sudo npm i npm@latest -g
npm update rc --depth 4

- &lerna_install
run:
name: Install Lerna
command: |
sudo npm i lerna@3.11.1 -g
sudo yarn global add lerna@3.11.1
version: 2
jobs:
Expand All @@ -24,14 +17,18 @@ jobs:
steps:
- *lerna_install
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install package dependencies
command: |
npm i
yarn install --frozen-lockfile
- run:
name: Bootstrap dependencies
name: Build yarn workspaces
command: |
lerna bootstrap --no-ci
lerna run prepare
- run:
name: Ensure prettier formatting
command: |
Expand Down
12 changes: 3 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
Once the repo has been cloned, install Lerna:

```bash
npm install -g lerna
yarn global add lerna
```

Install dependencies in the root directory:
Install all package dependencies:

```bash
npm install
```

Install dependencies for packages within the project:

```bash
lerna bootstrap
yarn install
```

Learn more about [installing](https://www.fast.design/docs/en/contributing/install).
Expand Down
87 changes: 45 additions & 42 deletions build/documentation/copy-package-readme.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Utility for copying and mocking the copying of readme files from packages to .docs/en/packages/[package-name]/readme.md.
* Usage (copy):run node build/documentation/copy-package-readme.js OR
* npm run docs:build
* yarn docs:build
* Usage (dry-run):run node build/documentation/copy-package-readme.js --dry-run OR
* npm run docs:dry-run
* yarn docs:dry-run
*/
const path = require("path");
const fs = require("fs");
const glob = require("glob");
const chalk = require('chalk');
const chalk = require("chalk");

const rootDir = path.resolve(process.cwd());
const srcReadmePaths = "packages/*/?(readme.md|README.md)";
Expand All @@ -25,50 +25,52 @@ var updatedDocsCount = 0;
* Determine if a dry run will be executed based off --dry-run argument being present
* if an invalid third parameter is entered, the application will exit
*/
process.argv.forEach(function (val, index) {

process.argv.forEach(function(val, index) {
var validArg = true;

if (index == 2) {
val === "--dry-run" ? dryRun = true : validArg = false;
val === "--dry-run" ? (dryRun = true) : (validArg = false);
}

if (!validArg) {
console.log(chalk.red('Invalid argument used. To perform a dry-run use --dry-run'));
console.log(
chalk.red("Invalid argument used. To perform a dry-run use --dry-run")
);
process.exit(1);
}

});

/**
* Function to copy readme files to the ./docs/en/packages folder
* and update Docusaurus sidebar, ./website/sidebars.json
*/
function copyReadmeFiles() {

const resolvedSrcReadmePaths = path.resolve(rootDir, srcReadmePaths);

dryRun ? console.log(`In ${destDir}, this script would...`) : console.log(`In ${destDir}...`);
dryRun
? console.log(`In ${destDir}, this script would...`)
: console.log(`In ${destDir}...`);

fs.readdir('packages', (err, files) => {
fs.readdir("packages", (err, files) => {
totalDocsCount = files.length;
});

createDirectory(destDir);
glob(resolvedSrcReadmePaths, {realpath:true}, function(error, srcFiles) {

srcFiles.forEach((srcReadmePath) => {
glob(resolvedSrcReadmePaths, { realpath: true }, function(error, srcFiles) {
srcFiles.forEach(srcReadmePath => {
createDestReadme(srcReadmePath);
const srcDirPath = path.dirname(srcReadmePath);
const lastSrcDir = srcDirPath.split(path.sep).pop();
sidebarEntries.push(`en/packages/${lastSrcDir}/index`);
});

console.log(chalk.green(`${updatedDocsCount} of ${totalDocsCount} package readme.md files updated`));
console.log(
chalk.green(
`${updatedDocsCount} of ${totalDocsCount} package readme.md files updated`
)
);
updateSidebar();

});

}

/**
Expand All @@ -77,29 +79,27 @@ function copyReadmeFiles() {
* Then appends the original readme from .docs/en/packages/[package-name]
*/
function createDestReadme(srcReadmePath) {

const destReadmePath = srcReadmePath.replace(/(\bpackages\b)(?!.*\1)/, destDir);
const destDirPath = path.dirname(destReadmePath);
const srcDirPath = path.dirname(srcReadmePath);
const srcReadmeText = fs.readFileSync(srcReadmePath).toString();

var folderName = srcDirPath
.split(path.sep)
.pop();
var folderName = srcDirPath.split(path.sep).pop();

var lines = fs.readFileSync(srcReadmePath, 'utf-8')
.split('\n')
var lines = fs
.readFileSync(srcReadmePath, "utf-8")
.split("\n")
.filter(Boolean);

var title = lines[0]
.replace(/#/g, '')
.replace(/FAST/g, '')
.replace(/#/g, "")
.replace(/FAST/g, "")
.trim();
var docusaurusHeader =
`---\n` +
`id: index\n` +
`title: FAST ${title}\n` +

var docusaurusHeader =
`---\n` +
`id: index\n` +
`title: FAST ${title}\n` +
`sidebar_label: ${title}\n` +
`---\n\n`;

Expand All @@ -121,32 +121,35 @@ function createDestReadme(srcReadmePath) {
console.log(chalk.red(err));
}
}

}

/**
* Updates ./website/sidebars.json
*/
function updateSidebar() {

var sidebarJSONPath = path.resolve(rootDir, srcSidebar);
const sidebarText = fs.readFileSync(sidebarJSONPath).toString();
var sidebarJSON = JSON.parse(sidebarText);
sidebarJSON.docs.Packages = [];

sidebarEntries
.map((entry) => sidebarJSON.docs.Packages.push(entry))
sidebarEntries.map(entry => sidebarJSON.docs.Packages.push(entry));

if (dryRun) {
console.log("In website/sidebars.json, this script updates...\n" +
"...the Packages array with the filepath to each package's index file.");
console.log(
"In website/sidebars.json, this script updates...\n" +
"...the Packages array with the filepath to each package's index file."
);
} else {
fs.writeFile(sidebarJSONPath, JSON.stringify(sidebarJSON, null, 2), 'utf8', (err) => {
if (err) throw err;
console.log(chalk.green(`${srcSidebar} was succesfully updated!`));
});
fs.writeFile(
sidebarJSONPath,
JSON.stringify(sidebarJSON, null, 2),
"utf8",
err => {
if (err) throw err;
console.log(chalk.green(`${srcSidebar} was succesfully updated!`));
}
);
}

}

/**
Expand All @@ -163,4 +166,4 @@ function createDirectory(dir) {
* Run script
* Based off presence of --dry-run parameter
*/
copyReadmeFiles();
copyReadmeFiles();
23 changes: 14 additions & 9 deletions docs/en/contributing/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sidebar_label: Install

## Prerequisites

Before setting up FAST-DNA, install Git and [npm](https://www.npmjs.com/get-npm).
Before setting up FAST-DNA, install Git and [yarn](https://yarnpkg.com/en/docs/install).

## Setup the source repository

Expand All @@ -17,21 +17,26 @@ Clone the repository, `cd` into the project, install [Lerna](https://github.com/
```shell
git clone https://github.com/Microsoft/fast-dna.git
cd fast-dna
npm i --global lerna
npm i
yarn global add lerna
```

Install all Lerna dependencies:
Install all dependencies:

```shell
lerna bootstrap
yarn install
```

- `npm run tslint` or `npm run tslint:fix` runs tslint on all typescript in the project.
- `npm run unit-tests` runs all unit-tests.
- `npm run test` runs all processes required to pass prior to check-in. Generally includes building, linting, and unit-testing.
Prepare the workspaces:

To run these processes across *all* projects, substitute `npm` for `lerna`:
```shell
lerna run prepare
```

- `yarn tslint` or `yarn tslint:fix` runs tslint on typescript in a given package.
- `yarn unit-tests` runs unit-tests for the package.
- `yarn test` runs processes in a package required to pass prior to check-in. Generally includes building, linting, and unit-testing.

To run these processes across *all* projects, substitute `yarn` for `lerna run ____`:

```shell
lerna run test
Expand Down
18 changes: 12 additions & 6 deletions docs/en/contributing/working.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ Before submitting a pull request, [rebase](https://www.atlassian.com/git/tutoria

All "packages" share common script names for consistency along with their documentation guides.

To clean all packages:
To clean all packages node_modules:

```bash
lerna clean
```

To clean dependencies hoisted by yarn, navigate to the root of the project and run:

```bash
rm -rf node_modules
```

Install remote dependencies, build, and symlink local dependencies:

```bash
lerna bootstrap
yarn install
lerna run prepare
```

To run all tests on all packages:
Expand All @@ -64,13 +71,13 @@ To run all tests on a single package:

```bash
cd packages/package-name
npm run test
yarn test
```

Most packages have a _watch_ command that rebuilds the package's distribution when a file changes. This process can be useful when doing development across multiple packages:

```bash
npm run watch
yarn watch
```

## Troubleshooting
Expand All @@ -81,8 +88,7 @@ Delete root node_modules (`fast-dna/node_modules`) then:

```bash
lerna clean
npm i
lerna bootstrap
yarn install
lerna run test
```

Expand Down
4 changes: 3 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"packages": [
"packages/*"
],
"version": "independent"
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"license": "MIT",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/jest-preset-angular", "**/jest-preset-angular/**", "**/react-syntax-highlighter"]
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/fast-dna.git"
Expand All @@ -24,7 +28,7 @@
"integration-tests:alpha": "node build/testing/sauce-labs/test-browsers.js alpha",
"integration-tests:beta": "node build/testing/sauce-labs/test-browsers.js beta",
"integration-tests:release": "node build/testing/sauce-labs/test-browsers.js release",
"test": "npm run tslint && npm run unit-tests",
"test": "yarn tslint && yarn unit-tests",
"tslint": "tslint -c ./tslint.json 'build/**/*.ts'",
"tslint:fix": "tslint -c ./tslint.json --fix 'build/**/*.ts'",
"unit-tests": "jest --maxWorkers=4",
Expand Down Expand Up @@ -67,9 +71,6 @@
"moduleFileExtensions": [
"ts",
"js"
],
"moduleDirectories": [
"node_modules"
]
},
"lint-staged": {
Expand All @@ -78,6 +79,9 @@
"git add"
]
},
"resolutions": {
"@types/react": "*"
},
"devDependencies": {
"@microsoft/fast-tslint-rules": "^3.0.0",
"@types/jest": "^24.0.11",
Expand Down
Loading

0 comments on commit 4b7bb2d

Please sign in to comment.