-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tools): move inline templates that cause dep graph resolution iss…
…ues to template files
- Loading branch information
Showing
10 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tools/generators/migrate-converged-pkg/__fixtures__/just-config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { preset } from '@fluentui/scripts-tasks'; | ||
|
||
preset(); |
5 changes: 5 additions & 0 deletions
5
tools/generators/migrate-converged-pkg/files/just-config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { preset, task } from '@fluentui/scripts-tasks'; | ||
|
||
preset(); | ||
|
||
task('build', 'build:react-components').cached?.();` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tools/generators/migrate-converged-pkg/lib/__fixtures__/utils-hello-substitute.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function hello(){ return 'hello <%= greeting %>'; }; |
1 change: 1 addition & 0 deletions
1
tools/generators/migrate-converged-pkg/lib/__fixtures__/utils-hello.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function hello(){ return 'world'; }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { stripIndents } from '@nrwl/devkit'; | ||
import path = require('path/posix'); | ||
import { getTemplate } from './utils'; | ||
describe(`utils`, () => { | ||
describe(`#getTemplate`, () => { | ||
const getFixturePath = (src: string) => { | ||
return path.join(__dirname, '__fixtures__', src); | ||
}; | ||
|
||
it(`should return template contents`, () => { | ||
const expected = stripIndents`export function hello(){ return 'world'; };`; | ||
const actual = getTemplate(getFixturePath('utils-hello.ts__tmpl__'), {}); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it(`should return template contents and substitue variables`, () => { | ||
const expected = stripIndents`export function hello(){ return 'hello champion!'; };`; | ||
const actual = getTemplate(getFixturePath('utils-hello-substitute.ts__tmpl__'), { greeting: 'champion!' }); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { logger } from '@nrwl/devkit'; | ||
import * as ejs from 'ejs'; | ||
import * as fs from 'fs'; | ||
/** | ||
* Similar to @nrwl/devkit#generateFiles function but for getting content only | ||
* | ||
* @param src - the source folder of files (absolute path) | ||
* @param substitutions - an object of key-value pairs | ||
* @returns | ||
*/ | ||
export function getTemplate(src: string, substitutions: Record<string, unknown>) { | ||
if (!fs.existsSync(src)) { | ||
throw new Error(`${src} doesn't exists`); | ||
} | ||
|
||
const template = fs.readFileSync(src, 'utf8').trim(); | ||
|
||
if (!substitutions) { | ||
return template; | ||
} | ||
|
||
try { | ||
const content = ejs.render(template, substitutions, {}); | ||
|
||
return content; | ||
} catch (err) { | ||
logger.error(`Error in ${src}:`); | ||
throw err; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5262,6 +5262,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/doctrine/-/doctrine-0.0.5.tgz#9768264221e8fd422e4989c8cfdab2ff781f4eb6" | ||
integrity sha512-JJwEeFy8Sl9ctiugU4h4DGN9hCB47oyhUkM2H8g8xZr4tHTEXtmV4U6krKrU8Ng0S7RlG/J7fkta1rGu3pq+YQ== | ||
|
||
"@types/[email protected]": | ||
version "3.1.2" | ||
resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.1.2.tgz#75d277b030bc11b3be38c807e10071f45ebc78d9" | ||
integrity sha512-ZmiaE3wglXVWBM9fyVC17aGPkLo/UgaOjEiI2FXQfyczrCefORPxIe+2dVmnmk3zkVIbizjrlQzmPGhSYGXG5g== | ||
|
||
"@types/[email protected]": | ||
version "3.10.7" | ||
resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.7.tgz#ebdf3b972d293095e09af479e36c772025285e3a" | ||
|
@@ -11635,7 +11640,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" | ||
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= | ||
|
||
ejs@^3.1.7: | ||
ejs@3.1.9, ejs@^3.1.7: | ||
version "3.1.9" | ||
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.9.tgz#03c9e8777fe12686a9effcef22303ca3d8eeb361" | ||
integrity sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ== | ||
|