While creating a site collection or site & workspaces using SharePoint API , you can add these two lines code to enable the publishing feature.Provided below is an example using C# for enabling publishing feature at site collection level.
Code in C#

// Turn on publishing feature
objSiteCollection.Features.Add(SPFarm.Local.FeatureDefinitions["PublishingSite"].Id); // objSiteCollection is the Site Collection object

// Make the necessary changes to the local server to use the feature

Any suggestions are appreciated.
Sharepoint migration 2010