Skip to content

Commit 0513cb5

Browse files
author
paranerd
committed
Added support for dummy tests in template
1 parent f740126 commit 0513cb5

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

src/cli.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,31 +289,33 @@ async function handleConfigCopy(options: Options) {
289289
}
290290

291291
/**
292-
* Copy template if no .ts files in src/.
292+
* Handle putting template files in place.
293293
*/
294-
export async function handleTemplate() {
294+
async function handleTemplate() {
295295
const cwd = process.cwd();
296-
const sourceDirName = path.join(__dirname, '../../template');
297-
const targetDirName = path.join(cwd, 'src');
296+
const templates = path.join(__dirname, '../../template');
298297

299-
try {
300-
fs.mkdirSync(targetDirName);
301-
} catch (e) {
302-
const err = e as Error & { code?: string };
303-
if (err.code !== 'EEXIST') {
304-
throw err;
305-
}
306-
}
298+
const items = await fs.readdir(templates);
307299

308-
// Only install the template if no ts files exist in target directory.
309-
const files = fs.readdirSync(targetDirName);
310-
const tsFiles = files.filter((file: string) =>
311-
file.toLowerCase().endsWith('.ts')
312-
);
300+
for (const item of items) {
301+
const targetDirName = path.join(cwd, item);
302+
303+
// Create folder
304+
fs.mkdirSync(targetDirName, { recursive: true });
313305

314-
if (tsFiles.length === 0) {
315-
console.log(`${chalk.green('\u2714')}`, 'Installing default template...');
316-
fs.copySync(sourceDirName, targetDirName, { overwrite: false });
306+
// Only install the template if no ts files exist in target directory.
307+
const files = fs.readdirSync(targetDirName);
308+
const tsFiles = files.filter((file: string) =>
309+
file.toLowerCase().endsWith('.ts')
310+
);
311+
312+
// Copy files
313+
if (tsFiles.length === 0) {
314+
console.log(`${chalk.green('\u2714')}`, `Installing ${item} template...`);
315+
await fs.copy(path.join(templates, item), targetDirName, {
316+
overwrite: false,
317+
});
318+
}
317319
}
318320
}
319321

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export const config: {
4646
],
4747
scripts: {
4848
'clean': 'rimraf build dist',
49-
'lint': 'npm run license && eslint --fix src/ test/',
49+
'lint':
50+
'npm run license && eslint --fix --no-error-on-unmatched-pattern src/ test/',
5051
'bundle': 'rollup --no-treeshake -c rollup.config.mjs',
5152
'build': 'npm run clean && npm run bundle',
5253
'license': 'license-check-and-add add -f license-config.json',
File renamed without changes.

template/test/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
describe('index', () => {
17+
it.todo('test me!');
18+
});

0 commit comments

Comments
 (0)