-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @iceworks/[email protected] (#1053)
* feat: support generate ice3 project * chore: update ci node version * chore: update registry * chore: remove registry * feat: dist format * chore: version * fix: test fail * fix: ts error * feat: update test case * fix: package not found * fix: build error * fix: export function is not correct * fix: lint * fix: test * fix: tsconfig * chore: remove beta version * test: add timeout
- Loading branch information
Showing
23 changed files
with
519 additions
and
331 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
node-version: [12.x] | ||
node-version: [14.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
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
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
196 changes: 196 additions & 0 deletions
196
packages/generate-project/src/__tests__/downloadAndGenerateProject.test.ts
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,196 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
import { downloadAndGenerateProject } from '..'; | ||
|
||
const tmpPath = path.resolve(__dirname, '../../.tmp'); | ||
|
||
jest.setTimeout(60 * 1000); | ||
|
||
beforeAll(async () => { | ||
await fs.ensureDir(tmpPath); | ||
}) | ||
|
||
test('generate ice3-lite scaffold', async () => { | ||
const projectDir = path.resolve(tmpPath, 'ice-lite'); | ||
await fs.ensureDir(projectDir); | ||
|
||
await downloadAndGenerateProject( | ||
projectDir, | ||
'@ice/lite-scaffold', | ||
{ | ||
ejsOptions: { | ||
appConfig: { | ||
importDeclarationsStr: `import type { Manifest } from '@ice/plugin-pha/types'; | ||
import { defineSpmConfig } from '@ali/ice-plugin-spm/types'; | ||
`, | ||
exportDeclarationsStr: ` | ||
export const spmConfig = defineSpmConfig(() => { | ||
return { | ||
spmA: 'spmA', | ||
} | ||
}); | ||
export const phaManifest: Manifest = { | ||
routes: [ | ||
'index', | ||
], | ||
} | ||
`, | ||
}, | ||
iceConfig: { | ||
importDeclarationsStr: `import def from '@ali/ice-plugin-def'; | ||
import pha from '@ice/plugin-pha'; | ||
import spm from '@ali/ice-plugin-spm';\n`, | ||
optionsStr: ` | ||
plugins: [ | ||
def(), | ||
pha(), | ||
spm(), | ||
], | ||
`, | ||
}, | ||
esLintConfigOptions: `{ | ||
extends: [] | ||
}`, | ||
}, | ||
extraDependencies: { | ||
devDependencies: { | ||
'@ali/ice-plugin-def': '^1.0.0', | ||
'@ali/ice-plugin-spm': '^1.0.0', | ||
'@ice/plugin-pha': '^2.0.0', | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
const pkgJsonPath = path.join(projectDir, 'package.json'); | ||
const pkgJsonContent = await fs.readJSON(pkgJsonPath); | ||
expect(pkgJsonContent.version).toBe('0.1.0'); | ||
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy(); | ||
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-spm')).toBeTruthy(); | ||
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ice/plugin-pha')).toBeTruthy(); | ||
|
||
const appConfigPath = path.join(projectDir, 'src/app.ts'); | ||
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8'); | ||
expect(appConfigContent.includes('export const phaManifest')).toBeTruthy(); | ||
expect(appConfigContent.includes('export const spmConfig')).toBeTruthy(); | ||
expect(appConfigContent.includes(`import type { Manifest } from '@ice/plugin-pha/types'; | ||
import { defineSpmConfig } from '@ali/ice-plugin-spm/types';`)).toBeTruthy(); | ||
|
||
const configPath = path.join(projectDir, 'ice.config.mts'); | ||
const configContent = await fs.readFile(configPath, 'utf-8'); | ||
expect(configContent.includes(`import def from '@ali/ice-plugin-def'; | ||
import pha from '@ice/plugin-pha'; | ||
import spm from '@ali/ice-plugin-spm';`)).toBeTruthy(); | ||
expect(configContent.includes('plugins: [def(), pha(), spm()]')).toBeTruthy(); | ||
|
||
const eslintConfig = path.join(projectDir, '.eslintrc.cjs'); | ||
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8'); | ||
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy(); | ||
}) | ||
|
||
test('generate antd-pro scaffold', async () => { | ||
const projectDir = path.resolve(tmpPath, 'antd-pro'); | ||
await fs.ensureDir(projectDir); | ||
|
||
await downloadAndGenerateProject( | ||
projectDir, | ||
'@ice/antd-pro-scaffold', | ||
{ | ||
ejsOptions: { | ||
appConfig: { | ||
configStr: `router: { | ||
type: 'hash', | ||
},`, | ||
}, | ||
iceConfig: { | ||
importDeclarationsStr: `import def from '@ali/ice-plugin-def';\n`, | ||
options: { | ||
pluginItemsStr: `def(),` | ||
}, | ||
}, | ||
esLintConfigOptions: `{ | ||
extends: [] | ||
}`, | ||
}, | ||
extraDependencies: { | ||
devDependencies: { | ||
'@ali/ice-plugin-def': '^1.0.0', | ||
}, | ||
} | ||
} | ||
); | ||
|
||
const pkgJsonPath = path.join(projectDir, 'package.json'); | ||
const pkgJsonContent = await fs.readJSON(pkgJsonPath); | ||
expect(pkgJsonContent.version).toBe('0.1.0'); | ||
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy(); | ||
|
||
const appConfigPath = path.join(projectDir, 'src/app.ts'); | ||
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8'); | ||
expect(appConfigContent.includes(`router: { | ||
type: 'hash', | ||
},`)).toBeTruthy(); | ||
|
||
const configPath = path.join(projectDir, 'ice.config.mts'); | ||
const configContent = await fs.readFile(configPath, 'utf-8'); | ||
expect(configContent.includes(`import def from '@ali/ice-plugin-def';`)).toBeTruthy(); | ||
expect(configContent.includes('plugins: [request(), store(), auth(), def()]')).toBeTruthy(); | ||
|
||
const eslintConfig = path.join(projectDir, '.eslintrc.cjs'); | ||
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8'); | ||
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy(); | ||
}) | ||
|
||
test('generate fusion-pro scaffold', async () => { | ||
const projectDir = path.resolve(tmpPath, 'fusion-pro'); | ||
await fs.ensureDir(projectDir); | ||
|
||
await downloadAndGenerateProject( | ||
projectDir, | ||
'@ice/fusion-pro-scaffold', | ||
{ | ||
ejsOptions: { | ||
appConfig: { | ||
configStr: `router: { | ||
type: 'hash', | ||
},`, | ||
}, | ||
iceConfig: { | ||
importDeclarationsStr: `import def from '@ali/ice-plugin-def';\n`, | ||
options: { | ||
pluginItemsStr: `def(),` | ||
}, | ||
}, | ||
esLintConfigOptions: `{ | ||
extends: [] | ||
}`, | ||
}, | ||
extraDependencies: { | ||
devDependencies: { | ||
'@ali/ice-plugin-def': '^1.0.0', | ||
}, | ||
} | ||
} | ||
); | ||
|
||
const pkgJsonPath = path.join(projectDir, 'package.json'); | ||
const pkgJsonContent = await fs.readJSON(pkgJsonPath); | ||
expect(pkgJsonContent.version).toBe('0.1.0'); | ||
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy(); | ||
|
||
const appConfigPath = path.join(projectDir, 'src/app.ts'); | ||
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8'); | ||
expect(appConfigContent.includes(`router: { | ||
type: 'hash', | ||
},`)).toBeTruthy(); | ||
|
||
const configPath = path.join(projectDir, 'ice.config.mts'); | ||
const configContent = await fs.readFile(configPath, 'utf-8'); | ||
expect(configContent.includes(`import def from '@ali/ice-plugin-def';`)).toBeTruthy(); | ||
expect(configContent.includes('plugins: [request(), store(), auth(), def()]')).toBeTruthy(); | ||
|
||
const eslintConfig = path.join(projectDir, '.eslintrc.cjs'); | ||
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8'); | ||
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy(); | ||
}) |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
import * as path from 'path'; | ||
import * as fse from 'fs-extra'; | ||
|
||
export interface ExtraDependencies { | ||
dependencies?: Record<string, string>; | ||
devDependencies?: Record<string, string>; | ||
} | ||
|
||
export default async function addDependencies(extraDependencies: ExtraDependencies, projectDir: string) { | ||
const pkgJsonPath = path.join(projectDir, 'package.json'); | ||
if (!await fse.pathExists(pkgJsonPath)) { | ||
throw new Error(`Path ${pkgJsonPath} does not exist.`); | ||
} | ||
const pkgJson = await fse.readJSON(path.join(projectDir, 'package.json')); | ||
Object.entries(extraDependencies).forEach(([depType, value]) => { | ||
if (!pkgJson[depType]) { | ||
pkgJson[depType] = {}; | ||
} | ||
pkgJson[depType] = { ...value, ...pkgJson[depType] }; | ||
}); | ||
|
||
await fse.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 }); | ||
} |
Oops, something went wrong.