Skip to content

Commit

Permalink
feat: enable semi in prettier config and format
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jul 29, 2023
1 parent 9149391 commit fdd8551
Show file tree
Hide file tree
Showing 62 changed files with 813 additions and 809 deletions.
54 changes: 27 additions & 27 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import fs from 'fs'
import path from 'path'
import { version } from '../package.json'
import { projects } from '../projects/projects'
import build, { resetCache } from '../src/buildTemplate'
import { run } from '../src/cli'
import getConfig from '../src/getConfig'
import fs from 'fs';
import path from 'path';
import { version } from '../package.json';
import { projects } from '../projects/projects';
import build, { resetCache } from '../src/buildTemplate';
import { run } from '../src/cli';
import getConfig from '../src/getConfig';

jest.setTimeout(30000)
jest.setTimeout(30000);

const nodeVer = +process.versions.node.split('.')[0]
const nodeVer = +process.versions.node.split('.')[0];

describe('cli test', () => {
test('version command', async () => {
const spyLog = jest.spyOn(console, 'log').mockImplementation(x => x)
const args = ['--version']
const spyLog = jest.spyOn(console, 'log').mockImplementation(x => x);
const args = ['--version'];

await run(args)
expect(console.log).toHaveBeenCalledWith(`v${version}`)
await run(args);
expect(console.log).toHaveBeenCalledWith(`v${version}`);

spyLog.mockReset()
spyLog.mockRestore()
})
spyLog.mockReset();
spyLog.mockRestore();
});

test('main', async () => {
for (const project of projects) {
if (nodeVer < project.nodeVer) continue
if (nodeVer < project.nodeVer) continue;

resetCache()
resetCache();

const workingDir = path.join(process.cwd(), 'projects', project.dir)
const workingDir = path.join(process.cwd(), 'projects', project.dir);
const { type, input, staticDir, output, ignorePath, trailingSlash, pageExtensions, appDir } =
await getConfig(
project.enableStatic,
project.output && path.join(workingDir, project.output),
project.ignorePath,
workingDir
)
);

const result = fs.readFileSync(`${output}/$path.ts`, 'utf8')
const basepath = /-basepath$/.test(project.dir) ? '/foo/bar' : undefined
const result = fs.readFileSync(`${output}/$path.ts`, 'utf8');
const basepath = /-basepath$/.test(project.dir) ? '/foo/bar' : undefined;
const { filePath, text } = build(
type === 'nextjs'
? {
Expand All @@ -62,9 +62,9 @@ describe('cli test', () => {
trailingSlash,
basepath
}
)
);

expect(filePath).toBe(`${output}/$path.ts`)
expect(filePath).toBe(`${output}/$path.ts`);
expect(
text.replace(
new RegExp(
Expand All @@ -75,7 +75,7 @@ describe('cli test', () => {
),
''
)
).toBe(result.replace(/\r/g, ''))
).toBe(result.replace(/\r/g, ''));
}
})
})
});
});
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Config } from '@jest/types'
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['pages']
}
};

export default config
export default config;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"prettier": {
"printWidth": 100,
"semi": false,
"semi": true,
"arrowParens": "avoid",
"singleQuote": true,
"trailingComma": "none",
Expand Down
6 changes: 3 additions & 3 deletions projects/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec } from 'child_process'
import { projects } from './projects'
import { exec } from 'child_process';
import { projects } from './projects';

projects.forEach(({ dir, output, enableStatic, ignorePath }) =>
exec(
Expand All @@ -8,4 +8,4 @@ projects.forEach(({ dir, output, enableStatic, ignorePath }) =>
}${ignorePath ? ` --ignorePath ${ignorePath}` : ''}`,
(_err, stdout, stderr) => console.log(stdout, stderr)
)
)
);
30 changes: 15 additions & 15 deletions projects/nextjs-appdir/lib/$path.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Query as Query0 } from '../app/page'
import type { OptionalQuery as OptionalQuery1 } from '../app/(group1)/[pid]/page'
import type { Query as Query2 } from '../app/(group1)/blog/[...slug]/page'
import type { OptionalQuery as OptionalQuery3 } from '../pages/children/[pid]'
import type { Query as Query4 } from '../pages/children/blog/[...slug]'
import type { Query as Query0 } from '../app/page';
import type { OptionalQuery as OptionalQuery1 } from '../app/(group1)/[pid]/page';
import type { Query as Query2 } from '../app/(group1)/blog/[...slug]/page';
import type { OptionalQuery as OptionalQuery3 } from '../pages/children/[pid]';
import type { Query as Query4 } from '../pages/children/blog/[...slug]';

const buildSuffix = (url?: {query?: Record<string, string>, hash?: string}) => {
const query = url?.query
const hash = url?.hash
if (!query && !hash) return ''
const search = query ? `?${new URLSearchParams(query)}` : ''
return `${search}${hash ? `#${hash}` : ''}`
}
const query = url?.query;
const hash = url?.hash;
if (!query && !hash) return '';
const search = query ? `?${new URLSearchParams(query)}` : '';
return `${search}${hash ? `#${hash}` : ''}`;
};

export const pagesPath = {
"%E6%97%A5%E6%9C%AC%E8%AA%9E": {
Expand Down Expand Up @@ -109,9 +109,9 @@ export const pagesPath = {
})
}
}
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;

export const staticPath = {
aa_json: '/aa.json',
Expand All @@ -124,6 +124,6 @@ export const staticPath = {
},
duplicate_json_1: '/duplicate.json',
duplicate_json_2: '/duplicate_json'
} as const
} as const;

export type StaticPath = typeof staticPath
export type StaticPath = typeof staticPath;
26 changes: 13 additions & 13 deletions projects/nextjs-appdir/out/lib/basic/$path.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Query as Query0 } from '../../../app/page'
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page'
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page'
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]'
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]'
import type { Query as Query0 } from '../../../app/page';
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page';
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page';
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]';
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]';

const buildSuffix = (url?: {query?: Record<string, string>, hash?: string}) => {
const query = url?.query
const hash = url?.hash
if (!query && !hash) return ''
const search = query ? `?${new URLSearchParams(query)}` : ''
return `${search}${hash ? `#${hash}` : ''}`
}
const query = url?.query;
const hash = url?.hash;
if (!query && !hash) return '';
const search = query ? `?${new URLSearchParams(query)}` : '';
return `${search}${hash ? `#${hash}` : ''}`;
};

export const pagesPath = {
"%E6%97%A5%E6%9C%AC%E8%AA%9E": {
Expand Down Expand Up @@ -103,6 +103,6 @@ export const pagesPath = {
})
}
}
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;
30 changes: 15 additions & 15 deletions projects/nextjs-appdir/out/lib/ignore/$path.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Query as Query0 } from '../../../app/page'
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page'
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page'
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]'
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]'
import type { Query as Query0 } from '../../../app/page';
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page';
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page';
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]';
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]';

const buildSuffix = (url?: {query?: Record<string, string>, hash?: string}) => {
const query = url?.query
const hash = url?.hash
if (!query && !hash) return ''
const search = query ? `?${new URLSearchParams(query)}` : ''
return `${search}${hash ? `#${hash}` : ''}`
}
const query = url?.query;
const hash = url?.hash;
if (!query && !hash) return '';
const search = query ? `?${new URLSearchParams(query)}` : '';
return `${search}${hash ? `#${hash}` : ''}`;
};

export const pagesPath = {
"%E6%97%A5%E6%9C%AC%E8%AA%9E": {
Expand Down Expand Up @@ -103,9 +103,9 @@ export const pagesPath = {
})
}
}
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;

export const staticPath = {
aa_json: '/aa.json',
Expand All @@ -117,6 +117,6 @@ export const staticPath = {
},
duplicate_json_1: '/duplicate.json',
duplicate_json_2: '/duplicate_json'
} as const
} as const;

export type StaticPath = typeof staticPath
export type StaticPath = typeof staticPath;
30 changes: 15 additions & 15 deletions projects/nextjs-appdir/out/lib/static/$path.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Query as Query0 } from '../../../app/page'
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page'
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page'
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]'
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]'
import type { Query as Query0 } from '../../../app/page';
import type { OptionalQuery as OptionalQuery1 } from '../../../app/(group1)/[pid]/page';
import type { Query as Query2 } from '../../../app/(group1)/blog/[...slug]/page';
import type { OptionalQuery as OptionalQuery3 } from '../../../pages/children/[pid]';
import type { Query as Query4 } from '../../../pages/children/blog/[...slug]';

const buildSuffix = (url?: {query?: Record<string, string>, hash?: string}) => {
const query = url?.query
const hash = url?.hash
if (!query && !hash) return ''
const search = query ? `?${new URLSearchParams(query)}` : ''
return `${search}${hash ? `#${hash}` : ''}`
}
const query = url?.query;
const hash = url?.hash;
if (!query && !hash) return '';
const search = query ? `?${new URLSearchParams(query)}` : '';
return `${search}${hash ? `#${hash}` : ''}`;
};

export const pagesPath = {
"%E6%97%A5%E6%9C%AC%E8%AA%9E": {
Expand Down Expand Up @@ -109,9 +109,9 @@ export const pagesPath = {
})
}
}
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;

export const staticPath = {
aa_json: '/aa.json',
Expand All @@ -124,6 +124,6 @@ export const staticPath = {
},
duplicate_json_1: '/duplicate.json',
duplicate_json_2: '/duplicate_json'
} as const
} as const;

export type StaticPath = typeof staticPath
export type StaticPath = typeof staticPath;
10 changes: 5 additions & 5 deletions projects/nextjs-basepath/out/lib/basic/$path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Query as Query0 } from '../../../pages'
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]'
import type { Query as Query2 } from '../../../pages/blog/[...slug]'
import type { Query as Query0 } from '../../../pages';
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]';
import type { Query as Query2 } from '../../../pages/blog/[...slug]';

export const pagesPath = {
_a: (a: string | number) => ({
Expand Down Expand Up @@ -36,6 +36,6 @@ export const pagesPath = {
}
},
$url: (url: { query: Query0, hash?: string | undefined }) => ({ pathname: '/' as const, query: url.query, hash: url.hash })
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;
14 changes: 7 additions & 7 deletions projects/nextjs-basepath/out/lib/ignore/$path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Query as Query0 } from '../../../pages'
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]'
import type { Query as Query2 } from '../../../pages/blog/[...slug]'
import type { Query as Query0 } from '../../../pages';
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]';
import type { Query as Query2 } from '../../../pages/blog/[...slug]';

export const pagesPath = {
_a: (a: string | number) => ({
Expand Down Expand Up @@ -36,9 +36,9 @@ export const pagesPath = {
}
},
$url: (url: { query: Query0, hash?: string | undefined }) => ({ pathname: '/' as const, query: url.query, hash: url.hash })
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;

export const staticPath = {
aa_json: '/foo/bar/aa.json',
Expand All @@ -50,6 +50,6 @@ export const staticPath = {
},
duplicate_json_1: '/foo/bar/duplicate.json',
duplicate_json_2: '/foo/bar/duplicate_json'
} as const
} as const;

export type StaticPath = typeof staticPath
export type StaticPath = typeof staticPath;
14 changes: 7 additions & 7 deletions projects/nextjs-basepath/out/lib/static/$path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Query as Query0 } from '../../../pages'
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]'
import type { Query as Query2 } from '../../../pages/blog/[...slug]'
import type { Query as Query0 } from '../../../pages';
import type { OptionalQuery as OptionalQuery1 } from '../../../pages/[pid]';
import type { Query as Query2 } from '../../../pages/blog/[...slug]';

export const pagesPath = {
"_ignore": {
Expand Down Expand Up @@ -39,9 +39,9 @@ export const pagesPath = {
}
},
$url: (url: { query: Query0, hash?: string | undefined }) => ({ pathname: '/' as const, query: url.query, hash: url.hash })
}
};

export type PagesPath = typeof pagesPath
export type PagesPath = typeof pagesPath;

export const staticPath = {
aa_json: '/foo/bar/aa.json',
Expand All @@ -54,6 +54,6 @@ export const staticPath = {
},
duplicate_json_1: '/foo/bar/duplicate.json',
duplicate_json_2: '/foo/bar/duplicate_json'
} as const
} as const;

export type StaticPath = typeof staticPath
export type StaticPath = typeof staticPath;
Loading

0 comments on commit fdd8551

Please sign in to comment.