Skip to content

Commit 10bc1c2

Browse files
authored
Merge pull request #384 from phase2/feature/local-dev-dx
Local development enhancements
2 parents 4b0d85d + 787cad8 commit 10bc1c2

File tree

9 files changed

+155
-15
lines changed

9 files changed

+155
-15
lines changed

.github/workflows/build.yml

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,9 @@ jobs:
7676
env:
7777
NODE_AUTH_TOKEN: ${{ secrets.NPM_GITHUB_PACKAGES }}
7878

79-
- name: Build Outline
80-
run: yarn build --force
81-
82-
- name: Build Storybook
83-
run: yarn storybook:build
84-
8579
# Job to run build, and basic assurances the codebase is ready for additional processing.
86-
build:
87-
name: Build Codebase
80+
build_outline:
81+
name: Build Outline Codebase
8882
runs-on: ubuntu-latest
8983
needs: ['setup']
9084
strategy:
@@ -123,6 +117,54 @@ jobs:
123117
- name: Build Storybook
124118
run: yarn storybook:build
125119

120+
# Test initialization of a new project
121+
build_project:
122+
name: Initialize and Test Build of Project Codebase
123+
runs-on: ubuntu-latest
124+
needs: ['build_outline']
125+
strategy:
126+
matrix:
127+
node: [ 16, 18 ]
128+
# The steps for the setup job.
129+
steps:
130+
# @see https://github.com/marketplace/actions/checkout
131+
- name: Checkout Codebase
132+
uses: actions/checkout@v3
133+
134+
- uses: actions/setup-node@v3
135+
with:
136+
node-version: ${{ matrix.node }}
137+
cache: 'yarn'
138+
139+
# @see https://github.com/marketplace/actions/cache
140+
# node_modules caching is validated by always running yarn install.
141+
# Turborepo cache lives inside node_modules/.cache/turbo
142+
- uses: actions/cache@v3
143+
id: yarn-cache
144+
with:
145+
path: |
146+
node_modules
147+
storybook-static
148+
key: ${{ runner.os }}-node-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}
149+
restore-keys: |
150+
${{ runner.os }}-node-${{ matrix.node }}-yarn-
151+
152+
- name: Install
153+
run: yarn install --prefer-offline
154+
155+
- name: Build from cache
156+
run: yarn build
157+
158+
- name: Generate a project
159+
run: |
160+
PROJDIR=$(mktemp -d)
161+
cd $PROJDIR
162+
npx ${{ github.workspace }}/packages/outline-cli init -a -l -s prj
163+
cd prj
164+
yarn install --prefer-offline
165+
yarn build
166+
yarn storybook:build
167+
126168
# Job to run package publishing process.
127169
test:
128170
name: Test Codebase
@@ -175,7 +217,7 @@ jobs:
175217
name: "Publish: GitHub Pages"
176218
if: github.ref == 'refs/heads/next'
177219
runs-on: ubuntu-latest
178-
needs: ['setup', 'build', 'test']
220+
needs: ['setup', 'build_outline', 'test']
179221

180222
# The steps for the setup job.
181223
steps:
@@ -242,7 +284,7 @@ jobs:
242284
name: "Publish: GitHub Packages"
243285
runs-on: ubuntu-latest
244286
if: github.ref == 'refs/heads/release'
245-
needs: ['setup', 'build', 'test']
287+
needs: ['setup', 'build_outline', 'test']
246288

247289
# The steps for the build job.
248290
steps:
@@ -294,7 +336,7 @@ jobs:
294336
name: "Publish: NPM Packages"
295337
runs-on: ubuntu-latest
296338
if: github.ref == 'refs/heads/release'
297-
needs: ['setup', 'build', 'test']
339+
needs: ['setup', 'build_outline', 'test']
298340

299341
# The steps for the build job.
300342
steps:
@@ -343,7 +385,7 @@ jobs:
343385
chromatic-deployment:
344386
name: "Publish: Chromatic"
345387
runs-on: ubuntu-latest
346-
needs: ['setup', 'build', 'test']
388+
needs: ['setup', 'build_outline', 'test']
347389

348390
steps:
349391
# @see https://github.com/marketplace/actions/checkout

packages/outline-cli/src/actions/init/init-project.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export const initProject = (prompts: Prompts, local: boolean = false): void => {
100100
throw console.error(`${chalk.red('error')}: ${error}`);
101101
}
102102

103+
if (local) {
104+
console.log(
105+
`${chalk.blue('info')}: Linking outline packages for local development`
106+
);
107+
execSync(`node scripts/link-for-local-dev.js ${__dirname}/../../../..`, {
108+
stdio: [0, 1, 2],
109+
});
110+
}
103111
console.log(
104112
`${chalk.green(
105113
'success'

packages/outline-core/src/controllers/light-dom-styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import { ReactiveControllerHost, CSSResultGroup, CSSResult } from 'lit';
3-
import { addScopeToStyles } from '../internal/light-dom';
3+
import { addScopeToStyles } from '../internal/light-dom.mjs';
44

55
/**
66
* The LightComStyles ReactiveController.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Add the scopeId to each CSS rule selector.
3+
* Handle the :host and ::slotted selectors.
4+
*/
5+
export function addScopeToStyles(cssStyles: string, scopeId: string): string;
6+
//# sourceMappingURL=light-dom.d.mts.map

packages/outline-core/tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"rootDir": ".",
5-
"outDir": "./dist"
5+
"outDir": "./dist",
6+
"allowJs": true
67
},
78
"include": ["index.ts", "src/**/*", "tests/**/*"]
89
}

packages/outline-templates/default/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@phase2/outline-docs": "^0.0.9",
9292
"@phase2/outline-dropdown": "^0.1.0",
9393
"@phase2/outline-examples": "^0.0.3",
94-
"@phase2/outline-form": "^0.0.1",
94+
"@phase2/outline-form": "^0.0.6",
9595
"@phase2/outline-grid": "^0.0.1",
9696
"@phase2/outline-heading": "^0.1.0",
9797
"@phase2/outline-icon": "^0.1.0",

packages/outline-templates/default/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const defaultOutput = {
4848
'src/components/**/*.css.lit.ts',
4949
'src/components/**/*.test.ts',
5050
'src/components/examples/**/*',
51+
'src/components/sample/**/*',
5152
],
5253
},
5354
output: [
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Takes an argument of the path to a directory containing package directories to link for
3+
* local development. Will register them all for local development in the current project.
4+
*/
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
const { exec } = require('child_process');
9+
10+
const directoryPath = process.argv[2];
11+
const pattern = /^[^\.]/;
12+
13+
const originalCwd = process.cwd();
14+
15+
if (!directoryPath) {
16+
console.error(
17+
'Directory containing packages to link must be provided as first argument'
18+
);
19+
process.exit(1);
20+
}
21+
22+
fs.readdir(directoryPath, async (err, files) => {
23+
if (err) {
24+
console.error(`Error reading directory: ${err}`);
25+
process.exit(1);
26+
}
27+
28+
const matchingDirs = files.filter(file => {
29+
const filePath = path.join(directoryPath, file);
30+
return fs.statSync(filePath).isDirectory() && pattern.test(file);
31+
});
32+
33+
if (matchingDirs.length === 0) {
34+
console.log(
35+
`No directories matching pattern: /${pattern}/ found in ${directoryPath}`
36+
);
37+
process.exit();
38+
}
39+
40+
for (const dir of matchingDirs) {
41+
const dirPath = path.join(directoryPath, dir);
42+
const pkgJsonPath = path.join(dirPath, 'package.json');
43+
44+
if (!fs.existsSync(pkgJsonPath)) {
45+
console.error(`Skipping ${dirPath}: No 'package.json' file found`);
46+
continue;
47+
}
48+
49+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath));
50+
51+
try {
52+
process.chdir(dirPath);
53+
54+
await execAsync('yarn unlink').catch(error => {
55+
if (!error.message.includes('No registered package found')) {
56+
throw error;
57+
}
58+
});
59+
60+
const linkOutput = await execAsync(`yarn link`);
61+
process.chdir(originalCwd);
62+
63+
const linkOutput2 = await execAsync(`yarn link ${pkgJson.name}`);
64+
} catch (error) {
65+
console.error(`Error linking package: ${error}`);
66+
process.exit(1);
67+
}
68+
}
69+
});
70+
71+
function execAsync(command) {
72+
return new Promise((resolve, reject) => {
73+
exec(command, (error, stdout, stderr) => {
74+
if (error) {
75+
reject(error);
76+
} else {
77+
resolve(stdout);
78+
}
79+
});
80+
});
81+
}

packages/outline-templates/default/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"exclude": [
4343
"./src/components/**/*.stories.ts",
4444
"./src/components/**/*.lit.ts",
45+
"./src/components/sample/**/*",
4546
"node_modules"
4647
]
4748
}

0 commit comments

Comments
 (0)